这是一个测试代码:
tell application "Spotify"
set playerState to player state as string
end tell
display dialog playerState
从AppleScript编辑器中正常工作。但是,当我将我的脚本导出为应用程序时,我得到的是:
为什么会这样?
答案 0 :(得分:6)
似乎Spotify不会将常量强制转换为字符串。由于编辑器无法像在AppleScript编辑器中运行脚本时那样从applet强制它,因此会返回四个字母的常量代码。由于您无法将播放器状态的值测试为字符串,因此请尝试针对常量本身进行测试。
property spotPause : «constant ****kPSp»
property spotPlay : «constant ****kPSP»
tell application "Spotify" to set playerState to player state
if playerState = spotPause then
display dialog "paused"
else if playerState = spotPlay then
display dialog "playing"
end if
答案 1 :(得分:1)
最好使用此代码来获取播放器状态。您不需要知道确切的常量值。适用于OS X 10.13
tell application "Spotify"
if player state is playing then
display dialog "Player running"
else if player state is paused then
display dialog "Player paused"
else if player is stopped then
display dialog "Player is stopped"
else
display dialog "Unknow state"
end if
end tell