0

Has anyone found a way to download iTunes Purchase history into some type of csv or text format?

The closest thing I could find was this StackExchange answer of a great applescript that could automate this task, but the script doesn't work with High Sierra and the newer versions of iTunes.

https://apple.stackexchange.com/a/229240/288140

1 Answer 1

1

The following works on currently latest macOS I'm using (High Sierra 10.13.5 Beta) and latest iTunes (12.7.4.76).

I've written an AppleScript that is using UI Scripting and compiles a list of purchased songs on iTunes. The script will open a new TextEdit document and fill in the songs in a comma delimited format and will contain the sequential number, song name, artist, album and song duration. The output will be similar to this:

"Nr","Song Name","Artist","Album","Duration"
"1","Badinerie","Lucero Tena","Lección de castañuelas","1:03"
"2","El colibrí","Lucero Tena","Lección de castañuelas","1:07"
"3","El relicario","Lucero Tena","Lección de castañuelas","1:36"

itunes

Here is the script:

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 1 of UI element 1 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

The process is not fast, on my computer it takes about 1 second per song so be prepared to wait a while. Also, if you start getting some "out of index" errors try, while the script is running, scrolling the iTunes song list in the background to make sure the entire list content is loaded before being accessed by AppleScript.

3
  • I'm using High Sierra OS 10.13.4 (17E202) with iTunes 12.7.4.76, and when I run this script I get the following error: 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 Any ideas on what's going wrong?
    – Stephen
    Commented May 18, 2018 at 8:09
  • @Stephen 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)?
    – boris42
    Commented May 18, 2018 at 8:16
  • @Stephen try the updated script where I replaced the text "Purchased" with access by index, should work better
    – boris42
    Commented May 19, 2018 at 11:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .