How can I call a command line program from the gnome shell extension?

I wrote a simple shell script to accomplish a common task, and I want to be able to run it whenever a button is clicked. I used gnome-shell-extension-tool to create the Hello World example already, but now I need to know how easy it is to run an arbitrary command on click. There is no input or output to be affected; it just has to work.

+6
gnome-shell gnome-shell-extensions
source share
2 answers

After a few more creative searches, I found a solution:

const Util = imports.misc.util; Util.spawn(['/path/to/program', 'arg1', 'arg2']) 
+9
source share
 const GLib = imports.gi.GLib; let stuff = GLib.spawn_command_line_sync("cat hello.txt")[1].toString(); 

For those who want to read the output of a command, use this. The default working directory for Gnome shell extensions is the user's home directory.

Just thought I mentioned this because it took me a while to figure them out.

+1
source share

All Articles