Swift Scripting WWDC 2015 Session Links


Why?

I frequently find myself referring to relevant WWDC sessions and linking to their videos.

How?

Obviously the new hotness is Swift scripting, I just decided to add Automator to the mix.

What?

A brand spankin’ new Automator service running a swift script.

So What?

Before I had to move to a new window highlight the link, copy the link, and move back, and paste it. Now I can just type: 2015 408, highlight it, and press a hotkey.

Not having to move from one screen to another and back again makes this a much better experience.

Here’s the goods…

Download the Automator service, Xcode project, and compiled swift script from the github repo here → https://github.com/iJoeCollins/WWDCLinkService

This was inspired by Ayaka Nonaka’s talk and Hector Matos’s post. You can follow them both @ayanonagon and @allonsykraken respectively.

Here’s how to do it yourself…


Open Xcode and Create a New Command Line Tool


In main.swift, remove everything and paste in this.

#!/usr/bin/swift
import Foundation
let components = Process.arguments[1].componentsSeparatedByString(" ")
print("https://developer.apple.com/videos/wwdc/\(components[0])/?id=\(components[1])")

Build by pressing cmd+b. Then right-click on the product and click Show in Finder.


Now that you have the compiled script, copy it to /usr/local/bin

Voila!


Next…


Open Automator and create a new Service


  • First make sure “Output replaces selected text” is checked.
  • Drag in a Run Shell Script phase
  • pass inputs: as arguments
  • copy and paste the script below
export PATH=$PATH:/usr/local/bin
wwdclink "$@"

It should look like the picture below…

The last thing you have to do is save. Automator should automatically save the service in the proper folder. i.e. ~/Library/services

That’s all you have to do. Your service, mine is named “Get WWDC Session Link”, will be listed in the Services contextual menu.

To use it, type something like “2015 408” without the quotes. This is the year and session number of the video you are looking for. Highlight it, right click and select your Automator service from the Services menu.

That’s all folks.

P.S. If you would like to add a shortcut, open System Preferences, and navigate to Keyboard Shortcuts. Select Services and find your wwdc session link service. Add hotkey.

Happy Coding!


Please recommend this post and follow me @iJoeCollins on twitter.