Home > AppleScript, Geeky, Mac OS X > Rebooting an Airport Extreme via AppleScript.

Rebooting an Airport Extreme via AppleScript.

After the latest firmware update for my saucer-shaped Airport Extreme base station, I’ve found myself rebooting my Airport on a much more regular basis than I had before. Before the update, I was rebooting it once in a blue moon. Now, I’m rebooting it once every couple of days. The routine goes something like this:

*Get home*
*Wife fires up her laptop*
“Honey, the internet’s broken.”
*I trudge down to my basement office and power-cycle the base station*
*Walk back up*
“Is it working now?”
“Yup.”

This got old fast, so I started thinking about ways to reboot my Airport base station nightly, preferably without human involvement. A quick Google showed surprisingly few people trying to accomplish this, but the nice folks who had also posted their AppleScripts. I’m hardly an AppleScript master, but I was able to pull together the following script using this entry from MacOSXHints, as well as this one from David Chan.

———–

tell application "AirPort Utility" to activate
delay 2
tell application "System Events"
	tell application process "AirPort Utility"
		
		tell window 1
			click button "Manual Setup"
			delay 60
		end tell
		
		tell menu bar 1
			click menu bar item "Base Station"
			
			tell menu bar item "Base Station"
				tell menu 1
					click menu item "Restart…"
				end tell
			end tell
		end tell
		
		delay 1 --imperative
		
		delay 30
		
	end tell
end tell

tell application "AirPort Utility" to quit

———–

I later added the ability to log to a file in ~/Library/Logs by using this additional script from MacOSXHints, so my current script looks like this:

———–

set commonScript to load script alias ¬
	((path to library folder from user domain as string) ¬
		& "Scripts:Common code.scpt")

tell application "AirPort Utility" to activate
delay 2
tell application "System Events"
	tell application process "AirPort Utility"
		
		tell window 1
			click button "Manual Setup"
			delay 60
		end tell
		
		tell menu bar 1
			click menu bar item "Base Station"
			
			tell menu bar item "Base Station"
				tell menu 1
					click menu item "Restart…"
				end tell
			end tell
		end tell
		
		delay 1 --imperative
		
		delay 30
		
	end tell
end tell

tell application "AirPort Utility" to quit

log_event("Basement Airport Extreme restarted") of commonScript

———–
The last piece of the puzzle was figuring out how to trigger it, but iCal came to the rescue. Maria Langer posted a good write-up on how to do this up on her site, which I was able to use to help me set up a recurring appointment at 12:00 AM every day to reboot the Airport, with the alarm for the event triggering the script that actually reboots the Airport.

restart_airport

Categories: AppleScript, Geeky, Mac OS X
  1. November 30, 2008 at 1:41 am

    Glad you found my script helpful!

  2. December 1, 2008 at 2:24 pm

    And I’m glad you found my iCal scheduling trick helpful! I use it for all kinds of things. Most recently, I set it up to

    But here’s dumb question: why not simply attach the power cord of the AirPort base station to a light timer with a short delay between power down and power up? Would that mess up the base station’s innards? I hope not, because that’s how I reset mine when it stops working.

  3. December 1, 2008 at 3:07 pm

    Maria,

    I set it up this way because it was a fun project during a long weekend and the box that handles the reboot is up all of the time anyway, performing a different job in addition to rebooting my Airport.

  4. Brian Millar
    August 21, 2012 at 3:29 pm

    Found this post and thought it was just the thing that I’ve been looking for. Know absolutely nothing about AppleScript, so am only really ok with very simple changes etc, but I was wondering have you found a way to achieve the same capabilities using AppleScript and the later version of AirPort Utility – I currently have 6.1.

    Many thanks

  1. February 6, 2009 at 6:39 pm

Leave a comment