在 AppleScript 中获取 iTunes 播放器状态

get iTunes player state in AppleScript

我有这个问题: 运行 脚本编辑器中的这个脚本完美运行。

tell application "iTunes"
set playerstate to get player state
end tell
display dialog playerstate

我得到 s 播放器状态 runningstoppedpaused。 但是如果我将脚本导出到应用程序,我会得到类似 kPSS.

的东西

哪里错了?

player state是一个枚举常量(实际上是一个整数)。 只需将值强制转换为 text

tell application "iTunes"
    set playerstate to (get player state) as text
end tell
display dialog player state

编辑:

这也适用于小程序

   tell application "iTunes"
        if player state is paused then
            set playerStateText to "Paused"
        else if player state is playing then
            set playerStateText to "Playing"
        else
            set playerStateText to "Stopped"
        end if
    end tell
    display dialog playerStateText