如何使用 applescript 获取 iTunes 曲目的播放时间?
我刚刚开始使用 Geektool 和 applescripting 来让我的 mac 桌面变得有趣,但我遇到了一个我似乎找不到答案的问题。如何从 osascript 命令获取当前歌曲的播放时间?我找到了关于如何在命令行上使用 iTunes 和 osascript 执行任何其他操作的大量资源,但似乎没有人关心显示当前的播放时间。谢谢!我假设它会是这样的:
osascript -e 'tell application "iTunes" to time of current track'
不过我已经尝试过了,它告诉我这首歌有多长。我想知道已经玩了多久了
I'm just starting to play around with Geektool and applescripting to make my mac desktop fun and I've run into a question I can't seem to find an answer to. How do you get the current song playtime from an osascript command? I've found great resources on how to do just about anything else with iTunes and osascript on the command line but no one seems to care at all about showing the current playtime. Thanks! I'm assuming it will be something like:
osascript -e 'tell application "iTunes" to time of current track'
I already tried that though and it tells me how long the song is. I want to know how long it has been playing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iTunes 套件/应用程序:
如果没有播放/暂停歌曲(例如在启动 iTunes 之后,但在播放任何内容之前),它将返回缺失值。
当您这样做时,您不妨询问曲目的持续时间、起点和终点:
持续时间(秒的小数部分)可能比时间更适合使用(MM:SS 格式的字符串)。
iTunes Suite / application:
It will return missing value if no song is playing/paused (like after starting iTunes, but before playing anything).
While you are at it, you might as well ask for the track's duration, start and finish points:
The duration (fractional seconds) might be nicer to work with than the time (string in MM:SS format).
iTunes Applescript 字典没有任何类的经过时间函数或属性。你必须自己动手。
The iTunes Applescript dictionary doesn't have an elapsed time function or property for any of the classes. You'll have to roll your own.