Я думаю, что D-Bus следует использовать. По сути, я хочу что-то подобное — https://wiki.gnome.org/Gjs/Examples/DBusClient — но наоборот.
В расширении будет функция:
function f(s) { doSomethingWithS; }
И эта функция будет вызываться после запуска:
$ <something> "abc"
… в терминале с s == "abc"
.
После предложений от @Jasper и @owen в #gnome-shell
на irc.gnome.org
я адаптировал некоторый код из https://github.com/GNOME/gnome-shell/blob/master/js/ui/magnifierDBus.js:
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Main = imports.ui.main;
let text;
function init() {
text = new St.Label({ text: "0:0", style_class: 'panel-text' });
}
function enable() {
Main.panel._rightBox.insert_child_at_index(text, 0);
}
function disable() {
Main.panel._rightBox.remove_child(text);
}
const TextInTaskBarIface = '<node> \
<interface name="com.michalrus.TextInTaskBar"> \
<method name="setText"> \
<arg type="s" direction="in" /> \
</method> \
</interface> \
</node>';
const TextInTaskBar = new Lang.Class({
Name: 'TextInTaskBar',
_init: function() {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(TextInTaskBarIface, this);
this._dbusImpl.export(Gio.DBus.session, '/com/michalrus/TextInTaskBar');
},
setText: function(str) {
text.text = str;
}
});
Теперь, после выдачи:
% dbus-send --dest=com.michalrus.TextInTaskBar /com/michalrus/TextInTaskBar \
com.michalrus.TextInTaskBar.setText string:"123"
… Ничего не произошло.