Created
April 29, 2016 01:15
-
-
Save larryfox/7fd6fe7b765fae0f6a82ed731dcd2789 to your computer and use it in GitHub Desktop.
Get info about the currently playing iTunes track
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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