Recently I've been playing with KWin script https://develop.kde.org/docs/plasma/kwin/
I understand that I can open the IDE for creating KWin script by either:
- running command
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.showInteractiveKWinConsolein console - running command
plasma-interactiveconsole --kwinin console - press
Alt+F2then typewm consolethen enter
Now I've created a script like such:
print("registerShortcut ...");;
registerShortcut("...","...", "Meta+C", function() {
...
});
I can run it successfully on the IDE, and when it run, when I check it in journalctl, it add a log which print my registerShortcut string above:
$ journalctl -f | grep registerShortcut
Nov 12 xx:xx:xx HOST kwin_x11[1105]: js: registerShortcut ...
Now I have a nice shortcut of Meta+C for doing anything I specify in above function.
But I don't want to press Alt+F2 then type wm console then enter, then open/load the script manually every startup, just to enable my shortcut.
So I'm looking at https://develop.kde.org/docs/plasma/kwin/#packaging-kwin-scripts in hope that if I package it then install it in my own machine then it'll be run at startup. So I placed it in ~/tools/kwin-script-1.
File ~/tools/kwin-script-1/metadata.desktop:
[Desktop Entry]
Name=kwin-script-1
Comment=kwin-script-1
Icon=preferences-system-windows
X-KDE-PluginInfo-Author=xxx
[email protected]
X-KDE-PluginInfo-Name=kwin-script-1
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-License=GPL
Type=Service
X-KDE-ServiceTypes=KWin/Script
X-Plasma-API=javascript
X-Plasma-MainScript=code/main.js
File ~/tools/kwin-script-1/contents/code/main.js
print("registerShortcut ...");;
registerShortcut("...","...", "Meta+C", function() {
...
});
Then I install it with kpackagetool5 --type=KWin/Script -i ~/tools/kwin-script-1
But it seems all it does is just copying them to ~/.local/share/kwin/scripts/kwin-script-1/, and it doesn't run at startup, evident by output of journalctl -b | grep registerShortcut is empty
So, the question is:
- how to run KWin script at startup?
- if installing the KWin script does not make it run at startup, then why bother installing at all? what's the purpose of installing them (or copying them to
~/.local/share/kwin/scripts/...? - I'm aware of How can I run a kwin script from the command line? and I've tried using them (I'm thinking of adding them to my bash_profile or bashrc to automatically run it at startup): it didn't work (either running manually via console or via bash_profile/bashrc)
- command:
script="/home/kristian/.local/share/kwin/scripts/kwin-script-1/contents/code/main.js"
num=$(dbus-send --print-reply --dest=org.kde.KWin \
/Scripting org.kde.kwin.Scripting.loadScript \
string:"$script" | awk 'END {print $2}' )
dbus-send --print-reply --dest=org.kde.KWin /$num \
org.kde.kwin.Scripting.run
- output:
Error org.freedesktop.DBus.Error.UnknownInterface: No such interface 'org.kde.kwin.Scripting' at object path '/4'
- command:
$ script="/home/kristian/.local/share/kwin/scripts/kwin-script-1/contents/code/main.js"
num=$(dbus-send --print-reply --dest=org.kde.kwin.Scripting \
/Scripting org.kde.kwin.Scripting.loadScript \
string:"$script" | awk 'END {print $2}' )
dbus-send --print-reply --dest=org.kde.KWin /$num \
org.kde.kwin.Scripting.run
- output:
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.kde.kwin.Scripting was not provided by any .service files
Error org.freedesktop.DBus.Error.UnknownInterface: No such interface 'org.kde.kwin.Scripting' at object path '/'