【发布时间】:2014-11-11 00:12:49
【问题描述】:
我正在编写一个 Applescript,它会显示一条通知,其中包含当前 Spotify 曲目的名称、专辑和艺术家。是的,我知道已经有一个应用程序可以做到这一点,但即使使用最新版本,它也有很多错误并且行为不稳定。
到目前为止,我有一个很好的小脚本。这里是:
repeat until application "Spotify" is not running
tell application "Spotify"
set theSong to name of current track
set theAlbum to album of current track
set theArtist to artist of current track
set theTime to player position
set theDuration to duration of current track
end tell
(* This sets the amount of delay to the length of the song minus the current place in the song, which leaves us with the amount of time left until the next song plays.*)
set delayTime to theDuration - theTime + 0.5
tell application "Spotify"
if player state is playing then
display notification theArtist with title theSong subtitle theAlbum
end if
delay delayTime
end tell
end repeat
基本上,问题是如果我暂停或更改曲目,延迟保持不变,因此在歌曲开始时不会显示通知。
我在这个脚本中使用了延迟,因为我真的不知道检查曲目结尾的更好方法。一首歌的结尾(或一首新歌的开头)是否有任何 Applescript 事件?
谢谢。
P.S.,如果这个问题太复杂,请随时问更多。
【问题讨论】:
-
有没有人注意到
duration of current track似乎返回的是毫秒而不是秒? AppleScript 文档说“duration (integer, r/o) : The length of the track in seconds.”,但对于 1:19 的轨道,我得到的值为 76553。 -
@bonh,到今天还没有修复。
标签: macos applescript spotify playback