Sunday, November 19, 2017

#1 2004-07-02 03:24:24 pm

dmccoy26
Member
From:: Austin TX
Registered: 2003-09-24
Posts: 46
Website

itunes player status

i am trying to pull itunes player information into a timer program i am working on. everything that i have tested in script editor has worked perfectly, but when i move the code into apple script studio it doesn't. for example. in this section of the code, i am trying to see what the current player state is (playing, stopped, paused). it works fine in scripted editor, but does not work in studio.

script in SE

Applescript:


tell application "iTunes" to player state as string
display dialog result

the result is "stopped"

in AS

Applescript:


tell application "iTunes" to player state as string
set the contents of text field "playerStatus" of window "main" to result
set needs display of text field "playerStatus" of window "main" to true

the result is "«constant ****kPSS»"

how can I fix this?


using Macintosh since 1988


Filed under: iTunes

Offline

 

#2 2004-07-03 02:34:48 am

julifos
Administrator
From:: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

Re: itunes player status

I think you can't fix it. Anyway, does it matter? You can use it anyway (though a bit lengthy):

tell application "iTunes"
    if player state is stopped then
        beep
    else
        beep 2
    end if
end tell


Or, in raw form:

tell application "iTunes" to ¬
    set playerState to player state as string

if playerState is "«constant ****kPSS»" then --> stopped
    
else if playerState is "«constant ****kPSP»" then --> playing
    
else if playerState is "«constant ****kPSp»" then --> paused
    
else if playerState is "«constant ****kPSF»" then --> fast forwarding
    
else --> rewinding
    
end if


"stopped" is an application keyword, and it has no meaning (textual meaning) out of its own context. So, at run time you see only the raw constant. It's the same as:

tell application "Finder" to ¬
    set x to owner privileges of startup disk

display dialog (x as text)
--> «constant ****rdwr»

Offline

 

#3 2004-07-03 11:05:24 am

dmccoy26
Member
From:: Austin TX
Registered: 2003-09-24
Posts: 46
Website

Re: itunes player status

I think i have found a work around for it. it mostly works, it reads the stopped and playing states fine but has a problem reading iTunes, if the player is paused. i get a connection error.

Applescript:


on player_status()
   tell application "System Events" to (name of processes) contains "iTunes"
   if result is true then
       using terms from application "iTunes"
           tell application "iTunes"
               if the player state is stopped then
                   set theResult to "stopped"
                   try                        
                       if current track is not missing value then set theResult to "paused"
                   end try
               else if the player state is paused then
                   set theResult to "paused"
               else
                   set theResult to "playing"
               end if
           end tell
       end using terms from
       set the contents of text field "playerStatus" of window "main" to theResult
       set needs display of text field "playerStatus" of window "main" to true
       return 1
   end if
end player_status


using Macintosh since 1988


Filed under: iTunes, System

Offline

 

#4 2004-07-08 12:00:53 pm

BlueCabbie
Member
From:: Silicon Valley
Registered: 2004-07-08
Posts: 2

Re: itunes player status

I think that the key is you need to use "get".

I use the following to return a list of state info to a Cocoa application. -Chuck-


--Open this script in a new Script Editor window.

property CurrentInfoTrack : " "
property cInfo : {"playlist", "trackname", "artist", "album", "playlist", "state", "playtime", "duration", "time-left-to-play", "track-number", "bpm", "genre"}


on currentInfo()
     try
          --say "currentInfo"
          tell application "iTunes"
               copy ((get player state) as string) to item 6 of cInfo
               set CurrentInfoTrack to name of current playlist
               copy (name of current playlist as string) to item 1 of cInfo
               copy (name of current track as string) to item 2 of cInfo
               copy (artist of current track as string) to item 3 of cInfo
               copy (album of current track as string) to item 4 of cInfo
               copy (shuffle of current playlist as string) to item 5 of cInfo
               copy ((get player position) as string) to item 7 of cInfo
               copy (duration of current track as string) to item 8 of cInfo
               if player state is playing then
                    set temp to ((duration of current track) - (get player position))
                    --set MM to (temp div 60)
                    set MM to text -2 thru -1 of ("00" & ((temp div 60) as string))
                    set SS to text -2 thru -1 of ("00" & ((temp - (MM * 60)) as string))
                    
                    copy (MM & ":" & SS) as string to item 9 of cInfo
                    
                    copy ("Track " & (track number of current track as string) & " of " & track count of current track as string) to item 10 of cInfo
                    copy (text -6 thru -1 of ("      " & (bpm of current track) & "bpm") as string) to item 11 of cInfo
                    copy (genre of current track as string) to item 12 of cInfo
                    
               else
                    copy "00:00" to item 9 of cInfo
                    copy "     " to item 10 of cInfo
                    copy "     " to item 11 of cInfo
                    copy "     " to item 12 of cInfo
               end if
          end tell
          return cInfo
     on error
          copy "     " to item 1 of cInfo
          copy "Nothing Selected" to item 2 of cInfo
          copy "     " to item 3 of cInfo
          copy "     " to item 4 of cInfo
          copy "     " to item 5 of cInfo
          copy "     " to item 6 of cInfo
          copy "     " to item 7 of cInfo
          copy "     " to item 8 of cInfo
          copy "     " to item 9 of cInfo
          copy "     " to item 10 of cInfo
          copy "     " to item 11 of cInfo
          copy "     " to item 12 of cInfo
          
          return cInfo
     end try
end currentInfo



-------------------------
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Offline

 

#5 2012-08-11 08:04:14 pm

philostein
Member
Registered: 2010-10-18
Posts: 2

Re: itunes player status

8 years too late? big_smile Anyway, this works in AppleScriptObjC in Xcode 4:

Tell app "iTunes"
    set  _playerStateRaw to {player state=playing, player state=paused, player state=stopped, player state=fast forwarding, player state=rewinding}
end tell

set _playerStateText to {"Playing", "Paused", "Stopped", "Fast forwarding", "Rewinding"}
set _playerState to "Unknown"

repeat with i from 1 to count of _playerStateRaw
    if (item i of _playerStateRaw) as text = "true" then set _playerState to item i of _playerStateText
end repeat

Model: 2011 MBA
AppleScript: Xcode 4.4
Browser: Safari 537.1
Operating System: Mac OS X (10.8)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)