Add note about current iTunes track to DEVONthink

I wrote an Applescript that adds information about the current track in iTunes to a new DEVONthink note. Especially it ads the player position. So you can take notes about an exact position of a track/podcast/recording…

It would be useful if there was a way to start the track from this DEVONthink note. Is there a way to do this?

I’m just an amateur-AppleScripter, so this script might be buggy. Use it at your own risk.

tell application "iTunes"
	activate
	
	set this_track to ""
	
	-- get playing track
	if player state is playing then
		set this_track to current track
	end if
	
	-- if no track is playing, get selected track
	if this_track is "" and selection is not {} then
		set this_track to item 1 of selection
	end if
	
	-- no track is playing or selected
	if this_track is "" then
		display dialog "No track is selected or playing..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
	end if
	
	-- get the information of the track
	set this_name to name of this_track
	set this_artist to artist of this_track
	set this_album to album of this_track
	set this_position to player position
	
	-- convert this_position to dd:hh:mm:ss
	set dys to this_position div days as string
	if dys = "0" then
		set dys to ""
	else
		set dys to dys & " days "
	end if
	set this_position to this_position mod days
	set hrs to this_position div hours as string
	if hrs = "0" then
		set hrs to ""
	else
		set hrs to hrs & " hrs "
	end if
	set this_position to this_position mod hours
	set mins to this_position div minutes as string
	if mins = "0" then
		set mins to ""
	else
		set mins to mins & " mins "
	end if
	set secs to ((this_position mod minutes) as string) & " secs"
	set formatted_position to (dys & hrs & mins & secs)
	
	-- make devonthink note
	tell application id "com.devon-technologies.thinkpro2" to create record with {name:this_name, type:txt, plain text:("Name: " & this_name & return & "Artist: " & this_artist & return & "Album: " & this_album & return & "Position: " & formatted_position & return & return & "Write your notes here..")}
	
end tell

Nice work! Many thanks.

This script works well for me (forget where I got it):

tell application "iTunes"
	if player state is not stopped then
		set ct to current track
		set station_name to ""
		set {nom, art} to {"", ""}
		
		tell ct
			try
				if artist is not "" and artist is not missing value then
					set art to (" by " & artist)
				end if
			end try
			try
				if name is not "" then
					set nom to name
				else
					set nom to "unknown"
				end if
			end try
			
		end tell
		
		try
			if (class of ct is URL track) and (get current stream title) is not missing value then
				set station_name to nom -- you can use this if you want
				set {art, nom} to my text_to_list((get current stream title), " - ")
				set art to " by " & art
			end if
		end try
		
		set the clipboard to (station_name & "\"" & nom & "\"" & art)
	end if
end tell
tell application "DEVONthink Pro"
	set inGroup to create location "/Songs"
	create record with {name:nom & art, label:4, type:txt, plain text:nom & art & return & station_name} in inGroup
end tell


on text_to_list(txt, delim)
	set saveD to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to {delim}
		set theList to every text item of txt
	on error errStr number errNum
		set AppleScript's text item delimiters to saveD
		error errStr number errNum
	end try
	set AppleScript's text item delimiters to saveD
	return (theList)
end text_to_list