Applescript to put the current track in iTunes into the clipboard

I use screen in order to connect to a host where I have a terminal with irssi running.
Since this is located on a remote machine it would make it difficult to make a script that is triggered from within irssi to show the information of the song currently played in iTunes. The solution was quite simple: make a script that picks out current artist, name of song and name of album and put the information into the clipboard for a simple paste into the irssi chat.

The script is below:

tellapplication “iTunes”
ifplayer stateis****notstoppedthen
setctracktocurrent track

tellctrack
try
ifartistis****not “” then
setarttoartist

else
setartto “”

end****if
end****try

try
ifnameis****not “” then
setnomtoname

else
setnomto “”
end****if
end****try

try
ifalbumis****not “” then
setalbmto (“on album: “” & album & “””)
else
setalbmto “”
end****if
end****try

end****tell

end****if

set the clipboard to {“np: “” & art & “” – “” & nom & “” ” & albm & “”} astext

end****tell

Save the script somewhere (I saved it in /Library/Scripts for easy access).

In order to have it easily accessible follow the guide by Stephen Foskett
here!
Now the script appears in your applications “Services” menu, see below:
wpid-wpid-Screenshot2010-09-10at21.57.32-2010-09-10-21-49-300x85-2010-09-10-21-49.png

That’s all!
Easy eh 😉

Mastodon