property last_secs : 10 property min_delay : 5 tell application "iTunes" repeat if player state is playing and special kind of current playlist is Party Shuffle then -- it is playing, and in party shuffle -- determining how much time we left from the song set curpos to player position set maxpos to finish of the current track set time_to_enter to maxpos - curpos - (my last_secs) if time_to_enter <= 0 then -- Ok, we are in the last 10 seconds, updating the last played count set played date of the current track to current date delay my last_secs else -- No, we are not there if (time_to_enter < my min_delay) then delay my min_delay else delay time_to_enter end if end if -- display dialog "Curpos:" & curpos & ", Maxpos: " & maxpos & "Current date: " & (current date) buttons {"OK"} else -- it is not playing or not in party shuffle -- waiting and trying again -- display dialog "Not my cup of tee" buttons {"OK"} delay my min_delay end if end repeat end tell