Advertisement
n8henrie

Update iOS Apps in iTunes

Dec 16th, 2012
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2. Many thanks to those unknowing contributers that share their Applescript on the web. A few that helped with this script include:
  3. - Most of the UI Scripting came from Yoshimasa Niwa here: https://gist.github.com/4223249
  4. - Code for checking if an app is running came from here: http://codesnippets.joyent.com/posts/show/1124
  5.  
  6. ####n8henrie Sat Mar 16 14:41:41 MDT 2013
  7. * Added several delays that seemed to be responsible for breaking this script in iTunes 11
  8.  
  9. ####n8henrie Sun Mar 17 09:57:47 MDT 2013
  10. * Added compatibility with iTunes 10 (untested, please confirm if you can)
  11. * Added compatibility with having the iTunes sidebar activated (thanks to mattb in the comments)
  12. *)
  13.  
  14. -- Check if iTunes is running. If not, start it up and give it 30 seconds to get in gear.
  15. repeat while not isItunesRunning()
  16.     tell application "iTunes" to activate
  17.     delay 30
  18. end repeat
  19.  
  20. -- In case anything has stolen focus during the delay, bring it back into focus. I do this several times, after most delays.
  21. tell application "iTunes" to activate
  22. delay 1
  23.  
  24. --CMD 7 to get to the "Apps" screen
  25. tell application "System Events" to keystroke "7" using command down
  26. delay 5
  27.  
  28. tell application "iTunes" to activate
  29. delay 1
  30.  
  31. --CMD r to check for update apps
  32. tell application "System Events" to keystroke "r" using command down
  33. delay 10
  34.  
  35. tell application "iTunes" to activate
  36. delay 1
  37.  
  38. --Now for clicking the "Download All Free Updates" button and the "are you old enough" dialog box that often comes afterward.
  39. tell application "System Events"
  40.     tell process "iTunes"
  41.         set frontmost to true
  42.         delay 1
  43.         tell window 1
  44.            
  45.             tell splitter group 1
  46.                
  47.                 -- If the sidebar is activated
  48.                 if exists splitter group 1 then
  49.                     tell splitter group 1
  50.                         -- Compatibility with iTunes 10
  51.                         if exists UI element "iTunes store" then
  52.                             tell UI element "iTunes store"
  53.                                 tell UI element "Download All Free Updates"
  54.                                     if exists then perform action "AXPress"
  55.                                 end tell
  56.                             end tell
  57.                            
  58.                             -- for iTunes 11
  59.                         else if exists UI element "loading iTunes store" then
  60.                             tell UI element "loading iTunes store"
  61.                                 tell UI element "Download All Free Updates"
  62.                                     if exists then perform action "AXPress"
  63.                                 end tell
  64.                             end tell
  65.                         end if
  66.                     end tell
  67.                    
  68.                     -- If the sidebar is not activated     
  69.                 else
  70.                     -- Compatibility with iTunes 10
  71.                     if exists UI element "iTunes store" then
  72.                         tell UI element "iTunes store"
  73.                             tell UI element "Download All Free Updates"
  74.                                 if exists then perform action "AXPress"
  75.                             end tell
  76.                         end tell
  77.                        
  78.                         -- for iTunes 11
  79.                     else if exists UI element "loading iTunes store" then
  80.                         tell UI element "loading iTunes store"
  81.                             tell UI element "Download All Free Updates"
  82.                                 if exists then perform action "AXPress"
  83.                             end tell
  84.                         end tell
  85.                     end if
  86.                 end if
  87.             end tell
  88.         end tell
  89.     end tell
  90. end tell
  91.  
  92. on isItunesRunning()
  93.     tell application "System Events" to (name of processes) contains "iTunes"
  94. end isItunesRunning
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement