Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Last active September 28, 2024 04:08

Revisions

  1. n8henrie revised this gist Jul 24, 2013. 1 changed file with 22 additions and 11 deletions.
    33 changes: 22 additions & 11 deletions UpdateiOSApps.applescript
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,10 @@ Many thanks to those unknowing contributers that share their Applescript on the
    * 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.
    @@ -51,14 +55,17 @@ tell application "System Events"
    try
    -- If sidebar is shown
    if exists splitter group 1 then
    tell radio button "Updates" of radio group 1 of splitter group 1 to perform action "AXPress"

    -- If sidebar not shown
    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
    delay 1
    tell button "Update All Apps" to perform action "AXPress"
    end try


    @@ -119,12 +126,16 @@ on old_enough()
    delay 30
    tell application "System Events" to tell process "iTunes"
    set frontmost to true
    delay 0.5
    tell window 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"
    end if
    end tell
    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

  2. n8henrie revised this gist May 25, 2013. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions UpdateiOSApps.applescript
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,17 @@ Many thanks to those unknowing contributers that share their Applescript on the
    - 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
    #### 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
    #### 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
    *)

    -- Check if iTunes is running. If not, start it up and give it 30 seconds to get in gear.
  3. n8henrie revised this gist May 25, 2013. 1 changed file with 41 additions and 7 deletions.
    48 changes: 41 additions & 7 deletions UpdateiOSApps.applescript
    Original file line number Diff line number Diff line change
    @@ -3,17 +3,17 @@ Many thanks to those unknowing contributers that share their Applescript on the
    - 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
    ####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
    ####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)
    *)

    -- 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
    tell application "iTunes" to activate
    delay 30
    end repeat

    @@ -42,20 +42,36 @@ tell application "System Events"
    delay 1
    tell window 1

    -- For iTunes 11.0.3
    try
    -- If sidebar is shown
    if exists splitter group 1 then
    tell radio button "Updates" of radio group 1 of splitter group 1 to perform action "AXPress"

    -- If sidebar not shown
    else
    tell radio button "Updates" of radio group 1 to perform action "AXPress"
    end if
    delay 1
    tell button "Update All Apps" to perform action "AXPress"
    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
    -- Compatibility with iTunes 10
    -- 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
    -- 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"
    @@ -67,15 +83,15 @@ tell application "System Events"

    -- If the sidebar is not activated
    else
    -- Compatibility with iTunes 10
    -- 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
    -- 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"
    @@ -89,6 +105,24 @@ tell application "System Events"
    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
    delay 0.5
    tell window 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"
    end if
    end tell
    end tell
    end old_enough

    on isItunesRunning()
    tell application "System Events" to (name of processes) contains "iTunes"
    end isItunesRunning
  4. n8henrie created this gist May 25, 2013.
    94 changes: 94 additions & 0 deletions UpdateiOSApps.applescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,94 @@
    (*
    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)
    *)

    -- 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

    tell splitter group 1

    -- If the sidebar is activated
    if exists splitter group 1 then
    tell splitter group 1
    -- Compatibility with 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
    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
    -- Compatibility with 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
    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

    on isItunesRunning()
    tell application "System Events" to (name of processes) contains "iTunes"
    end isItunesRunning