7

I'm wondering if anyone has found a way to download one's entire iTunes or App Store purchase history as a CSV file?

I know that from within iTunes I can go to Account / View Account / Purchase History, but this has numerous problems. It does not let me download the results, but only shows them in iTunes. It does not show all purchases, but instead shows results one screenful at a time. And it does not even show purchases as individal line items, but shows them grouped into collections you need to click into. It's almost like they're trying to make it hard to see how you spend on the App Store or iTunes Store....

I have not been assiduously saving all the email receipts regarding my purchases, so I cannot access this information by doing bulk processing of those old emails.

So is there any other way to get access to this information except for the inadequate iTunes interface?

And if the only way is via the iTunes interface, is there any way to script the UI so I could write a program that iterated through all results and extracted them? Has anyone actually succeeded in doing this?

| improve this question | | | | |
  • If no one scrapes the data, do consider just asking Apple Support for a summary. They might be able to get you the data if you ask and explain how you tried and failed to download it with the tools they provide. – bmike Jul 13 '15 at 1:44
  • are you asking for beyond 90 days ? – Ruskes Jul 13 '15 at 3:04
  • Yes. I want to figure out how much money I've been spending monthly since 2007 on this stuff. Second, I want to inventory all purchases I've made that will not be shareable via iCloud family sharing, which excludes in-app purchases and non-shareable apps among other things. – algal Jul 13 '15 at 3:06
  • Aside of looking in the purchases history in the App Store, you are probably better off looking at your credit card reports that can be downloaded as CSV file. – Ruskes Jul 13 '15 at 3:13
  • Yup, that will work for figuring out the total spend. But only iTunes (only Apple...) can provide the per purchase information needed to identify in-app purchases and to distinguish music from app purchases. Seems like the only way is screen scraping, which is another way of saying I'm out of luck... – algal Jul 13 '15 at 3:17
6

You asked, "is there any way to script the UI?" Yes, if you are on a Mac. You also asked, "Has anyone actually succeeded in doing this?" Sort of. My history goes back to 2005, and the iTunes Store session kept timing out, so I had to run it it batches, but the following script does work. Be aware that it runs very slowly; simply retrieving the class of an object from iTunes can take almost a second. I would welcome any performance enhancements anyone can suggest.

This worked on OS X Yosemite 10.10.5 with iTunes 12.3.2.35, and on OS X Mavericks 10.9.5 with iTunes 12.3.2.35, on or around February 28th, 2016. Any changes Apple makes to the iTunes Store account interface will likely break this script.

In iTunes, go to Store > View Account, log in, scroll to Purchase History and click See All, then, when the screen showing Batch 1 out of N is visible, run the following script in Script Editor:

tell application "System Events"
    set dateString to do shell script "date \"+%Y-%m-%d_%H.%M.%S\""
    log dateString
    set target_file to ((path to documents folder) as text) & dateString & "_iTunes_Purchase_History.txt"
    set myOutput to ""

    set webArea to UI element "loading iTunes store" of splitter group 1 of window "iTunes" of application process "iTunes"
    set batchText to value of first UI element of webArea whose value starts with "Viewing Batch"
    log batchText
    set AppleScript's text item delimiters to {" "}
    set num to last text item in batchText
    log num
    set currentNum to text item 3 in batchText
    log currentNum

    repeat num times
        set els to UI elements of webArea
        set ready to false
        set open_target_file to open for access file target_file with write permission
        --repeat with el in els
        repeat with el in els
            set cl to class of el
            if cl is button then
                set myOutput to myOutput & "\n"
            end if
            if cl is static text then
                set val to value of el
                if val starts with "Copyright" then set ready to false
                if ready then set myOutput to myOutput & val & "\t"
                if val is "Total Price" then set ready to true
            end if
        end repeat
        log myOutput
        write myOutput to open_target_file starting at eof
        set myOutput to ""
        close access open_target_file

        click button "Next" of webArea
        repeat
            delay 2
            set batchText to value of first UI element of webArea whose value starts with "Viewing Batch"
            set tempNum to text item 3 in batchText
            if tempNum is not currentNum then
                set currentNum to tempNum
                log currentNum
                exit repeat
            end if
        end repeat
        delay 2
    end repeat
end tell

This produces tab-delimited text, not CSV as the OP requested, but most spreadsheet applications will import it. Gift purchases seem to mess up the formatting, so it may need some manual curation.

I relied on information at http://n8henrie.com/2013/03/a-strategy-for-ui-scripting-in-applescript/ to learn how to do GUI scripting.

