有没有办法(最好使用 GUI)在 xx 分钟后挂起我的计算机?我正在使用 Ubuntu MATE 16.04 LTS 并尝试了所有方法,包括电源管理。
谢谢,菲利普
答案1
如果您不介意使用终端,您可以这样做。
执行 :sleep 2h 45m 20s && systemctl suspend -i
它会在 2 小时 45 分钟 20 秒内暂停您的系统。
我编写了一个脚本来获得如下的 GUI:
复制以下脚本的内容并将其保存到您的主目录中 fast_suspend.sh
。
#!/bin/bash
# Tested on : Ubuntu 16.04 LTS
# Date : 19-May-2016
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
set -- `zenity --title="Scheduled-action" \
--forms \
--text='<span foreground="green">Enter Relative time</span>' \
--add-entry="hours" \
--add-entry="min" -\
--add-entry="sec" \
--separator=".0 " \
--add-combo=action --combo-values="poweroff|restart|suspend|logout"`
hrs=$1
min=$2
sec=$3
action=$4
time=$hrs\h\ $min\m\ $sec\s
#Checking validity of the input :
re='^[0-9]*([.][0-9]+)?$'
if ! [[ $hrs =~ $re ]] || ! [[ $min =~ $re ]] || ! [[ $sec =~ $re ]]
then
zenity --error \
--title="Invalid Input" \
--text="You have entered an Invalid time! \n\nOnly positive integers supported"
exit 1
fi
case $action in
"poweroff")
zenity --title=Confirm --question \
--text="Your system is about to <span foreground=\"red\">$action</span> in ${hrs%%.*} hours ${min%%.*} minutes ${sec%%.*} seconds. \nAre you sure \?"
if [ $? -eq 0 ]
then
sleep $time && poweroff
else
exit
fi ;;
"restart")
zenity --title=Confirm --question \
--text="Your system is about to <span foreground=\"red\">$action</span> in ${hrs%%.*} hours ${min%%.*} minutes ${sec%%.*} seconds. \nAre you sure \?"
if [ $? -eq 0 ]
then
sleep $time && reboot
else
exit
fi ;;
"suspend")
zenity --title=Confirm --question \
--text="Your system is about to <span foreground=\"red\">$action</span> in ${hrs%%.*} hours ${min%%.*} minutes ${sec%%.*} seconds. \nAre you sure \?"
if [ $? -eq 0 ]
then
sleep $time && systemctl suspend -i
else
exit
fi ;;
"logout")
zenity --title=Confirm --question \
--text="Your system is about to <span foreground=\"red\">$action</span> in ${hrs%%.*} hours ${min%%.*} minutes ${sec%%.*} seconds. \nAre you sure \?"
if [ $? -eq 0 ]
then
sleep $time && gnome-session-quit --logout --no-prompt
else
exit
fi ;;
esac
此外,您还可以创建一个.desktop
文件来运行它。
复制以下文本并将其保存为fast_suspend.desktop
。
[Desktop Entry]
Type=Application
Terminal=false
Icon=
Name=fast_suspend
Exec=/home/your-user-name/fast_suspend.sh
Name[en_US]=fast_suspend
为两个文件提供执行权限-执行:
chmod a+x ~/fast_suspend.sh ~/Desktop/fast_suspend.desktop
当你想再次启动此窗口时,只需双击在fast_suspend
桌面上。
答案2
如果你正在寻找图形工具,你可以尝试关机。