启动关机/重启对话的命令

mpt*_*.cz 5 shutdown shortcut-keys suspend unity 16.04

我在笔记本电脑上新安装了 Ubuntu 16.04(带有 Unity),我希望能够启动对话窗口(默认情况下通过按住电源按钮启动的那个窗口,有四个按钮可以锁定、暂停,分别重新启动和停止系统)使用自定义键盘快捷键

这样做的目的是在关闭笔记本电脑盖并使用外部显示器时能够启动与外部(USB 或 BT)键盘的对话,至少使电源按钮无法访问或不方便。

在旧的 Ubuntu 12.04 中,我使用了这个简单的命令:

exec /usr/lib/indicator-session/gtk-logout-helper --shutdown

我绑定了 Ctrl-Alt-Del 键盘快捷键(注销我重定向到 Ctrl-Shift-Del)。

在 Ubuntu 16.04 中是否有类似的命令(或者这只是另一件被“改进”到更糟的东西,就像很多东西一样)?

非常感谢您的帮助!

Ser*_*nyy 9

通常,注销、重新启动和关闭的对话框可以通过dbus. 特别是,你想要的是

qdbus com.canonical.Unity  /com/canonical/Unity/Session com.canonical.Unity.Session.RequestShutdown
Run Code Online (Sandbox Code Playgroud)

您可以通过此命令列出其他方法:

$ qdbus com.canonical.Unity  /com/canonical/Unity/Session | grep '\.Request.*'                                           
method void com.canonical.Unity.Session.RequestLogout()
method void com.canonical.Unity.Session.RequestReboot()
method void com.canonical.Unity.Session.RequestShutdown()
Run Code Online (Sandbox Code Playgroud)

例如,我对多个其他答案使用了相同的方法

如何获得“暂停”警告


如果有人觉得命令有点冗长,请记住 Linux 101:您可以为命令或函数创建别名。

alias quit_session='qdbus com.canonical.Unity  /com/canonical/Unity/Session com.canonical.Unity.Session.RequestShutdown'

quit_session()
{
    qdbus com.canonical.Unity  \
          /com/canonical/Unity/Session \
          com.canonical.Unity.Session.RequestShutdown
}
Run Code Online (Sandbox Code Playgroud)

在命令行上,这将被称为quit_session. 容易,对吧?您可以将其放入~/.bashrc. 如果它仍然很长,请使用更短的名称。

尽管长度很长,但它完全符合问题中的要求。


Jac*_*ijm 8

命令:

gnome-session-quit --power-off
Run Code Online (Sandbox Code Playgroud)

简单有效,并且完全符合您的要求:

在此处输入图片说明

来自man gnome-session-quit

OPTIONS
       The following options are supported:

       --logout
              Prompt the user to confirm logout. This is the default behavior.

       --power-off
              Prompt the user to confirm system power off.

       --reboot
              Prompt the user to confirm system reboot.

       --force
              Ignore any inhibitors.

       --no-prompt
              End the session without user interaction. This only  works  with
              --logout.
Run Code Online (Sandbox Code Playgroud)