Trigger command on shutdown (Manjaro KDE)

I've come from this thread where I've been given a solution to automatically gracefully shut down Firefox, to prevent it from restoring all previously open tabs in the next session.

There are instructions in that thread for triggering a command on shutdown to close Firefox gracefully, but it's not for a different version of Manjaro than the one I have. Can someone tell me how to do the below equivelant in KDE?

In Settings-->Session and Startup-->Application Autostart
Add command wmctrl -c firefox , Trigger: on shutdown

I have wmctrl installed and have got as far as putting the command in the startup / shutdown section, but there's no clear way to set the trigger to "shut down". Double clicking the item just opens a standard file properties dialogue box.

Have a look at the following article and see if the suggested method will work for you. Scroll down to the part related to systemd:

1 Like

Have a look at this as an example for a systemd service triggering before shutdown/reboot and the likes:

1 Like

Firefox doesn't remember tabs unless you set it to do so. In Firefox>Preferences>General section make sure that Restore previous session is not checked.

Not so. In the thread I linked to you can see that setting is off, and Manjaro shuts down in a way that Firefox considers a crash, and I've already tried the settings related to restoring from a crash and it still does it.

Thanks guys. I was kinda hoping it would be built in like it apparently is in whatever version of Manjaro, but I will give these a go.

You can do it by creating a script file (killFirefoxGracefully.sh) with the command you want to execute

#!/bin/bash
wmctrl -c firefox

and put it inside ~/.config/plasma-workspace/shutdown/

The problem is that this method and all the other methods that I know of (systemd and whatnot) run very late at the logout process (all operations (restart, shutdown) are logouts in KDE) which means that firefox would've been killed by the system already, so it is useless for your use case.

1 Like

Ah well. Looks like I am doomed to see my old tabs show up every time. Thanks anyway everyone.

There is the browser.sessionstore.resume_from_crash option. Set it to false.

1 Like

I just tried it, no change. Pretty sure that was one of the ones I already tried but did it just now to check. I am actually typing this reply to you from the tab that re-opened from when I read your reply before changing that setting and restarting.

Well, I tested it and it worked for me. See Restore previous session - Privacy issues

A workaround I tried today, it's working but I don't know if it's the optimal way of doing it.
killFirefoxGracefully.sh

#!/bin/bash
enable -f /usr/lib/bash/sleep sleep
while :; do
    sleep 1
    [ $(qdbus org.kde.ksmserver /KSMServer isShuttingDown) != 'false' ] && { wmctrl -c firefox; break; }
done

you can put it in the ~/.config/autostart-scripts/ folder. And don't forget to make it executable.

Forum kindly sponsored by