如何通过命令行工具获取Mac上当前正在播放的歌曲?

发布于 2025-01-18 00:15:44 字数 266 浏览 3 评论 0 原文

我只能在Google上找到一些带有特定音乐应用程序(例如iTunes,Spotify等)的苹果本,以获取当前播放歌曲。

但是现在我正在使用不支持AppleScript控制的NetEase音乐,我想知道是否有任何通用方法可以通过Mac Media Center获取当前的歌曲信息?

AppleScript和其他命令行工具都可以。

“在此处输入图像说明”

I can only find some applescripts on Google with specific music app(like itunes, spotify, etc) to get current playing song.

But now I'm using Netease Music which not supporting to be controled by applescript, I wonder if there is any universal way to get current playing song info via mac media center?

Applescript and other command line tools both ok.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2025-01-25 00:15:44

我制作了一个 cli 工具,可让您从私有 MediaRemote 框架读取属性。

https://github.com/kirtan-shah/nowplaying-cli

因为它使用私有API,它可能会随着未来的 macOS 更新而中断,但目前正在 Ventura 13.1 上运行。

这是一个检索歌曲名称的示例:
正在播放中心截图

I made a cli tool that lets you read properties from the private MediaRemote framework.

https://github.com/kirtan-shah/nowplaying-cli

Since it uses private APIs, it may break with future macOS updates but is currently working on Ventura 13.1.

Here is an example that will retrieve the song name:
now playing center screenshot

nowplaying-cli usage

南巷近海 2025-01-25 00:15:44

在此处输入图像描述1

下面的 AppleScript 代码使用 UI 脚本来检索当前播放的媒体。

tell application "System Events" to tell process "Control Center"
    click menu bar item "Control Center" of menu bar 1
    set currentlyPlaying to value of static text 3 of window "Control Center"
    key code 53 -- press 'esc' key
end tell

activate
display dialog currentlyPlaying with title "Currently Playing" buttons ¬
    {"OK"} default button 1 giving up after 3

在此处输入图像描述2

enter image description here1

This following AppleScript code uses UI scripting to retrieve the currently playing media.

tell application "System Events" to tell process "Control Center"
    click menu bar item "Control Center" of menu bar 1
    set currentlyPlaying to value of static text 3 of window "Control Center"
    key code 53 -- press 'esc' key
end tell

activate
display dialog currentlyPlaying with title "Currently Playing" buttons ¬
    {"OK"} default button 1 giving up after 3

enter image description here2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文