Last active
July 20, 2023 06:13
-
-
Save buzztaiki/1492431 to your computer and use it in GitHub Desktop.
Using shell object in gjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/gjs | |
// SPDX-License-Identifier: MIT | |
// usage: gjs shell_object_sample.js | |
const { GIRepository, GLib, Gio } = imports.gi; | |
function findLib(path, prefix) { | |
const libdir = Gio.File.new_for_path(path); | |
const files = libdir.enumerate_children('', Gio.FileQueryInfoFlags.NONE, null); | |
for (; ;) { | |
const finfo = files.next_file(null); | |
if (!finfo) break; | |
if (finfo.get_file_type() == Gio.FileType.DIRECTORY && finfo.get_name().startsWith(prefix)) { | |
return GLib.build_filenamev([path, finfo.get_name()]); | |
} | |
} | |
return null; | |
} | |
GIRepository.Repository.prepend_library_path('/usr/lib64/gnome-shell') | |
GIRepository.Repository.prepend_search_path('/usr/lib64/gnome-shell'); | |
GIRepository.Repository.prepend_library_path(findLib('/usr/lib64', 'mutter-')); | |
GIRepository.Repository.prepend_search_path(findLib('/usr/lib64', 'mutter-')); | |
const { Shell } = imports.gi; | |
const appSys = Shell.AppSystem.get_default(); | |
print(appSys.get_installed().map(x => x.get_name()).join('\n')); |
The output is r(0) = Firefox Alacritty ....
. I mean the command works if i run this way.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running
Shell.AppSystem.get_default().get_running().map(x => x.get_name()).join('\n')
inlg
(alt+F2 then typelg
), is there output?