Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get iTunes player state in AppleScript

Tags:

applescript

I have this problem: On running this script in the Script-Editor it works perfectly.

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

I get s player state running, stopped or paused. But if I export the script a application, I get something like kPSS.

Where is the mistake?


1 Answers

player state is a enumerated constant (actually an integer). Just coerce the value to text

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

Edit:

This should work also with an 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
like image 125
vadian Avatar answered Sep 23 '25 16:09

vadian