Question

I'm just starting to play around with Geektool and applescripting to make my mac desktop fun and I've run into a question I can't seem to find an answer to. How do you get the current song playtime from an osascript command? I've found great resources on how to do just about anything else with iTunes and osascript on the command line but no one seems to care at all about showing the current playtime. Thanks! I'm assuming it will be something like:

osascript -e 'tell application "iTunes" to time of current track'

I already tried that though and it tells me how long the song is. I want to know how long it has been playing.

Was it helpful?

Solution

iTunes Suite / application:

player position (integer) : the player’s position within the currently playing track in seconds.

 $ osascript -e 'tell app "itunes" to player position'
 56

It will return missing value if no song is playing/paused (like after starting iTunes, but before playing anything).


While you are at it, you might as well ask for the track's duration, start and finish points:

$ osascript -e 'tell app "itunes" to {duration, start, finish} of current track & {player position}'
0.0, 254.772003173828, 254.772003173828, 55

The duration (fractional seconds) might be nicer to work with than the time (string in MM:SS format).

OTHER TIPS

The iTunes Applescript dictionary doesn't have an elapsed time function or property for any of the classes. You'll have to roll your own.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top