在AppleScript中获取iTunes播放器状态

时间:2015-06-28 16:41:53

标签: applescript

我有这个问题: 在Script-Editor中运行此脚本时,它可以很好地工作。

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

我获得了播放器状态runningstoppedpaused。 但是,如果我将脚本导出为应用程序,我会得到类似kPSS的内容。

错误在哪里?

1 个答案:

答案 0 :(得分:3)

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

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

修改

这也适用于applet

   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