Nowadays you can find from iTunes university and other sources a vast number of recorded lectures from the best universities of the world. Sometimes it would be helpful to have the ability to refer to specific points of them as you can do when you read a PDF file and you use DEVONthink. From now on there is an AppleScript for that!
I wrote two versions of this AppleScipt with a slightly different functionality. The first creates a link to a custom time point, which you set manually after executing it. One or more files should be selected in your iTunes library before executing it.
The AppleScript code for creating MediaWiki links is the following:
--http://www.organognosi.com
display dialog "Give the time point in seconds (the same for all the selected songs): " default answer ""
set songPoint to text returned of the result
set the clipboard to ""
tell application "iTunes"
set selectedSongs to selection
if selectedSongs is {} then error "Please select some contents."
repeat with thisSong in selectedSongs
set songPersistentID to persistent ID of thisSong
set songLocation to location of thisSong
set songName to name of thisSong
set applescriptURL to "[applescript://com.apple.scripteditor?action=new&script=tell%20application%20%22iTunes%22%0D%09set%20songID%20to%20%22" & songPersistentID & "%22%0D%09set%20myPlaylist%20to%20get%20file%20tracks%20of%20playlist%201%20whose%20persistent%20ID%20is%20songID%0D%09set%20songlogcation%20to%20location%20of%20item%201%20of%20myPlaylist%0D%09play%20songlogcation%0D%09set%20player%20position%20to%20" & songPoint & "%0Dend%20tell" & " (" & songName & " - " & songPoint & " sec)]"
set the clipboard to (the clipboard) & applescriptURL & "<br/>" & return
end repeat
end tell
The AppleScript code for creating RTF links is the following:
--http://www.organognosi.com
display dialog "Give the time point in seconds (the same for all the selected songs): " default answer ""
set songPoint to text returned of the result
set the clipboard to ""
tell application "iTunes"
set selectedSongs to selection
if selectedSongs is {} then error "Please select some contents."
repeat with thisSong in selectedSongs
set songPersistentID to persistent ID of thisSong
set songName to name of thisSong
set applescriptURL to "<a href=\"applescript://com.apple.scripteditor?action=new&script=tell%20application%20%22iTunes%22%0D%09set%20songID%20to%20%22" & songPersistentID & "%22%0D%09set%20myPlaylist%20to%20get%20file%20tracks%20of%20playlist%201%20whose%20persistent%20ID%20is%20songID%0D%09set%20songlogcation%20to%20location%20of%20item%201%20of%20myPlaylist%0D%09play%20songlogcation%0D%09set%20player%20position%20to%20" & songPoint & "%0Dend%20tell\">" & " (" & songName & " - " & songPoint & " sec)</a>"
set the clipboard to (the clipboard) & applescriptURL & "<br/>"
end repeat
tell application "Finder"
do shell script "pbpaste | textutil -stdin -format html -convert rtf -stdout | pbcopy -Prefer rtf"
end tell
end tell
The second version creates a link to the current track that plays in iTunes to the current time point.
The AppleScript code for creating MediaWiki links is the following:
--http://www.organognosi.com
tell application "iTunes"
set totalSeconds to player position as number
set totalMin to totalSeconds div 60 as number
set lastSeconds to totalSeconds mod 60 as number
set timePointer to totalMin & ":" & lastSeconds as text
set the clipboard to ""
set selectedSongs to current track as list
repeat with thisSong in selectedSongs
set songPersistentID to persistent ID of thisSong
set songLocation to location of thisSong
set songName to name of thisSong
set applescriptURL to "[applescript://com.apple.scripteditor?action=new&script=tell%20application%20%22iTunes%22%0D%09set%20songID%20to%20%22" & songPersistentID & "%22%0D%09set%20myPlaylist%20to%20get%20file%20tracks%20of%20playlist%201%20whose%20persistent%20ID%20is%20songID%0D%09set%20songlogcation%20to%20location%20of%20item%201%20of%20myPlaylist%0D%09play%20songlogcation%0D%09set%20player%20position%20to%20" & totalSeconds & "%0Dend%20tell" & " (" & songName & " " & timePointer & ")]"
set the clipboard to (the clipboard) & applescriptURL & "<br/>" & return
end repeat
end tell
The AppleScript code for creating RTF links is the following:
--http://www.organognosi.com
tell application "iTunes"
set totalSeconds to player position as number
set totalMin to totalSeconds div 60 as number
set lastSeconds to totalSeconds mod 60 as number
set timePointer to totalMin & ":" & lastSeconds as text
set the clipboard to ""
set selectedSongs to current track as list
repeat with thisSong in selectedSongs
set songPersistentID to persistent ID of thisSong
set songLocation to location of thisSong
set songName to name of thisSong
set applescriptURL to "<a href=\"applescript://com.apple.scripteditor?action=new&script=tell%20application%20%22iTunes%22%0D%09set%20songID%20to%20%22" & songPersistentID & "%22%0D%09set%20myPlaylist%20to%20get%20file%20tracks%20of%20playlist%201%20whose%20persistent%20ID%20is%20songID%0D%09set%20songlogcation%20to%20location%20of%20item%201%20of%20myPlaylist%0D%09play%20songlogcation%0D%09set%20player%20position%20to%20" & totalSeconds & "%0Dend%20tell\">" & " (" & songName & " " & timePointer & ")</a>"
set the clipboard to (the clipboard) & applescriptURL & return
end repeat
delay 1
tell application "Finder"
do shell script "pbpaste | textutil -stdin -format html -convert rtf -stdout | pbcopy -Prefer rtf"
end tell
end tell
Again the code for the links is sent to the clipboard and you may paste it to a MediaWiki page or a RTF document. Afterwards, every time you click a link an AppleScript editor window opens with the required AppleScript code inside it. Finally, you may press cmd + R (executes the script), cmd + W (closes the window) and cmd + D (without saving) or have the same effect by executing the AppleScript of this post.