Skip to content

Instantly share code, notes, and snippets.

@SLboat
Forked from bjhomer/currentTrack.swift
Created May 16, 2019 22:33
Show Gist options
  • Select an option

  • Save SLboat/ab7acd970b25923a0c0856b60f1676b5 to your computer and use it in GitHub Desktop.

Select an option

Save SLboat/ab7acd970b25923a0c0856b60f1676b5 to your computer and use it in GitHub Desktop.

Revisions

  1. @bjhomer bjhomer revised this gist Nov 16, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion currentTrack.swift
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,8 @@ 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.
    // Because these are all optional properties (to avoid providing an implementation), we have
    // to use '!' to indicate we know the implementation exists.
    let track: iTunesTrack? = app.currentTrack!
    let album = track?.album!
    let trackName = track?.name!
  2. @bjhomer bjhomer revised this gist Nov 16, 2014. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions currentTrack.swift
    Original file line number Diff line number Diff line change
    @@ -3,23 +3,23 @@
    import ScriptingBridge

    @objc protocol iTunesTrack {
    optional var name: String! {get}
    optional var album: String! {get}
    optional var name: String {get}
    optional var album: String {get}
    }

    @objc protocol iTunesApplication {
    optional var soundVolume: Int {get}
    optional var currentTrack: iTunesTrack! {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!
    let track: iTunesTrack? = app.currentTrack!
    let album = track?.album!
    let trackName = track?.name!


    println("Current track: \(trackName) - \(album)")
  3. @bjhomer bjhomer revised this gist Nov 16, 2014. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion currentTrack.swift
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,6 @@ import ScriptingBridge
    @objc protocol iTunesTrack {
    optional var name: String! {get}
    optional var album: String! {get}
    optional var foo: String! {get}
    }

    @objc protocol iTunesApplication {
  4. @bjhomer bjhomer revised this gist Nov 16, 2014. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion currentTrack.swift
    Original file line number Diff line number Diff line change
    @@ -16,8 +16,11 @@ import ScriptingBridge
    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: \(track.name) - \(album)")
    println("Current track: \(trackName) - \(album)")
  5. @bjhomer bjhomer renamed this gist Nov 16, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @bjhomer bjhomer created this gist Nov 16, 2014.
    23 changes: 23 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #! /usr/bin/swift

    import ScriptingBridge

    @objc protocol iTunesTrack {
    optional var name: String! {get}
    optional var album: String! {get}
    optional var foo: 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")
    let track = app.currentTrack!
    let album = track.album!


    println("Current track: \(track.name) - \(album)")