Spotify的“播放器状态”在编辑器中可用,但在打包的应用程序中,它只能获得“«常量**** kPSP»”

时间:2012-11-17 22:27:34

标签: applescript spotify

这是一个测试代码:

tell application "Spotify"
    set playerState to player state as string
end tell
display dialog playerState

从AppleScript编辑器中正常工作。但是,当我将我的脚本导出为应用程序时,我得到的是: enter image description here

为什么会这样?

2 个答案:

答案 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