libnotifyを使用してスクリプトを実行できますか?

libnotifyを使用してスクリプトを実行できますか?

スクリプトを実行するために使用できますかlibnotify

notify-sendスクリプトを使用してサウンドを再生したり、bashファイルやその他のプログラムを介してより複雑なプログラムを実行したいと思います。

それは可能ですか?ポップアップだけを使用していると思いますか?

ベストアンサー1

あまりにも近いので、実際にスクリプトを実行したくありませんが、libnotify代わりに通知をトリガーするイベントのモニターを作成します。送信される実際のメッセージをトリガーすることもできますが、notify-send自分で試していないため確認できません。

メモ: libnotifynotify-sendメッセージは検索で見つかった内容からのみ生成できます。

使用するイベントを監視してくださいdbus-monitor。サンプルスクリプトは次のように設定できます。

から抜粋Bashを使用してリズムボックスのトラック変更を継続的に監視する方法

#!/bin/bash

interface=org.gnome.Rhythmbox.Player
member=playingUriChanged

# listen for playingUriChanged DBus events,
# each time we enter the loop, we just got an event
# so handle the event, e.g. by printing the artist and title
# see rhythmbox-client --print-playing-format for more output options

dbus-monitor --profile "interface='$interface',member='$member'" |
while read -r line; do
    printf "Now playing: "
    rhythmbox-client --print-playing
done

上記のコードは、org.gnome.Rhythmbox.Playerインターフェイスを監視して呼び出すメンバーを見つけます。メンバーがplayingUriChanged呼び出されると、コマンドは結果を読み取り、read内容を変数に保存しますline

コンテンツはline実際には内部的には使用されず、結果のみを収集するために使用されますdbus-monitor。ループ内の結果はwhile次のように印刷されます。

Now playing: Daft Punk - Overture
Now playing: Daft Punk - The Grid

曲のタイトルはから選ばれましたrythmbox-client --print-playing

DBUS信号/イベント識別

これを達成する方法の詳細については、次の2つのQ&Aをご覧ください。

おすすめ記事