2

Looking to download my iTunes purchase history and found this AppleScript by @Boris42, Download entire iTunes purchase history as CSV file (MacOS High Sierra), however it's not working on my iMac.

  • 21.5-inch 2017
  • High Sierra OS 10.13.4 (17E202 - which is one earlier than Boris')
  • iTunes 12.7.4.76

I copy pasted his script into my Script Editor & ran (reposted here).

    tell application "iTunes" to activate
tell application "TextEdit"
    activate
    make new document at the front with properties {name:"iTunes purchased.txt"}
    delay 1
    tell application "System Events" to click menu item "Make Plain Text" of menu 1 of menu bar item "Format" of menu bar 1 of application process "TextEdit"
end tell
tell application "iTunes" to activate
tell application "System Events"
    keystroke "1" using {command down}
    set w to window "iTunes" of application process "iTunes"
    click radio button "Store" of radio group 1 of w
    delay 2
    set webarea to UI element 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of w
    click static text "Purchased" of UI element "Purchased" of group 6 of list 2 of webarea
    delay 2
    click radio button "All" of tab group 1 of group 2 of webarea
    delay 3
    click radio button "Songs" of tab group 1 of group 5 of webarea
    delay 5
    set allRows to UI elements of table 1 of webarea
    set entireContent to quote & "Nr" & quote & "," & quote & "Song Name" & quote & "," & quote & "Artist" & quote & "," & quote & "Album" & quote & "," & quote & "Duration" & quote & return
    tell application "TextEdit" to activate
    repeat with aRow in allRows
        if class of aRow is row then
            set gr to UI element 1 of group 1 of UI element 2 of aRow
            if class of gr is group then
                set songNum to value of static text 1 of group 1 of UI element 1 of aRow
                set songName to value of static text 1 of group 2 of UI element 2 of aRow
                set songArtist to value of static text 1 of group 1 of UI element 1 of UI element 3 of aRow
                set album to UI element 1 of UI element 4 of aRow
                set songAlbum to ""
                if (count of UI elements of album) is greater than 0 then
                    set songAlbum to value of static text 1 of group 1 of album
                end if
                set songDuration to ""
                set dur to UI element 5 of aRow
                if (count of UI elements of dur) is greater than 0 then
                    set songDuration to value of static text 1 of group 1 of dur
                end if
                set aLine to quote & songNum & quote & "," & quote & songName & quote & "," & quote & songArtist & quote & "," & quote & songAlbum & quote & "," & quote & songDuration & quote
                set entireContent to entireContent & aLine & return
                tell application "TextEdit" to set text of front document to entireContent
            end if
        end if
    end repeat
end tell

... and this is the error I got:

System Events got an error: Can’t get UI element "Purchased" of group 6 of list 2 of UI element 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of window "iTunes" of application process "iTunes".

With this line highlighted:

click static text "Purchased" of UI element "Purchased" of group 6 of list 2 of webarea

Boris had originally replied:

Does the script go to the Store section in iTunes? If so, what is the name of the link to Purchased (localisation might be the reason)?

I'm guessing that my iTunes interface is different, but I'm not smart enough to amend the code myself ;P.

To access this page, I open iTunes, visit the store, log in to my account (password protected), click "See All" to access purchased items, then am given a drop-down to select the years, then another to select month or all.

Open iTunes > Store > Account > See All > Select year from drop-down > Select all from drop-down

Australian iTunes store - purchase history by last 90 days or year

Can anyone suggest the code to make it work?

You must log in to answer this question.

Browse other questions tagged .