views:

147

answers:

2

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.

A: 

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.

Philip Regan
A: 

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).

Chris Johnsen
This is correct. I actually figured it out late late last night and was coming here to update. Thanks though for all the extra stuff. I was just gonna do some calculations in a perl script with the seconds but the fractional time is much more accurate.
sanpaco