Applescript Spotify';s";玩家状态“;在编辑器中可用,但在打包的应用程序中,它只得到«;常数****kPSP和#xBB&引用;

Applescript Spotify';s";玩家状态“;在编辑器中可用,但在打包的应用程序中,它只得到«;常数****kPSP和#xBB&引用;,applescript,spotify,Applescript,Spotify,下面是一个测试代码: tell application "Spotify" set playerState to player state as string end tell display dialog playerState 在AppleScript编辑器中工作正常。但是,当我将脚本导出为应用程序时,我得到的是: 为什么会发生这种情况?Spotify似乎没有将常量强制转换为字符串。由于编辑器无法像在AppleScript editor中运行脚本时那样从小程序强制执行脚本,因此将

下面是一个测试代码:

tell application "Spotify"
    set playerState to player state as string
end tell
display dialog playerState
在AppleScript编辑器中工作正常。但是,当我将脚本导出为应用程序时,我得到的是:


为什么会发生这种情况?

Spotify似乎没有将常量强制转换为字符串。由于编辑器无法像在AppleScript editor中运行脚本时那样从小程序强制执行脚本,因此将返回四个字母的常量代码。由于不能将播放器状态的值作为字符串进行测试,请尝试根据常量本身进行测试

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

最好使用此代码获取玩家状态。您不需要知道确切的常量值。在OSX10.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