
我正在尋找一種在 Gnome 3.20 的鎖定畫面中顯示通知發送訊息內容的方法。通常這是在設定>通知下配置的,但那裡沒有提到“通知發送”,只有已安裝的應用程式才會提到。
使用 dconf,尤其是 underorg.gnome.desktop.notifications application-children ['org-gnome-software', 'firefox', 'org-gnome-pomodoro', 'gnome-tweak-tool', 'evolution', 'ca-desrt-dconf-editor']
也沒有多大幫助。
我的通知發送腳本每 30 分鐘顯示一次從另一個文件獲取的確認訊息:
#!/bin/bash
while : ; do
notify-send -i /usr/share/icons/gnome/scalable/emotes/face-smile-big-symbolic.svg --hint int:transient:1 "$(sort -R ~/Sonstiges/Affirmationen/Affirmationen.txt | head -n 1)"
sleep 30m # Zeit in Minuten
done
有什麼想法如何實現這一點?
答案1
感謝 Chris Williams (chrisawi) 來自Gnome IRC 頻道找到了以下解決方案:
notifier
建立一個包含/.local/bin/
以下內容的腳本:
#!/usr/bin/python3
# License: MIT
# Author: Chris Williams
APP_ID = "com.example.Notifier"
import sys
from gi.repository import GLib, GObject, Gio
class Notifier(Gio.Application):
def __init__(self):
Gio.Application.__init__(self, application_id=APP_ID, flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE)
self.set_option_context_parameter_string ("ID TITLE [MESSAGE...]")
self.add_main_option("icon", ord('i'), GLib.OptionFlags.NONE, GLib.OptionArg.STRING, "Icon name or file", None)
#self.add_main_option("quit", ord('q'), GLib.OptionFlags.NONE, GLib.OptionArg.NONE, "Quit", None)
self.add_main_option(GLib.OPTION_REMAINING, 0, GLib.OptionFlags.NONE, GLib.OptionArg.STRING_ARRAY, "", None)
def do_command_line(self, cl):
Gio.Application.do_command_line(self, cl)
opts = cl.get_options_dict().end().unpack()
#if opts.get("quit"):
# self.quit()
args = opts.get(GLib.OPTION_REMAINING, [])
if len(args) >= 2:
notification = Gio.Notification()
notification.set_title(args[1])
if len(args) >= 3:
notification.set_body(" ".join(args[2:]))
icon_str = opts.get("icon")
if icon_str:
try:
icon = Gio.Icon.new_for_string(icon_str)
except GLib.Error as e:
if not e.matches(Gio.io_error_quark(), Gio.IOErrorEnum.INVALID_ARGUMENT):
raise
else:
notification.set_icon(icon)
self.send_notification(args[0], notification)
else:
print ("not enough arguments")
return 0
if __name__ == '__main__':
app = Notifier()
app.run(sys.argv)
在原來的notify-send腳本中提到它,也在於/.local/bin/
:
#!/bin/bash
while : ; do
notifier -i emote-love-symbolic idxyz "$(sort -R ~/Sonstiges/Affirmationen/Affirmationen.txt | head -n 1)"
sleep 30m # time in minutes
done
如果您希望在啟動時執行此腳本,您還必須建立一個.desktop
文件,無論是 in/.local/share/applications/
還是 in 。/.config/autostart/
我的/affirmationen.desktop
看起來/.config/autostart/
像這樣:
[Desktop Entry]
Name=Affirmationen
Exec=affirmationen
Icon=emote-love-symbolic
Type=Application
StartupNotify=true
Hidden=false
NoDisplay=false
Terminal=false
X-GNOME-UsesNotifications=true
X-GNOME-Autostart-enabled=true
享受!