3

Having a little past experience with Linux I recently decided to install Lubuntu 14.04 LTS to try and get away from windows and got most everything working except one thing so far... I have set Firefox to "Show my windows and tabs from last time" and that works just fine as long as I remember to close Firefox before I shutdown or restart, but if I forget, the next time I start Firefox 9/10 times it says that Firefox was not closed properly and sometimes forgets my tabs I had open.

I thought to try and find the logout script for lxde (if there is one) so I can maybe add a command such as "sleep 1" to delay logout for a second to allow Firefox to close properly, in my Google searches the only solution I could find that was close was Firefox not closed properly when logging out and I tried the solution suggested in that and couldn't get it to work and figured the reason why was because the solution was for gnome as opposed to lxde

So my question is, How can I add a delay during logout/shutdown to allow Firefox(or any other programs) to exit properly before continuing with logout/shutdown?

If there is already a solution to this issue, I apologize for not searching hard enough.

  • You can try this to run a script at logout Execute a script upon logout/reboot/shutdown in Ubuntu. And try first wmctrl -c firefox; without a delay in your script. – TuKsn May 10 '14 at 09:48
  • @Xubu-Tur Thank you for your response, I tried what you suggested and unfortunately it didn't solve the issue. I tried also adding a delay to see if the command isn't getting enough time to run but it still didn't work, it seems that the script isn't running before the kill command is issued by the logout process. – dnc40085 May 11 '14 at 05:08
  • Did you script work if you execute it manually? – TuKsn May 11 '14 at 09:50
  • Yes, the script does close Firefox correctly if I run it manually and I made sure that the addition to lightdm.conf (session-cleanup-script=/path/to/script) works correctly by pointing it to a script that runs the "touch" command to create a file on the desktop. It's just not running before the logout executes the kill command (or what ever command it uses to force exit) for Firefox. – dnc40085 May 11 '14 at 11:03
  • You can try the scripts below in my answer and create .desktop files for the scripts so you can use it instead of the standard buttons. – TuKsn May 12 '14 at 11:14
  • I guess that would work as a temporary workaround, maybe I'll try my luck at LXDE.org since I just found that forum. If I find a solution to this issue I'll be sure to post it here to help anyone else out in the future that has the same problem. Thank you very much for your help. – dnc40085 May 13 '14 at 10:21

2 Answers2

0

Script for shutdown. Start it from the user session (not from root!). Script finds Firefox window, sends Alt + F4, waits while Firefox closes til 20 seconds, then shuts the system down.

#!/bin/bash

WID=xdotool search --name "Mozilla Firefox" | head -1 if ((WID > 0)) then xdotool windowactivate --sync $WID xdotool key --delay 1 alt+F4 fi

for i in {1..40} do p=pgrep firefox if [ "$p" == "" ] then break fi sleep 0.5 done shutdown -h now

Requires xdotool

sudo apt install xdotool
0

Perhaps a workaround:

script for logout:

#!/bin/bash
wmctrl -c firefox && kill -SIGTERM $_LXSESSION_PID

script for shutdown:

#!/bin/bash
wmctrl -c firefox && dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

For more options look at this answer: shutdown/reboot/suspend/hibernate without password

TuKsn
  • 4,370
  • 2
  • 26
  • 43