Spotify's “player state” is available in the editor, but in a packaged app, it gets only “«constant ****kPSP»”

為{幸葍}努か 提交于 2019-12-12 13:16:23

问题


Here's a testing code:

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

Works fine from the AppleScript editor. However, when I export my script as an app, all I get is this:

Why is this happening?


回答1:


It seems that Spotify is not coercing the constant into a string. Since the editor can't coerce it from an applet as it does when you are running the script in AppleScript Editor, the four-letter constant code is returned. Since you can't test the player state's value as a string, try to test it against the constants themselves.

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



回答2:


It's better to use this code to obtain the player state. You don't need to know the exact constant values. Works on 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


来源:https://stackoverflow.com/questions/13435412/spotifys-player-state-is-available-in-the-editor-but-in-a-packaged-app-it-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!