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

Art*_*sky 3 applescript spotify

这是一个测试代码:

tell application "Spotify"
    set playerState to player state as string
end tell
display dialog playerState
Run Code Online (Sandbox Code Playgroud)

AppleScript编辑器可以正常工作.但是,当我将我的脚本导出为应用程序时,我得到的是: 在此输入图像描述

为什么会这样?

ada*_*one 7

似乎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
Run Code Online (Sandbox Code Playgroud)