PlaySingleTrack

From Wurst-Wasser.net
Revision as of 20:38, 18 October 2010 by Heiko (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Ever wondered how you can play a single track? Think of it: You navigate to a track in your music library, and you want to play it. Just it. Yes: iTunes offers no method of doing this (except creating a new playlist, adding the track, playing the track und deleting the playlist afterwards. Yes, this sucks).

  • The bad news: I have no better solution.
  • Now the good news: You don't have to do it yourself! Here's the script that does it all for you: (place into ~/Library/iTunes/Scripts/)
global tempplaylistname
on run
set tempplaylistname to "temp"
(* Create new playlist, if not existing *)
tell me to set pl to newtempplaylist()
(* selected track -> pl *)
tell application "iTunes"
(* remember old playlist *)
set oldpl to view of (browser window 1)
try
get class of selection
  1. log selection
  2. if ((count of selection) is greater than 0) then
set t to first item in selection
(* track into playlist *)
duplicate t to pl
(* playlist repeat off *)
set song repeat of pl to off
(* playlist to front *)
try
  1. set view of front window to playlist pl
  2. set view of browser window to pl
  3. set view of (browser window 1) to user playlist pl (*Fuck! (iTunes got an error: A descriptor type mismatch occurred.)*)
set view of (browser window 1) to pl (* Works with iTunes 9 *)
on error (e)
log "Fuck! (" & e & ")"
end try
(* play track *)
play first item of tracks of pl
(* Wait until track played or stopped *)
set dur to duration of t
repeat dur times
if player state is not playing then exit repeat
delay 1.0
end repeat
(* restore old playlist *)
set view of (browser window 1) to oldpl
on error (e)
display dialog "Select something, you weenie!" buttons "Yes, your highness!"
end try
(* delete temp playlist *)
delete pl
end tell
end run
(* Create a temp playlist we will delete afterwards *)
on newtempplaylist()
tell application "iTunes"
set pl to make new user playlist with properties {name:tempplaylistname & " as of " & (current date) as string}
end tell
return pl
end newtempplaylist

Soon also be available als part of Heikos Little Helpers