Skip to content

Instantly share code, notes, and snippets.

@haikusw
Forked from bjhomer/currentTrack.swift
Last active August 29, 2015 14:09
Show Gist options
  • Save haikusw/f7bcb44da441af255bac to your computer and use it in GitHub Desktop.
Save haikusw/f7bcb44da441af255bac to your computer and use it in GitHub Desktop.
#! /usr/bin/swift
import ScriptingBridge
@objc protocol iTunesTrack {
optional var name: String! {get}
optional var album: String! {get}
}
@objc protocol iTunesApplication {
optional var soundVolume: Int {get}
optional var currentTrack: iTunesTrack! {get}
}
extension SBApplication : iTunesApplication {}
let app: iTunesApplication = SBApplication(bundleIdentifier: "com.apple.iTunes")
// Because these are all optional properties (to avoid providing an implementation), we have to '!' the result out.
let track = app.currentTrack!
let album = track.album!
let trackName = track.name!
println("Current track: \(trackName) - \(album)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment