Starting with version 1.7.0 Porthole is scriptable using Apple's AppleScript Editor (or Script Editor in Yosemite). This means that you can automate and toggle certain functions of Porthole without going through the interface.
These are a few cases in which scripting could come in handy:
- Automatically connecting to a certain (or every) speaker on startup.
- Chaining several actions in one, such as: starting Spotify, playing a song and then connecting to all your AirPlay devices. You can put that in a single script.
- You could use it to develop a remote control.
- And obviously any case where you want to control Porthole without going through the interface.
- Download the latest version of Porthole, or make sure you're on version 1.7.0 or higher.
- Launch Porthole at least once and set it up.
- Start (Apple)Script Editor.app (find it in /Applications/Utilities/(Apple)Script Editor.app).
When you have AppleScript Editor running, paste in the script below to get the name of the first speaker Porthole's found. Press the big green "Run" button when you're done.
1 2 3
As you were probably expecting, Porthole should now be connected to the first speaker it found. Pretty sweet!
Say that you always want to connect to a certain speaker when your Mac boots up. There are a few things we need to do for this to work:
- Get a unique identifier for our speaker.
- Use that unique identifier to connect to the specific speaker.
- Run the script on startup.
Getting the Unique Identifier
Run this script:
1 2 3 4 5 6
It should return something along the lines of this:
1 2 3 4
Use the Unique Identifier
he first value is the MAC address and unique identifier of the speaker, we'll use this to pick out a specific speaker to connect to.Let's pick "Boy & Auk's AirPort Express" in this case. Make sure you replace the id with the value that was returned on your Mac.
1 2 3 4 5 6
And that's it, Porthole will only connect to that specific speaker. Run the script to test it.
Run the Script on Startup
You can actually turn Scripts into Applications, which you can add to your Login Items. Perfect, exactly what we need. Before we do this though, lets make a tiny modification to our script.
1 2 3 4 5 6 7 8
The 'activate' command will load Porthole if it isn't already running. Then the delay will give Porthole ten seconds to discover any available speakers. After that the script runs like it did before.
To turn this into an app, in (Apple)Script Editor, click File → Export... and in the dialog box that opens choose Application under File Format.
Save the file anywhere you like, but remember its location.
Finally, go into System Preferences and select Users & Groups, then Login Items. Press the little + button and pick the Application you just created. Your script will now run at login!
Version 1.7.1 and up.
Porthole sends out system wide notifications when an AirPlay speaker appears/disappears/connects/disconnects and when the computer speaker setting is toggled. This removes the need to poll for changes.
To receive these notifications, hook into the NSDistributedNotificationCenter event:
1 2 3 4 5 6 7 8 9 10 11 12
The notification's userInfo contains a dictionary with the current speaker setup:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
These are all the Porthole-specific commands you can use. For a more general AppleScript tutorial, have a look at this guide.
- Addresses a single speaker. Properties: id, name, connected, streaming.
- every speaker
- Addresses all speakers.
- first|second|...|last speaker
- Addresses the first/second/etc speaker. You can also use speaker 1,2,3,etc.
- connect to [speaker(s)]
- Connect to the specified speaker(s).
- disconnect from [speaker(s)]
- Disconnect from the specified speaker(s).
- use computer speaker [boolean]
- Enable or disable the (connected) computer speaker.
This is a property. You can set like so:
1 2 3