I am writing a simple extension to open browser by clicking the extension button. I would like to know if there is a function which can execute passed shell command as argument. Also, it'd be really helpful if anyone can suggest a good simple reference for extension development.
To access GNOME Shell, sign out of your current desktop. From the login screen, click the little button next to your name to reveal the session options. Select the GNOME option in the menu and log in with your password.
Install Gnome ExtensionsNavigate your Firefox browser to https://extensions.gnome.org/ and simply search for Gnome extensions you wish to install. Flip the ON switch to install the extension. Install extension by clicking on the ON switch. Click Install to confirm the gnome extension installation.
Each GNOME Shell extension is identified by a unique identifier, the uuid. The uuid is also used for the name of the directory where an extension is installed. You can either install the extension per-user in ~/. local/share/gnome-shell/extensions/uuid , or machine-wide in /usr/share/gnome-shell/extensions/uuid .
You can determine the version of GNOME that is running on your system by going to the About panel in Settings. Open the Activities overview and start typing About. A window appears showing information about your system, including your distribution's name and the GNOME version.
From https://github.com/GNOME/gnome-shell/blob/master/js/misc/util.js:
// Runs @command_line in the background, handling any errors that
// occur when trying to parse or start the program.
function spawnCommandLine(command_line) {
try {
let [success, argv] = GLib.shell_parse_argv(command_line);
trySpawn(argv);
} catch (err) {
_handleSpawnError(command_line, err);
}
}
There are a few variations on that method in there. Save yourself mountains of headaches and just bookmark the GitHub repository.
Some quick links:
I can't stress enough how much you'll get out of reading the gnome-shell source. Unfortunately, it's compiled into a resource file now so we don't have local copies to stumble upon.
UPDATE (2021)
If you're reading this, please instead see the documentation available on gjs.guide. Specifically the documentation on Spawning Subprocesses, which covers why this is a bad idea in extensions and how to do it slightly less bad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With