| improve this answer | | | | |
  • Sadly it seems that this no longer works on macOS Sierra and iTunes 12.5.3.x – Bradley MacDonald Dec 1 '16 at 15:54
  • it produces this error in Sierra: System Events got an error: Can’t get UI element 1 of UI element "loading iTunes store" of splitter group 1 of window "iTunes" of application process "iTunes" whose value starts with "Viewing Batch". Invalid index. – Bjørson Ålmer Jan 19 '17 at 23:53
  • (I added this comment in the wrong place: to the question, not the answer …) Worked perfectly for me. MacOS Sierra 10.12.4, 56 batches. Too about 1.5 hours. The data wasn’t perfectly formatted due to inconsistencies in the actual data, but that was easy to fix afterwards. Thanks for a most useful script! Too bad I can’t add it directly to iTunes. – Manngo Apr 7 '17 at 11:35
  • Wow thanks so much! Followed directions next to the script and it ran slowly as you said. And gave me a perfect file that opened cleanly in excel. Using OSX 10.11.6. – Todd Aug 9 '17 at 7:52
  • This works on High Sierra 10.13.5 and newest iTunes: apple.stackexchange.com/a/325065/191531 – boris42 May 11 '18 at 16:35
0

I use a windoze machine mostly and found a semi-manual way to accomplish the task as follows:

In iTunes Navigate to Account Info (currently at upper right of iTunes next to search button). Scroll down to Purchase History, click "See All".

  1. Use Greenshot to capture the purchase info
  2. Paste from clipboard into One-Note,
  3. Use "Image to Text option" on pasted image.
  4. Paste Text into One-Note - or another document.
  5. Correct and reformat as needed.

Click "Next" button and wait for iTunes to give you the next dozen entries. Repeat, repeat, repeat.

Sample One-Note screen of iTunes purchases

Hint: Seems by default the view is of the latest purchases and "Next" goes backward through time. Also note, that multiple purchases in the same day (like albumbs) get lumped together and you have to click the tiny -> symbol to see meaningful details.

| improve this answer | | | | |
0

this script actually does work! just not as expected…

  1. i followed the directions, but i got an error: something about not being able to handle the TITLES as a string (?). this took about 2-3 minutes.
  2. first suspicions:
    • when i copy-n-pasted the code into Script Editor, the following lines were “interpreted” i.e. \n showed up as a [literal/visual] line break, as did \t showing up as a tab [literal/visual]
      • set myOutput to myOutput & "\n"
      • if ready then set myOutput to myOutput & val & "\t"
    • commas separating the “Titles included in order” indicating multiple purchases in a single day
    • i was wrong… i think… i dunno.
  3. on a lark, i jumped to the LAST batch (apparently, my fist purchase with this account was in 2004 which meant 49 batches) and ran the script again
    • result: the script was running longer than expected, so i assumed an error and stopped the process after about 10 minutes… BUT there WAS a *.txt file generated [in my Documents folder]. this file showed data for
      • the LAST batch [that was showing in iTunes when i started the script] THEN
      • the FIRST batch [BATCH 1, showing my most recent purchases]
      • when i went to iTunes, i noticed that BATCH 2 was displayed
    • conclusion: the command for the NEXT button (click button "Next" of webArea) was working. SOMETHING WAS HAPPENING!!! (…and my theory about the commas was diminished)
  4. in order to get the info i needed (batches 1-13 of 49), i did the following:
    • jumped to the LAST batch (here, the 49th batch)
    • ran the script
    • i monitored iTunes, and watched the batch display automatically change until it showed BATCH 14
    • i stopped the script and checked the *.txt file in my Documents folder
    • LO! the *.txt file showed my purchases from [my last] BATCH 49 through BATCH 13!
  5. not done yet! i wanted to repeat the initial error to record the exact error and to see if my initial suspicions made sense. NOPE! i started from the beginning, and THIS:
    • the script ran as expected
    • the only error (so far, because i’m still running the script) was a lost connection timeout at BATCH 21

currently, the script is working on BATCH 32…

TIMING:

  • based on the creation date of the generated *.txt file and the modification times (which i am also monitoring), it looks like each batch takes about 3 minutes to process and update said *.txt file.
  • so far, for my 49 batches (lost connection timeout NOT included) it’s taken…
    • BATCHES 1-21 = @45 minutes
    • BATCHES 21-49 (in progress: current SAVED batch = 34) = @30 minutes

i know… TMI! TMI!
but i hope this helps!



EDIT:

  1. RE: #5 above… “ the only error (so far, because i’m still running the script) was a lost connection timeout at BATCH 21”
    • i re-started the script, starting at BATCH 21 (where the lost connection timeout happened)
    • i expected it to end at BATCH 1… NOPE! it kept going, uninterrupted, until it rounded upon itself and recorded up to BATCH 20 (which will display BATCH 21 in iTunes upon completion)

CONCLUSION: the script will run from BATCH[n] to BATCH[n-1] (provided NO timeouts/interruptions)

| improve this answer | | | | |
  • By This script actually does work, do you mean the one offered by jjpr in their answer? Regardless, it'd be good if you could clarify so that other readers know what you're referring to and aren't having to guess. – Monomeeth Mar 28 '17 at 5:17

You must log in to answer this question.

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