Last active
November 17, 2015 16:51
-
-
Save zushane/e097aa805bd010467665 to your computer and use it in GitHub Desktop.
A simple script to do unattentded reboot of Airport devices. It assumes that all of the devices are sequential, with none to skip. Works best on a server.
This file contains hidden or 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
-- | |
-- Simple script to do unattented reboot of Airport devices. | |
-- Assumptions: all the devices are sequential, with none to skip. | |
-- | |
-- only run this script if it's before 5am. | |
set foo to do shell script "date +%H" | |
set thisHour to foo as number | |
if thisHour < 5 then | |
-- start Airport Utility | |
tell application "AirPort Utility" | |
activate | |
end tell | |
-- wait for Airport Utility to start | |
delay 5 | |
tell application "System Events" | |
tell application process "AirPort Utility" | |
-- bring the application to the front. | |
set frontmost to true | |
perform action "AXRaise" | |
set thepassword to "AIRPORT_PASSWORD" | |
-- max is total number of devices to reboot. | |
set max to 5 | |
-- enter the password on the first Airport, to be used for the rest of them. | |
try | |
click image 2 of group 1 of scroll area 1 of window 1 | |
click button "Enter Password" of pop over 1 of image 2 of group 1 of scroll area 1 of window 1 | |
set value of text field 1 of sheet 1 of window 1 to thepassword | |
click button "OK" of sheet 1 of window 1 | |
on error | |
log "Couldn't enter password. It's probably already set." | |
end try | |
delay 2 | |
-- repeat the following for max devices. | |
repeat with n from 2 to max | |
-- click the airport device image | |
click image n of group 1 of scroll area 1 of window 1 | |
delay 2 | |
try | |
-- click the "Base Station > Restart..." menu item. | |
click menu item 3 of menu "Base Station" of menu bar 1 | |
delay 2 | |
-- click "Continue" on pop up window. | |
click button "Continue" of sheet 1 of window 1 | |
delay 2 | |
on error | |
log "Couldn't restart base station number " & n | |
end try | |
end repeat | |
end tell | |
-- All done, quit Airport Utility. | |
tell application "AirPort Utility" to quit | |
end tell | |
set theContent to "Unattended reboot of the Airport WiFi routers is complete." | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be launched on a schedule using Launchd. I call it from a bash script that does some mailing to let me know that it's been attempted.