Table of Contents
Airport Helper v1.1
NOTE: this application has been replaced by the AirPort Monitor Plugin.
Apple’s airport devices are great routers and wifi access points that don’t so far suffer from the number of hacks and problems that other models seem to. One of the ways they get some of that extra security is by not having a web based interface, you have to run their custom application which makes a secure connection to the device to change it’s configuration.
The downside to that is that you could script talking to the web pages of other devices to get your IP address or to do a restart, you can’t do this to an airport.
The AirPort Utility is likewise not scriptable in any reasonable way, nor do they support any other communications methods such an SNMP or anything else. It turns out that the AirPort utility is scriptable through the User Interface Scripting system in OSX. I need to be able to give my airports a regular restart to keep things from getting weird or to force them to restart when the network stops working for whatever reason. I would like to automate this process so undertook to figure out the UI scripting to talk to them. It’s not at all straightforward but it turns out you actually can automate both the reading of the status of your airport units, the connection to the internet, the internet IP address and also restart an airport under scripting control.
Integration with XTension
Limitations in the user interface scripting or possibly bugs in it’s implementation in the AirPort Utility make it impractical to control it directly from a script running inside XTension. So this script is an external script saved as an Application. It will stay running on your machine as long as you wish and will query the AirPort utility every 30 seconds for changes in the status of the connection to the internet, the status of any connected airport and your internet IP address.
The script has lists of both the names of your airports and the names of pseudo units in XTension that you wish to keep in sync with their status. Create a non dimmable pseudo for each airport that you wish to scan and another for the state of the internet. The IP address that the airport thinks it’s getting from the internet will be saved to the description field of the internet state unit. You can add an on descriptionChanged event in that units On script to catch changes to the IP address and send yourself an email or anything else if you wish.
The names of those units must be filled into the proper places in the script.
Scripting a Restart
Scripting a restart of any of your airports from XTension can be done from a global script something like this
tell app “airport helper” to restartAirportByName( “Office”)
For those looking for a way to script a restart of their airports without using this script or who don’t have XTension the meat of that is this:
on restartAirportByName(theName) tell application "System Events" tell process "AirPort Utility" click (first image of group 1 of scroll area 1 of window 1 where its name starts with theName) (* note that the "..." at the end of the Restart menu item name below is NOT just three periods it is the elipsis unicode character. It will not work if you retype that with just three periods. use the keyboard utility to enter it or just copy it from here. *) click menu item "Restart…" of menu "Base Station" of menu bar 1 end tell end tell end restartAirportByName
Please note that the same requirement to register your script or host application in the system preferences under allowed assistive scripting is a requirement for whatever you put that script into. Otherwise it will fail. There also seems to be either a bug in the AirPort Utility app or a limitation in user interface scripting that may not allow that to work if you run it from an application that was not launched specifically by a user action. You also may not be able to run it from a background app. Just cutting and pasting this into an XTension global script does not work. Thats why it became an external script application.
AirPort helper is offered for free to XTension users and completely open and free so that others might gain from it as well. The restart function could easily be pulled into your own scripts if you are not an XTension user. It is also free from warranties or expectations that it will work for you or that it won’t do anything horrible to your own system.
At this moment I know this script will run on OSX version 10.13.4 and with AirPort Utility version 6.3.8. It may run with older or newer versions though there may be problems getting the IP address on earlier OS versions. It will run against almost any XTension version in history.
Download: Airport Helper v1.1 (40k) 5/30/2018
MD5 Hash of the zipfile: c2d353d84e0fa6280d2359fbb5a267d2
The script has complete instructions in it’s initial comments for setting up the system with XTension. You must create the pseudos to hold your airport device status and create any other scripts needed to call the restartAirportByName( name) handler. Additionally the fact that it uses interface scripting means that you must also enable that for the application.
- Open the script in the script editor on the machine where it will live
- make the changes to the script necessary to work with your airport networks and XTension
- Please note that the list of airport names are the names of the devices, NOT the SSID of the network that they are hosting.
- choose “export” from the file menu and export the script as an Application
- choose the “stay open after run handler” option as you want this script to continue to run after it’s launched and keep scanning
- Open the system preferences, go to the “Security & Privacy” pane. And there visit the “Privacy” tab.
- select “Accessibility from the left hand list.
- If necessary “click the lock to make changes” and enter your admin password.
- drag the application you just exported into the list of apps allowed to control your computer and make sure that the checkbox left of it is checked.
- If you make changes to the script and have to re-export you will have to revisit that control panel. It seems to be enough to un-check and re-check the app. If you do not do this it will silently fail to be able to talk to the AirPort Utility and will just tell you all your interfaces are down.
- Launch the app. The AirPort Utility will launch and 30 seconds later it will begin scanning. You’ll get an update for the status of all your airports in XTension and the internet IP address will be added to the description of the internet status unit.
- if you wish create scripts in XTension that call the restart for your airports or send alerts to you if things go offline or your IP changes.
Limitations of the External IP Address Field
Apple does not make it easy to get any of this information out of the application. The WAN IP address is particularly susceptible to getting lost if there are changes to the popover window that displays the data. If you have a firmware update available it may not work or if other things are different there. If you have to temporarily just disable the ip address check by entering a blank name in the script then that will get you past the problem until I find a better way to collect that information.
- version 1.0 released 5/29/2018
- version 1.1 released 5/30/2018
- allows the IP check to be made less frequently than the internet and airport checks
- verifies that the AirPort Utility is running and re-launches it if it has quit or crashed
- can regularly quit and restart the AirPort Utility to let it recover memory leaked in the process of checking the IP address
- you can configure the speed of the checking as well as the frequency of the IP checks and restart times,
- will not cause XTension to relaunch constantly if you are trying to quit it on purpose without quitting the helper app first
- puts the actual text of the airport statuses into the description field of your airport status units in XTension.