小编use*_*074的帖子

每次正则表达式匹配时运行命令,从没有 EOF 的 stdin 读取

我正在尝试编写一个 BASH 脚本,每次在 dbus-monitor 的输出中找到某个字符串(稍后在帖子中指定的参数)时,该脚本都会创建一个时间戳(要写入文件)。我的脚本的主要目的是在 Spotify 上开始播放歌曲时节省时间(包括毫秒)和日期,因为它使用通知。

string "Spotify"每当播放歌曲时,就会输出以下命令。

dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify' | grep 'string "Spotify"'
Run Code Online (Sandbox Code Playgroud)

我的尝试:

search='string "Spotify"'
found=$(dbus-monitor --session interface='org.freedesktop.Notifications',member='Notify' | grep 'string "Spotify"')

while [ ${search} == ${found} ]; do
    date -u +%Y%M%d-%H%M%S.%N >> timestamp.txt
done
Run Code Online (Sandbox Code Playgroud)

我假设代码功能障碍的原因是 dbus-monitor 持续运行,因此阻止了 while 循环的执行。

bash d-bus notifications

6
推荐指数
3
解决办法
1077
查看次数

标签 统计

bash ×1

d-bus ×1

notifications ×1