키보드 단축키 로 종료 할 수 있도록 gnome-session-quit ---power-off
사용자 정의 단축키에 할당 할 수 있습니다 .
Unity에서는 다음과 같은 대화 상자가 나타납니다.
그런 다음 마지막으로 시스템 전원을 끄려면 최소 두 번의 키 입력이 필요합니다. 이것은 다소 불편하며 Return기본 카운트 다운 인 60 초를 기다림으로써 전원을 끌 수있을 때 이전 종료 대화 상자를 선호합니다 .
호출 할 때 gnome-session-quit --poweroff
A로부터 GNOME 세션 플래시백 동일한 시스템 (14.04 LTS)에 세션 카운트 다운을 포함하여 이전 대화 상자가 다시 온다 :
그래서 우리는 그것이 어딘가에 있다는 것을 압니다.
Unity 세션을 실행할 때이 이전 대화 상자를 호출하는 방법이 있습니까?
다음은 원하는 동작을 에뮬레이트하는 스크립트입니다. 와 같이 실행해야합니다 sudo
. 키보드 바로 가기에 바인딩 할 수 있습니다 ( 비밀번호없는 실행shutdown
을 허용 하기 위해 sudoers 파일에 명령을 미리 추가 함 ). 단순하고 간결하며 작업을 수행합니다.
#!/bin/bash
# Date: June 11,2015
# Author: Serg Kolo
# Description: a script to emulate
# behavior of GNOME session flashback
# shutdown dialog
# Tell ubuntu to shutdown in 1 min
shutdown -P +1 &
# Show the dialog
zenity --question --text="Shutdown now ? Automatic shutdown in 60 seconds" --ok-label="DOIT"
# If user clicks DOIT, then cancel the old
# shutdown call that has countdown,
# (because only one shutdown command can be run at a time), and
# tell ubuntu to shutdown immediately
# otherwise - cancel it
if [ $? -eq 0 ];then
shutdown -c
shutdown -P now
else
shutdown -c
fi
Takkat이 제안한대로 다음은 zenity의 --timer 옵션과 dbus를 사용하여 sudo 액세스없이 동일한 동작을 달성하는 스크립트입니다.
#!/bin/bash
# Date: June 14,2015
# Author: Serg Kolo
# Description: a script to emulate
# behavior of GNOME session flashback
# shutdown dialog
# version #2
zenity --question --text="Shutdown now ? Autoshutdown in 60 seconds" \
--cancel-label="DOIT" --ok-label="NOPE" --timeout=60 ||
dbus-send --system --print-reply --dest=org.freedesktop.login1 \
/org/freedesktop/login1 "org.freedesktop.login1.Manager.PowerOff" boolean:true
여기서 기본 아이디어는 zenity의 시간 초과 옵션이 0보다 큰 코드로 종료되며 일반적으로 명령이 실패했음을 의미합니다. 따라서 zenity의 취소 옵션과 시간 제한을 종료를 허용하는 조건으로 처리하여 ||
사용자가 취소 버튼 ( "DOIT"로 표시됨)을 클릭하거나 대화 상자가 시간 초과되는 경우에만 OR 연산자 ( )를 사용하여 종료합니다.
사용자 경험을 향상시키기위한 또 다른 변형을 수행 할 수 있습니다 yad
(이 명령을 사용하여 먼저 설치해야 함 sudo apt-add-repository ppa:webupd8team/y-ppa-manager;sudo apt-get update; sudo apg-get install yad
). 이 변형은 진행률 표시 줄을 사용하여 사용자에게 남은 시간을 알려줍니다.
#!/bin/bash
yad --auto-close --sticky --on-top --skip-taskbar --center \
--text 'Shutdown now ? Autoshutdown in 60 seconds.' \
--button="gtk-ok:1" --button="gtk-close:0" --image=dialog-question \
--title 'Shutdown' --timeout=60 --timeout-indicator=top ||
dbus-send --system --print-reply --dest=org.freedesktop.login1 \
/org/freedesktop/login1 "org.freedesktop.login1.Manager.PowerOff" boolean:true
또 다른 가능한 버전은 zenity의 확인 버튼 레이블을 변경하면 기본적으로 강조 표시된 버튼이 확인 버튼 일 수도 있고 아닐 수도 있다는 점을 고려합니다.
zenity --question --timeout 10 --text="Automatic shutdown in 10 seconds"
if [[ $? -eq 1 ]] ; then
# user clicked Cancel
exit
else
dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.PowerOff" boolean:true
fi
스크립트는 0이 아닌 반환시 시스템을 종료합니다. 스크립트 시간이 초과되면 반환 값 1 또는 5는 스크립트가 해당 else
부분 을 실행하도록 지시합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다