I have a preliminary version of this script working using the Accessibility 
API. What this means is that an administrator needs to authorize either the 
script editor application or an application created from the script in order 
for this script to run.

Right now I have it use VoiceOver to speak the name of the next song. There is 
also a string that returns the Artist and Album.

To the person that was requesting this, what was the final requirement? Do you 
want the information in a dialog box? Should it run just once, or be checking 
on regular intervals to see if the up next has changed?

Perhaps you want me to attempt to insert the information into a Numbers sheet.

Text of script so far is below: note, I believe at least one of the handlers is 
not being used.
note 2 I put the UI Elements being accessed as properties at the top of the 
script. 

use application "System Events"
use scripting additions

property miniPlayerWindow : a reference to window "miniplayer" of application 
process "iTunes"
property ToggleButton : a reference to pop up button 2 of miniPlayerWindow
property UpNextRadioButton : a reference to radio button "Up Next" of radio 
group 1 of miniPlayerWindow
property ScrollRegion : a reference to scroll area 1 of miniPlayerWindow
property NextSongItem : a reference to static text 1 of UI element 1 of row 1 
of table 1 of ScrollRegion
property NextAlbumItem : a reference to static text 2 of UI element 1 of row 1 
of table 1 of ScrollRegion

on run
        -- find the mini player or create it
        ActivateMiniPlayer()
        if description of ToggleButton is not equal to "hide up next" then
                error "Who are we kidding, this should be the button. Perhaps 
iTunes changed the arrangement"
        end if
        
        if value of UpNextRadioButton = 0 then -- Up next needs to be selected 
                click UpNextRadioButton
        end if
        
        -- make sure information is visible 
        set ScrollSize to size of ScrollRegion
        if second item of ScrollSize is equal to 0 then -- hight = 0 
                click ToggleButton
        end if
        
        set Song to value of NextSongItem
        set ALbum to value of NextAlbumItem
        VoiceOverSpeech(Song)
        return Song & ALbum
end run

on VoiceOverSpeech(myText)
        tell application "VoiceOver" to output myText
        
end VoiceOverSpeech
on ActivateMiniPlayer()
        set iTunesRunning to my ActivateIfRunning:"iTunes"
        if not iTunesRunning then
                error "You must be running iTunes for this script to work."
        end if
        tell application "iTunes"
                if (not (exists miniplayer window 1)) then
                        make new miniplayer window
                end if
        end tell
        return {}
        return window "MiniPlayer" of application process "iTunes"
end ActivateMiniPlayer


on appWithName(appName as {text, application})
        set c to class of appName
        if c is equal to application then
                return appName
        else if c is equal to text then
                return application appName
        end if
end appWithName


on ActivateIfRunning:appName
        try
                set frontmost of application process appName to true
                set Success to true
        on error
                set Success to false
        end try
        return Success
end ActivateIfRunning:

                Best wishes,

Jonathan Cohn



-- 
The following information is important for all members of the Mac Visionaries 
list.

If you have any questions or concerns about the running of this list, or if you 
feel that a member's post is inappropriate, please contact the owners or 
moderators directly rather than posting on the list itself.

Your Mac Visionaries list moderator is Mark Taylor.  You can reach mark at:  
[email protected] and your owner is Cara Quinn - you 
can reach Cara at [email protected]

The archives for this list can be searched at:
http://www.mail-archive.com/[email protected]/
--- 
You received this message because you are subscribed to the Google Groups 
"MacVisionaries" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/macvisionaries.
For more options, visit https://groups.google.com/d/optout.

Reply via email to