Get Running App From GJS Script

The following code works:

#!/usr/bin/gjs

const res = imports.gi.GIRepository.Repository

// load library of Mutter project
res.prepend_search_path('/usr/lib/x86_64-linux-gnu/mutter-11')
res.prepend_library_path('/usr/lib/x86_64-linux-gnu/mutter-11')

// load library of gnome-shell project
res.prepend_search_path('/usr/lib/gnome-shell')
res.prepend_library_path('/usr/lib/gnome-shell')

const Shell = imports.gi.Shell;
const appSys = Shell.AppSystem.get_default();
print(appSys.get_installed().map(x => x.get_name()).join('\n'));

However, if I replace get_installed with get_running, then there are no output. Why?

It’s not working because you are trying to use the internal libraries of GNOME Shell in a stand-alone context.

Libraries like Shell are intended to be used inside the gnome-shell process (e.g. by extensions), and will rarely be any use in other projects.

1 Like

Thank you very much.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.