Is it possible to run a script/command when the xfce session stops ?
Change the /usr/bin/xfce4-session
executable with a shell script which runs the original xfce4-session
and your logout script if xfce4-session
finished.
# mv /usr/bin/xfce4-session /usr/bin/xfce4-session.orig
The new /usr/bin/xfce4-session
file:
#!/bin/bash
/usr/bin/xfce4-session.orig
echo "my logout script" > /tmp/testfile
Don't forget to set the execute permissions:
# chmod a+x /usr/bin/xfce4-session
(Tested on Debian Squeeze.)
xfce4-settings
is installed. –
Dithionite See http://mail.xfce.org/pipermail/xfce/2012-November/031694.html - There, Erik Habicht suggested creating a wrapper script in /usr/local/bin/xfce4-session
(or another dir that precedes the dir where xfce4-session
is installed, /usr/bin
in your PATH
). This way, you do not have to change /usr/bin/X11/xfce4-session
, so it can be updated independently.
#!/bin/bash
# Add your own pre-session logic here
/usr/bin/xfce4-session
# Add your own logout logic here
then
$ chmod +x /usr/local/bin/xfce4-session
It's not perfect (depends on PATH
order) but may be more palatable.
(Note: I promoted my comment to an answer.)
Change the /usr/bin/xfce4-session
executable with a shell script which runs the original xfce4-session
and your logout script if xfce4-session
finished.
# mv /usr/bin/xfce4-session /usr/bin/xfce4-session.orig
The new /usr/bin/xfce4-session
file:
#!/bin/bash
/usr/bin/xfce4-session.orig
echo "my logout script" > /tmp/testfile
Don't forget to set the execute permissions:
# chmod a+x /usr/bin/xfce4-session
(Tested on Debian Squeeze.)
xfce4-settings
is installed. –
Dithionite I'd prefer solution that does not touch system directories or files and will run the logout hook within current user session and its privilledges.
below is my solution:
create ~/.local/bin/xfce4-session-logout
script with the following contents:
#!/bin/bash
PRELOGOUT=${HOME}/scripts/pre-logout.sh
RESULT=RES_`echo -e "logout\nrestart\nshutdown\nsuspend" | zenity --height=250 --list --title "Logout from $USER" --column "What do You want to do?"`
case $RESULT in
RES_logout)
[ -x $PRELOGOUT] && $PRELOGOUT
/usr/bin/xfce4-session-logout --fast --logout
;;
RES_restart)
[ -x $PRELOGOUT] && $PRELOGOUT
/usr/bin/xfce4-session-logout --fast --reboot
;;
RES_shutdown)
[ -x $PRELOGOUT] && $PRELOGOUT
/usr/bin/xfce4-session-logout --fast --halt
;;
RES_suspend)
/usr/bin/xfce4-session-logout --suspend
;;
*)
exit 1
;;
esac
and make it executable:
chmod u+x ~/.local/bin/xfce4-session-logout
Now, put whatever You need to be executed at logout action to ~/scripts/pre-logout.sh
and make it executable
chmod u+x ~/scripts/pre-logout.sh
after relogin, either menu > logout button
or Alt+f3: "logout"
will bring simple dialog for leaving the current session
Note: pressing Alt+F4
does not work with it, but maybe some black belted xfce4 users will provide some suggestion
I validated the answer above since it does not involve new code writing. I however found another way to proceed : create a X11 program which would be launched at session startup : it could execute custom scripts when the X session is closed
Note : the drawback is that the used scripts could not connect to X windows so this solution may, depending on the need, execute the script too late.
© 2022 - 2024 — McMap. All rights reserved.