Skip navigation

applescript - cannot reference iTunes context menu

1293 Views 18 Replies Latest reply: May 11, 2013 10:55 AM by iamsudo RSS
1 2 Previous Next
iamsudo Level 1 Level 1 (0 points)
Currently Being Moderated
Apr 13, 2013 8:39 AM

I cannot get any reference for the context menu and its child elements.

 

Accessibility Inspector reads

 

AXApplication

    AXWindow:AXStandardWindow

        AXMenu

 

but ASE always returns an invalid index. Also tried UI Browser to no avail.

 

Any ideas?

MacBook Air, OS X Mountain Lion (10.8.3)
  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Apr 13, 2013 11:47 AM (in response to iamsudo)

    iamsudo wrote:

     

    I cannot get any reference for the context menu and its child elements.

     

    Nor do I. However, with at least one track selected in the iTunes window, it is not too difficult, using GUI Scripting in conjunction with cliclick, to open the contextual menu and select a menu item. For example:

     

    tell application "iTunes" to activate

     

    tell application "System Events"

        tell process "iTunes"

            tell window "iTunes"

                tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1

                    tell (row 1 whose selected is true)

                        set {x, y} to position

                    end tell

                end tell

            end tell

        end tell

    end tell

     

    do shell script "/usr/local/bin/cliclick kd:ctrl c:" & (x + 5) & "," & (y + 5) & " ku:ctrl"

     

    tell application "System Events" to keystroke "Get Album Artwork" & return


     

    Tested under OS X 10.8.3 with iTunes 11.0.2 and cliclick 2.2. (When using GUI Scripting, you must enable access for assistive devices in the Accessibility System Preference pane.)

  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Apr 14, 2013 6:57 PM (in response to iamsudo)

    Unfortunately, there seems to be an issue with the AppleScript “reveal” command, at least in iTunes 11.0.2. I'm unable to have it work properly.

  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Apr 24, 2013 11:13 AM (in response to iamsudo)

    Here's another variation, which doesn't need to “reveal” the track or the playlist:

     

     

    set theFile to POSIX file "/Users/pierre/Music/iTunes/iTunes Media/Music/Compilations/Gold - Greatest Hits/11 Chiquitita.m4a" -- just an example (ABBA Gold - Chiquitita)

     

    tell application "iTunes"

        add theFile

        set theIndex to index of result

        activate

    end tell

     

    tell application "System Events"

        tell process "iTunes"

            tell window "iTunes"

                tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1

                    set {x, y} to position of row theIndex

                end tell

            end tell

        end tell

    end tell

     

    do shell script "/usr/local/bin/cliclick kd:ctrl c:" & (x + 5) & "," & (y + 5) & " ku:ctrl"

     

    tell application "System Events" to keystroke "Add to Up Next" & return


  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Apr 24, 2013 12:41 PM (in response to Pierre L.)

    Here's another variation, which doesn't need to “reveal” the track or the playlist:

     

    Well, that was not a good idea at all. It works only when the track is visible in the iTunes window. Sorry…

  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Apr 25, 2013 5:29 AM (in response to iamsudo)

    For now I'll stick with my version of the script. Btw, did you try it?

     

    I tried, but was unable to run it, no more than any of your other versions. As I said in my second post (in this thread), there seems to be an issue with the “reveal” command. Actually, the issue is most likely due to my setup of iTunes. The “reveal SelTrack” line of code reveals the track for just a brief fraction of a second, so that the next line of code cannot be executed. I've finally found out why:

     

    set TheTrack to "Macintosh HD:Users:pierre:Music:iTunes:iTunes Media:Music:Compilations:Gold - Greatest Hits:11 Chiquitita.m4a"

    tell application "iTunes"

        add TheTrack --> file track id 2599 of library playlist id 1801 of source id 74 of application "iTunes"

    end tell


    Actually, library playlist id 1801 of source id 74 is the same as library playlist "Library" of source "Library", whose visible property is false.

     

     

    Of course, I could use the following workaround:

     

    set TheTrack to "Macintosh HD:Users:pierre:Music:iTunes:iTunes Media:Music:Compilations:Gold - Greatest Hits:11 Chiquitita.m4a"

    tell application "iTunes"

        add TheTrack

        set theDatabaseId to database ID of result

        set TheTrack to file track 1 of user playlist "Music" of source "Library" whose database ID is theDatabaseId

        reveal TheTrack

    end tell

     

    But that's not going to make things faster.

  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Apr 25, 2013 7:45 AM (in response to iamsudo)

    Does this script work for you?

     

    No, it doesn't. No error, but the script again reveals the track for just a brief fraction of a second. The reason is that library playlist 1 of source 1 is the same as library playlist "Library" of source "Library", and has nothing to do with the “Purchased” playlist.

     

    Could it be that your files are not located in the standard folder, that is ~/Music/iTunes/iTunes Media/Music?

     

    Let's compare:

    Your example file: "HD:Users:me:Music:iTunes:iTunes Music:Your Music:test.m4a"

    My example file: "Macintosh HD:Users:pierre:Music:iTunes:iTunes Media:Music:Compilations:Gold - Greatest Hits:11 Chiquitita.m4a"

     

    By the way, I've not the slightest idea of what you are talking about when you say “Bear in mind that I use TotalSpaces with no transitions to achieve this speed — with Mission Control alone it'd probably need introducing delays, I think”.

  • Pierre L. Level 4 Level 4 (3,860 points)
    Currently Being Moderated
    Apr 25, 2013 9:33 AM (in response to iamsudo)

    Thanks for your explanations. Now, since you already have a working version of your script and since I personally don't need a script that “add a track to up next via its HFS path”, everything is nice.

1 2 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.