Skip to content

Instantly share code, notes, and snippets.

@larryfox
Created April 29, 2016 01:15
Show Gist options
  • Save larryfox/7fd6fe7b765fae0f6a82ed731dcd2789 to your computer and use it in GitHub Desktop.
Save larryfox/7fd6fe7b765fae0f6a82ed731dcd2789 to your computer and use it in GitHub Desktop.
Get info about the currently playing iTunes track
#!/usr/bin/env bash
read -r -d '' JS <<JS
function run () {
var iTunes = Application("iTunes")
if (!iTunes.running()) { return JSON.stringify({ state: "closed" }) }
var state = iTunes.playerState()
if ('stopped' === state) { return JSON.stringify({ state: state }) }
var current = iTunes.currentTrack()
var position = iTunes.playerPosition()
return JSON.stringify({
state: state,
artist: current.artist(),
name: current.name(),
album: current.album(),
duration: current.duration(),
position: position,
remaining: current.duration() - position
})
}
JS
osascript -l JavaScript -e "$JS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment