![有没有办法从命令行切换“请勿打扰”?](https://linux22.com/image/1175462/%E6%9C%89%E6%B2%A1%E6%9C%89%E5%8A%9E%E6%B3%95%E4%BB%8E%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%88%87%E6%8D%A2%E2%80%9C%E8%AF%B7%E5%8B%BF%E6%89%93%E6%89%B0%E2%80%9D%EF%BC%9F.png)
是否有命令或标志可以传递以启用或禁用请勿打扰?目前我知道的唯一方法是单击日期和时间,然后单击切换按钮。这将有助于在需要时创建键盘快捷键来切换它。
答案1
答案2
如果您想要一个漂亮的单行命令来切换它,您可以使用以下命令:
gsettings set org.gnome.desktop.notifications show-banners $(if [ "$(gsettings get org.gnome.desktop.notifications show-banners)" = "true" ]; then echo "false"; else echo "true"; fi)
答案3
您也可以通过 Python 执行此操作。使用类似 systemd/supervisord/etc 的程序,可以自动完成此操作:
import subprocess
import time
# Time to set when dnd should start/stop
dnd_time = {'start': {'hour': 17, 'minute': 00}, 'end': {'hour': 8, 'minute': 00}}
sleep_time = 30
def get_dnd_status():
enabled = None
# get to check
status = subprocess.check_output(['gsettings', 'get', 'org.gnome.desktop.notifications', 'show-banners']).strip().decode()
# 'false' means DND is enabled
if status == 'false':
enabled = True
else:
enabled = False
return enabled
def set_dnd_status(to):
# set to apply
set_it = subprocess.check_output(['gsettings', 'set', 'org.gnome.desktop.notifications', 'show-banners', f'{to}'])
if __name__ == '__main__':
current_time = time.localtime()
if dnd_time['start']['hour'] >= current_time.tm_hour >= dnd_time['end']['hour']:
set_dnd_status('true')
else:
enabled = get_dnd_status()
if enabled:
set_dnd_status('false')
time.sleep(sleep_time)
答案4
(您的问题提到您正在寻找键盘快捷键)默认组合键(截至 Ubuntu 22.04)“Super+V”打开通知抽屉,然后按空格键可以切换“请勿打扰”。