Archive

Archive for November, 2008

Rebooting an Airport Extreme via AppleScript.

November 29, 2008 5 comments

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
Follow

Get every new post delivered to your Inbox.

Join 144 other followers

%d bloggers like this: