Sunday, November 9, 2014

Autostart in Plasma 5

In the past few days as I got more and more annoyed that git pushes and svn updates and commits were always asking for my ssh key password I looked at what the current status of plasma autostart is. When I set up my plasma 5 environment I copied all the scripts that were in ~/.kde/Autostart to ~/.config/autostart thinking they would "just work" there, but it turns out they don't. My needs are simple I only had two .sh bash scripts in there, one for running ksshaskpass to ssh-add my ssh key. The other to launch synergys on login. Both scripts showed up in the autostart kcm, but neither was getting launched at login time.

Digging a bit in the code of kinit and klauncher I found that when it looks at ~/.config/autostart it only looks for .desktop files. It turns out this comes from an xdg spec for autostart scripts. Ok, simple enough, so I removed my script and in the autostart kcm created a new autostart item that launches synergys for me at login time. Works like a charm.

Next I went to look at ssh-add using ksshaskpass (there's a kf5 port of ksshaskpass in kdereview now by the way, which works pretty well and has some small improvements from the kdelibs4 version). For one thing, files that aren't .desktop files in ~/.config/autostart aren't getting launched, because klauncher doesn't even look at them. To fix this the autostart kcm was modified to not show these anymore.

The other question then is where should plain bash scripts be put that users and sysadmins used to put into ~/.kde/Autostart ? One solution is to put them into ~/.config/plasma-workspace/env/ . This is what I did here with and that works fine. The only thing to note though is that these are sourced, not executed, and they are sourced before plasma has started, so they can set environment variables and such if needed. This may not be ideal for scripts that need to talk to running services, so we may need to add something to ksmserver to launch scripts from ~/.config/ksm-autostart or something like that. There's a bug about it here already, so don't file new bugs about this issue.


Unknown said...

Do you know if krunner supports aliases?
I put two scripts in
"$HOME/.config/plasma-workspace/env", one containing exports, the other containing aliases. While the exports seem to work (I can call executables within my PATH variable that I could not call before), krunner does not show any aliases, e.g. alias ec='emacsclient -c -n' does not show up.
If you have any knowledge on that or could point me to a source that helps me understand how to properly plasma5 with respect to that functionality, I'd be glad to hear about it.


Anonymous said...

Hi, thanks for the post. Unfortunately, KDE does not tell you about the .desktop files and simply accepts Bash scripts without further notice. Except for the scripts not being executed. plasma-workspace 5.3.1 .

Unknown said...

It seems that there is a folder ~/.config/autostart-scripts

David said...

Here's what each autostart folder does:

I found if I went to "System Settings > Startup and Shutdown > Autostart" I could add a script or binary as a symlink. I checked and it had created a symlink here:

ls -l ~/.config/autostart-scripts

lrwxrwxrwx 1 david david 18 Feb 23 10:31 syncthing -> /usr/bin/syncthing