Spotify's “player state” is available in the e

2019-07-05 21:47发布

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: enter image description here

Why is this happening?

2条回答
看我几分像从前
2楼-- · 2019-07-05 22:24

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
查看更多
霸刀☆藐视天下
3楼-- · 2019-07-05 22:25

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
查看更多
登录 后发表回答