Glen Solsberry
Glen Solsberry

Reputation: 12320

iTunes track Played Date

The following AppleScript works as expected, giving me the last played value for the first track in the the specified user playlist.

tell application "iTunes"
    set theTrack to (item 1 of tracks of user playlist "Named")
    set playedDate to played date of theTrack
    display dialog (playedDate as string)
end tell

This AppleScript however, will not compile and instead gives me an error Expected end of line, etc. but found class name.

tell application "iTunes"
    my testMethod(item 1 of tracks of user playlist "Named")
end tell

on testMethod(theTrack)
    set trackName to (name of theTrack)
    display dialog trackName
    -- set playedDate to played date of theTrack
    -- display dialog playedDate        
end testMethod

Are these two scripts so different that AppleScript's compiler goes wonky? How do I get played date of theTrack in to playedDate in the second example?

Upvotes: 0

Views: 112

Answers (1)

vadian
vadian

Reputation: 285082

played date is a part of the iTunes application terminology, you need an application tell block

tell application "iTunes"
    set playedDate to played date of theTrack
end tell

or an using terms from application block to help the compiler to resolve the terminology

using terms from application "iTunes"
    set playedDate to played date of theTrack
end using terms from

You might now ask: why does name work? Well, name is a well-known property in many applications and even the AppleScript runner knows it.

Upvotes: 1

Related Questions