Skip to content

Instantly share code, notes, and snippets.

@mijorus
Created January 9, 2022 20:38
Show Gist options
  • Save mijorus/312a5ac5dd22878a4740fd6bd395c40c to your computer and use it in GitHub Desktop.
Save mijorus/312a5ac5dd22878a4740fd6bd395c40c to your computer and use it in GitHub Desktop.
How to run a command from a gnome extension
/**
The first time I wanted to create an extension for Gnome, I spent two hours trying to understand how to do this, due to bad documentation.
So now I am sharing this once for all.
*/
const ByteArray = imports.byteArray;
function exec(command) {
const output = GLib.spawn_command_line_sync(command);
return {
ok: output[0],
standard_output: ByteArray.toString(output[1]),
standard_error: ByteArray.toString(output[2]),
exit_status: output[3]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment