Last active
September 28, 2024 04:08
-
-
Save n8henrie/5649326 to your computer and use it in GitHub Desktop.
Uses UI Scripting to Update iOS Apps in iTunes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
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 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 | |
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment