Skip to content

Instantly share code, notes, and snippets.

@AlexSatrapa
Forked from n8henrie/UpdateiOSApps.applescript
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexSatrapa/33a1a4b149667da9c327 to your computer and use it in GitHub Desktop.
Save AlexSatrapa/33a1a4b149667da9c327 to your computer and use it in GitHub Desktop.
(*
Many thanks to those unknowing contributers that share their Applescript on the web. A few that helped with this script include:
- Most of the UI Scripting came from Yoshimasa Niwa here: https://gist.github.com/4223249
- Code for checking if an app is running came from here: http://codesnippets.joyent.com/posts/show/1124
#### n8henrie Sat Mar 16 14:41:41 MDT 2013
* Added several delays that seemed to be responsible for breaking this script in iTunes 11
#### n8henrie Sun Mar 17 09:57:47 MDT 2013
* Added compatibility with iTunes 10 (untested, please confirm if you can)
* Added compatibility with having the iTunes sidebar activated (thanks to mattb in the comments)
#### n8henrie Sat May 25 09:27:12 MDT 2013
* Added compatibility with iTunes 11.0.3
* Re-added "I am 18 or over" dialog box clicker
#### n8henrie Wed Jul 24 17:00:42 MDT 2013
* Fixed iTunes 11.0.3 problem with sidebar and "error number -1728"
* Added repeat loop for multiple "I am over 18" confirmation boxes
*)
-- Check if iTunes is running. If not, start it up and give it 30 seconds to get in gear.
repeat while not isItunesRunning()
tell application "iTunes" to activate
delay 30
end repeat
-- In case anything has stolen focus during the delay, bring it back into focus. I do this several times, after most delays.
tell application "iTunes" to activate
delay 1
--CMD 7 to get to the "Apps" screen
tell application "System Events" to keystroke "7" using command down
delay 5
tell application "iTunes" to activate
delay 1
--CMD r to check for update apps
tell application "System Events" to keystroke "r" using command down
delay 10
tell application "iTunes" to activate
delay 1
--Now for clicking the "Download All Free Updates" button and the "are you old enough" dialog box that often comes afterward.
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 1
tell window 1
-- For iTunes 12.0.1
try
if exists radio group 2 then
tell radio button "Updates" of radio group 2 to perform action "AXPress"
tell button "Update All Apps" to perform action "AXPress"
end if
end try
-- For iTunes 11.0.3
try
-- If sidebar is shown
if exists splitter group 1 then
tell splitter group 1
tell radio button "Updates" of radio group 1 to perform action "AXPress"
delay 1
tell button "Update All Apps" to perform action "AXPress"
-- If sidebar not shown
end tell
else
tell radio button "Updates" of radio group 1 to perform action "AXPress"
delay 1
tell button "Update All Apps" to perform action "AXPress"
end if
end try
-- For < 11.0.3
tell splitter group 1
-- If the sidebar is activated
if exists splitter group 1 then
tell splitter group 1
-- For iTunes 10
if exists UI element "iTunes store" then
tell UI element "iTunes store"
tell UI element "Download All Free Updates"
if exists then perform action "AXPress"
end tell
end tell
-- For iTunes 11 - 11.0.3
else if exists UI element "loading iTunes store" then
tell UI element "loading iTunes store"
tell UI element "Download All Free Updates"
if exists then perform action "AXPress"
end tell
end tell
end if
end tell
-- If the sidebar is not activated
else
-- For iTunes 10
if exists UI element "iTunes store" then
tell UI element "iTunes store"
tell UI element "Download All Free Updates"
if exists then perform action "AXPress"
end tell
end tell
-- For iTunes 11 - 11.0.3
else if exists UI element "loading iTunes store" then
tell UI element "loading iTunes store"
tell UI element "Download All Free Updates"
if exists then perform action "AXPress"
end tell
end tell
end if
end if
end tell
end tell
end tell
end tell
-- Click the stupid "i am 18 or older" dialog box
try
old_enough()
end try
--CMD 1 to get to the "Music" screen
tell application "System Events" to keystroke "1" using command down
delay 5
on old_enough()
delay 30
tell application "System Events" to tell process "iTunes"
set frontmost to true
repeat
tell window 1
delay 1
if exists static text "Click OK to confirm that you are 17 or over. Your content will then begin downloading immediately." then
tell button "OK" to perform action "AXPress"
else if exists static text "There are no updates available for any of the apps in your iTunes library." then
tell button "OK" to perform action "AXPress"
else
break
end if
end tell
end repeat
end tell
end old_enough
on isItunesRunning()
tell application "System Events" to (name of processes) contains "iTunes"
end isItunesRunning
@AlexSatrapa
Copy link
Author

Opens iTunes, instructs iTunes to check for updated iOS apps, then dismisses various dialogs that appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment