I would like a warning before shutting down the computer

Message
Author
Wallon
Posts: 339
Joined: Wed Oct 21, 2020 4:08 pm

I would like a warning before shutting down the computer

#1 Post by Wallon »

Dear users,

It's silly, there have been several times when I've closed the computer without realising that I'd left LibreOffice documents open.
When I restart, I can't always recover the documents. Naturally, in the LibreOffice settings, I've set up a backup of open files and a copy every 10 minutes. It's my fault, I should be more careful, I know.
Isn't there a way of receiving a notification saying that programmes are open before shutting down the computer?

Best regards,
Wallon

User avatar
j2mcgreg
Global Moderator
Posts: 7122
Joined: Tue Oct 23, 2007 12:04 pm

Re: I would like a warning before shutting down the computer

#2 Post by j2mcgreg »

@Wallon
In the XFCE version, there's already a warning in place. You just have to get into the habit of checking the panel for open applications before you initiate a shutdown. In the attachment, the little horizontal bars above the Chrome and Writer icons indicate that they are active and need to be closed prior to shutdown.


Screenshot_2023-06-02_09-00-14.png
You do not have the required permissions to view the files attached to this post.
HP 15; ryzen 3 5300U APU; 500 Gb SSD; 8GB ram
HP 17; ryzen 3 3200; 500 GB SSD; 12 GB ram
Idea Center 3; 12 gen i5; 256 GB ssd;

In Linux, newer isn't always better. The best solution is the one that works.

User avatar
CharlesV
Administrator
Posts: 7900
Joined: Sun Jul 07, 2019 5:11 pm

Re: I would like a warning before shutting down the computer

#3 Post by CharlesV »

Wallon wrote: Fri Jun 02, 2023 8:33 am Dear users,

It's silly, there have been several times when I've closed the computer without realising that I'd left LibreOffice documents open.
When I restart, I can't always recover the documents. Naturally, in the LibreOffice settings, I've set up a backup of open files and a copy every 10 minutes. It's my fault, I should be more careful, I know.
Isn't there a way of receiving a notification saying that programmes are open before shutting down the computer?

Best regards,
Wallon
Since the shutdown is a script, (and there is a way to run a script in-front of that even!), I am sure there is a way to look for specific open applications, throw a notification and then prevent the shutdown.

This is an interesting thought, and one I want to investigate.
*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!

MXRobo
Posts: 1839
Joined: Thu Nov 14, 2019 12:09 pm

Re: I would like a warning before shutting down the computer

#4 Post by MXRobo »

Re:
when I've closed the computer….
Do you mean:
A - Power Manager>System>Laptop Lid
does it go into one of those four options.

Or B - is it when you actually shut down the computer?

If it's the later, Power Manager>General - - Buttons has five options, one being Ask.

This is obvious, but…. HTH

Wallon
Posts: 339
Joined: Wed Oct 21, 2020 4:08 pm

Re: I would like a warning before shutting down the computer

#5 Post by Wallon »

Dear @j2mcgreg

I know there's a little line above the icon but I don't see it all the time!
It's better to have a warning message before you shut down the computer.

Best regards,
Wallon

Wallon
Posts: 339
Joined: Wed Oct 21, 2020 4:08 pm

Re: I would like a warning before shutting down the computer

#6 Post by Wallon »

Dear @MXRobo ,

I can't make a printscreen of the window with the 5 options.
I would like a message before clicking on the red icon (turn off the computer).

Best regards,
Wallon

User avatar
CharlesV
Administrator
Posts: 7900
Joined: Sun Jul 07, 2019 5:11 pm

Re: I would like a warning before shutting down the computer

#7 Post by CharlesV »

So, I have not had too much testing on this.. but here is a solution that appears to work.

1) Save the below script code to a file named: xfce4-session-logout
2) Copy this file to /usr/local/bin/
3) Make the file executable

When you click on the Menu Logout button you will have a second menu show up, asking what you want to do. Choose Shutdown and it will check for both other logged on users and then open files and attempt to close them gracefully. ( I can remove the other users part if you like, but I like that in this script.)

For me, when I run this with an open, non saved libre office document, it stops the shutdown and then libre office requests the 'Discard, cancel or Save Dialog'. Also other apps that have 'non saved' work.

Note: this does NOT work using the Log out Action Button in the main panel.. I am hunting down how to do that now, but it is being elusive and I am out of time for this today.

I will keep working on this as I can get time, I see it as an interesting addition that is smart!

The script:
xfce4-session-logout

Code: Select all

#!/bin/bash
# requires wmctrl and yad packages

# if dialog already displayed, exit
wmctrl -l | grep "Xfce Exit"  && exit 1

close_apps () {
	WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$|xfce4-panel$" | cut -f1 -d' ')
	for i in $WIN_IDs; do wmctrl -ic "$i"; done

	# Keep checking and waiting until all windows are closed
	while [ "$WIN_IDs" != "" ]; do
		sleep 0.1;
		WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$|xfce4-panel$" | cut -f1 -d' ')
	done
}

check_if_other_users_logged_in () {
	# check if anyone other than $USER is logged in
	U=$(loginctl --no-legend list-users | awk '{print $2}' | grep -v $USER)

	# if yes, ask if to continue
	if [ "$U" != "" ]; then
		ans=$(yad  --window-icon=system-devices-panel-information --on-top --sticky --fixed --center --title "Xfce Exit" --text-align=center --buttons-layout=center --title "Confirm" --text " The following users are currently logged in: \n\n$U\n\nContinue with action?")
		ret=$?
		[[ $ret -eq 1 ]] && exit 1		#if cancel, exit
	fi
}

# display dialog asking for exit/suspend/lok options
ans=$(yad  --window-icon=system-devices-panel-information --on-top --sticky --fixed --center --width 200 --entry --title "Xfce Exit" --text "\nSelect an action:\n" --image=xfce4_xicon3 --image-on-top --button="gtk-ok:0" --button="gtk-cancel:1" --text-align center --entry-text  "Logout" "Reboot" "Suspend" "Hibernate" "Power Off" "Lock Screen")
ret=$?
[[ $ret -eq 1 ]] && exit 1		#if cancel, exit

case $ans in
	Logout*)
		check_if_other_users_logged_in
		close_apps
		/usr/bin/xfce4-session-logout -l
	;;
	Power*)
		check_if_other_users_logged_in
		close_apps
		/usr/bin/xfce4-session-logout -h
	;;
	Reboot*)
		check_if_other_users_logged_in
		close_apps
		/usr/bin/xfce4-session-logout -r
	;;
	Suspend*)
		/usr/bin/xfce4-session-logout -s
	;;
	Hibernate*)
		/usr/bin/xfce4-session-logout --hibernate
	;;
	Lock*)
		xflock4
	;;
	*) ;;
esac

exit 0

*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!

Jakob77
Posts: 658
Joined: Thu Feb 09, 2023 3:09 am

Re: I would like a warning before shutting down the computer

#8 Post by Jakob77 »

Wallon wrote: Fri Jun 02, 2023 12:46 pm It's better to have a warning message before you shut down the computer.
As I see it it all depends on how you turn off the computer.
If you can't remember to close an open document how can anyone relay on it is not the same with the computer so the warning has to be where the wire is plugged in.? ;)
However if you actually are able to follow a close down procedure by using only one icon for it, a reminder is not a problem.
For a while to educate yourself you can just create a panel icon you always use and let that icon open a document (my_dummy_close_down_list.txt) with featherpad.
And in that document you write a good long warning message to yourself. :happy:

User avatar
Duliwi
Posts: 1178
Joined: Sun Jul 07, 2019 9:34 am

Re: I would like a warning before shutting down the computer

#9 Post by Duliwi »

CharlesV wrote: Fri Jun 02, 2023 4:16 pm So, I have not had too much testing on this.. but here is a solution that appears to work.
Cool Script. Is there a way to place this file in home? And if yes, in which path?

Edit: Works not, when it is placed here:
~/.bin/xfce4-session-logout

User avatar
CharlesV
Administrator
Posts: 7900
Joined: Sun Jul 07, 2019 5:11 pm

Re: I would like a warning before shutting down the computer

#10 Post by CharlesV »

All calls in the script are either explicit or using the path, so it should be able to *run* from anywhere... HOWEVER... the xfce4 shutdown process specifically looks for *** that file name, in that folder *** ( ie /usr/local/bin/xfce4-session-logout ) and if found then it runs it.

SO... I believe you could put the script anyplace and name it differently, ( say Shutdown_Gracefully ) .. and then create a script to call that, and make that script the /usr/local/bin/xfce4-session-logout .

Also, I believe you could set the "graceful" script anyplace and then create a link to it and name that link xfce4-session-logout and put in the /usr/local/bin folder.

What envision doing to make this all tight, is to remove the Log Out Action Button, (unless I can find a method to rework it!), and then create a new "Log Out" button that points to that script. if you use one of the above methods for the menu part, then I think this will all be 'seamless'

When I get a little time I will see about reworking that YAD menu into maybe a GTKDialog and clean it up even more.
*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!

Post Reply

Return to “Software / Configuration”