<
 
frontpage : scripts : here

Missing Menu Commands

This is a list (a very subjective list) of scripts that perform tasks you may wish were actual iTunes Menu commands. Just copy and paste 'em to your Script Editor and save to your iTunes Scripts folder...then add a Shortcut.

Optionally, you can click the mini-script icon link beneath each snippet to open the script in Script Editor on your computer. This is URL Protocol Messaging and works with most modern Mac browsers (IE for Mac is not considered one of these).

Following these scripts is a list of other Missing Menu Command candidates that are available for downloading elsewhere on the site.

This list is still growing. Send your suggestions.

View Main Library

This is helpful in iTunes 7 for displaying the entire "master" library and listing all tracks. (BROKEN as of iTunes 7.1. See the workaround on this page.)

tell application "iTunes"
	set view of front browser window to library playlist 1
end tell

View Party Shuffle

Same as above but selects the "Party Shuffle" Playlist.

tell application "iTunes"
	set view of front browser window to playlist "Party Shuffle"
end tell

View Current Playlist

Select playlist containing currently playing track. Same as Command-L without current track being selected.

tell application "iTunes"
	if player state is playing then
		set view of front window to playlist (name of current playlist)
	end if
end tell

Jump to Playlist

Enter a name or first few letters of a playlist and the script will select it in the main browser window.

tell application "iTunes"
	repeat
		set search_for_this to text returned of ¬
			(display dialog "Enter the name or first few letters of the playlist you want to view:" default answer "")
		if search_for_this is not "" then exit repeat
	end repeat
	try
		set view of front browser window to playlist ¬
			(name of (get (first playlist whose name starts with search_for_this)))
	on error
		display dialog "None of your playlists seem to begin with \"" & ¬
			search_for_this & "\"" buttons {"Cancel"} default button 1
	end try
end tell

Delete Selected Playlists
tell application "iTunes"
	set deleteThese to (choose from list (name of user playlists) as list with prompt "Select Playlists to delete..." with multiple selections allowed)
	if deleteThese is false then error number -128 -- cancel
	repeat with thisPlaylist in deleteThese
		try
			delete playlist thisPlaylist
		end try
	end repeat
	display dialog "Playlists have been deleted!" buttons {"Thanks"} default button 1 giving up after 10
end tell

Virgin Again

Set the played count of selected tracks to 0 and set their last played date to a time long ago.
from Dale Critchley

tell application "iTunes"
	if selection of front browser window is not {} then
		set sel to selection of front browser window
		repeat with this_track in sel
			try
				set played date of this_track to date "Wednesday, June 16, 1993 12:00:00 AM"
				set played count of this_track to 0
			end try
		end repeat
	end if
end tell

Add/Subtract Half Star

iTunes 6.0.2 recognizes half-star ratings. The four scripts below increase or decrease the selected tracks' (or current track's) ratings by half a star (see the script Add-Subtract A Half Star.)

-- add a half star
tell application "iTunes"
	if selection is not {} then
		set sel to selection
		with timeout of 30000 seconds
			repeat with this_track in sel
				my add_half(this_track)
			end repeat
		end timeout
	else
		display dialog "Select some tracks first..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
	end if
end tell

to add_half(this_track)
	tell application "iTunes"
		try
			set rat to (get this_track's rating)
			if rat is less than or equal to 90 then set this_track's rating to (rat + 10)
		end try
	end tell
end add_half

-- subtract a half star
tell application "iTunes"
	if selection is not {} then
		set sel to selection
		with timeout of 30000 seconds
			repeat with this_track in sel
				my sub_half(this_track)
			end repeat
		end timeout
	else
		display dialog "Select some tracks first..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
	end if
end tell

to sub_half(this_track)
	tell application "iTunes"
		try
			set rat to (get this_track's rating)
			if rat is greater than or equal to 10 then set this_track's rating to (rat - 10)
		end try
	end tell
end sub_half

-- add a half star to current track
tell application "iTunes"
	if player state is not stopped then my add_half(get current track)
end tell

to add_half(this_track)
	tell application "iTunes"
		try
			set rat to (get this_track's rating)
			if rat is less than or equal to 90 then set this_track's rating to (rat + 10)
		end try
	end tell
end add_half

-- subtract a half star to current track
tell application "iTunes"
	if player state is not stopped then my sub_half(get current track)
end tell

to sub_half(this_track)
	tell application "iTunes"
		try
			set rat to (get this_track's rating)
			if rat is greater than or equal to 10 then set this_track's rating to (rat - 10)
		end try
	end tell
end sub_half

Selected Tracks to Current Playlist
tell application "iTunes"
	if player state is not stopped then
		set curPlaylist to current playlist
		if curPlaylist is not view of front browser window and ¬
			class of curPlaylist is user playlist and ¬
			not smart of curPlaylist and selection is not {} then
			duplicate selection to curPlaylist
			display dialog "Tracks copied." buttons {"Thanks"} ¬
				default button 1 giving up after 10
		end if
	end if
end tell

Play Random Track of Next Playlist
tell application "iTunes"
	if player state is playing then
		set last_p to (index of last user playlist)
		set this_p to index of current playlist
		if this_p is not last_p then
			my play_this(this_p + 1)
		else
			my play_this(1)
		end if
	end if
end tell

to play_this(i)
	tell application "iTunes"
		set view of front browser window to playlist i
		-- un-comment to shuffle the playlist first
		(*
		repeat 5 times
			set shuffle of playlist i to false
			set shuffle of playlist i to true
		end repeat
		*)
		play some track of playlist i
	end tell
end play_this

Play Random Track of Random Playlist
tell application "iTunes"
	if player state is playing then
		set last_p to (index of last user playlist)
		my play_this(random number from 1 to last_p)
	end if
end tell

to play_this(i)
	tell application "iTunes"
		set view of front browser window to playlist i
		-- un-comment to shuffle the playlist first
		(*
		repeat 5 times
			set shuffle of playlist i to false
			set shuffle of playlist i to true
		end repeat
		*)
		play some track of playlist i
	end tell
end play_this

De-Shuffle All Playlists

Turns "Shuffle" off for every playlist.

tell application "iTunes"
	repeat with i from 1 to (index of last playlist)
		try
			set shuffle of playlist i to false
		end try
	end repeat
end tell

Choose Playlist

from Jason Kacmarski

tell application "iTunes"
	set matchFound to false
	set hasList to {}
	set myPlaylist to the text returned of ¬
		(display dialog "Enter a Playlist Name" default answer "" default button 2)
	set allPlaylists to name of playlists
	
	repeat with thisPlaylist in allPlaylists
		if thisPlaylist is myPlaylist then
			set matchFound to true
			exit repeat
		else
			if thisPlaylist contains myPlaylist then
				set end of hasList to thisPlaylist
			end if
		end if
	end repeat
	
	if not matchFound then
		if length of hasList is 0 then
			display dialog "No matching playlist was found."
		else if length of hasList is 1 then
			set thisPlaylist to hasList as string
		else
			set thisPlaylist to (choose from list hasList ¬
				with prompt "The following playlists contain " & ¬
				myPlaylist without empty selection allowed)
			if thisPlaylist is false then return
		end if
	end if
	try
		set view of browser window 1 to playlist thisPlaylist
		play track 1 of playlist thisPlaylist
	end try
end tell

Skip Ahead n Seconds

Change the "differential" property to the number of seconds you want the current track to skip ahead to. Useful for skipping over commercials and what not. Works great when assigned a shortcut.

property differential : 120 -- seconds

tell application "iTunes"
	if current track exists then
		if player position is greater than start of current track ¬
			and player position is less than ((finish of current track) - differential) then
			set player position to (player position + differential)
		end if
	end if
end tell

Update iPod Songs

(Not effective if iPod Options are set to "Manually manage songs and playlists".)
from Jason Kacmarski

tell application "iTunes"
	set mySource to some source whose name contains "iPod"
	update mySource
end tell

Open iTunes Scripts Folder

The two variations below will open the iTunes Scripts folder and make it frontmost.

tell application "Finder"
	open folder (((path to "dlib" from user domain) as string) & "iTunes:Scripts") as alias
	activate
end tell

tell application "Finder"
	open folder ((path to home folder as string) & "Library:iTunes:Scripts")
	activate
end tell

Go To Doug's With Safari

from Brian Purnell

tell application "Safari"
	activate
	if URL of document 1 does not contain "dougscripts" then
		make new document at beginning of documents
	end if
	set the URL of document 1 to "http://dougscripts.com/itunes/"
end tell

Toggle Check Marks of Selected Tracks
tell application "iTunes"
	set sel to selection
	if sel is not {} then
		repeat with aTrack in sel
			tell aTrack
				try
					set enabled to not (get enabled)
				end try
			end tell
		end repeat
	end if
end tell

Search Results To New Playlist

iTunes 4.5 or better

tell application "iTunes"
	set searchString to text returned of (display dialog "Enter text to search for:" default answer "" default button 2)
	set searchResult to search library playlist 1 for searchString
	if searchResult is not {} then
		set newPlaylist to (make playlist with properties {name:searchString})
		repeat with t in searchResult
			duplicate t to newPlaylist
		end repeat
		set view of front browser window to newPlaylist
	else
		display dialog "No result." buttons {"Cancel"} default button 1
	end if
end tell

Skip & Pretend We Played This

Increment the Play Count of the currently playing track and set its Last Played Date to "now", and, irregardless of acomplishing that, advance to the next track in the current playlist. (I have a Smart Playlist that live updates to tracks not played in the last 8 weeks. If a song from it is playing that I don't want to hear again for another 8 weeks, I run this script while it's playing, it leaves the Smart Playlist, and the next song plays.)

tell application "iTunes"
	if player state is not stopped then
		try
			tell current track
				set played count to (get played count) + 1
				set played date to (get current date)
			end tell
		end try
		next track
	end if
end tell

Pretend We Played This Today

Select one or more tracks; increases each track's played count and sets its last played date to "now". (I have a Smart Playlist that live updates to tracks not played in the last 8 weeks. If I see some songs I don't want in the playlist, I run this script on 'em.)

tell application "iTunes"
	if selection is not {} then
		set sel to selection
		repeat with cur in sel
			if class of cur is file track then
				tell cur
					set played count to (get played count) + 1
					set played date to (get current date)
				end tell
			end if
		end repeat
	end if
end tell

Refresh Live-Updating Smart Playlist

Remove all the tracks from the selected playlist. It must be a Smart Playlist. Use carefully: there is no way to check for "Live Updating".

tell application "iTunes"
	set lib to view of front browser window
	if class of lib is user playlist and smart of lib then
		display dialog "Remove all tracks from this playlist?" default button 2 ¬
			buttons {"Cancel", "Proceed..."}
		delete every file track of lib
	end if
end tell
end

Super Shuffle

Select a playlist in the Source column and run this script to super-shuffle the tracks. For more super-ness, change the 7 in "repeat 7 times" to as large a number as you can stand. (Strangely, "Party Shuffle" is impervious to shufflin'.)

tell application "iTunes"
	tell view of front browser window
		if name is not "Party Shuffle" then
			repeat 7 times
				set shuffle to false
				set shuffle to true
			end repeat
		end if
	end tell
end tell

Super Shuffle Plus

Like the script above, will "Super Shuffle" the selected Playlist, then select a random track to initiate playing the playlist.

tell application "iTunes"
	set myPlaylist to view of front window
	stop
	tell myPlaylist
		repeat 7 times
			set shuffle to false
			set shuffle to true
		end repeat
	end tell
	play some track of myPlaylist
end tell

Current Track to (Select Playlist)
tell application "iTunes"
	if player state is not stopped then
		set cur_track to current track
		
		with timeout of 300 seconds
			
			-- comment out one or the other by placing "--" in front of the line:
			
			-- use for pre-iTunes 4.9
			set the_playlist to ((choose from list (get name of every user playlist whose smart is false and ¬
				name is not "Party Shuffle" and name is not "Purchased Music") with prompt "Copy \"" & (name of cur_track) & ¬
				"\" to..." OK button name "This Playlist" without multiple selections allowed) as string)
			
			-- use for iTunes 4.9 and later
			set the_playlist to ((choose from list (get name of every user playlist whose smart is false and ¬
				special kind is none) with prompt "Copy \"" & (name of cur_track) & ¬
				"\" to..." OK button name "This Playlist" without multiple selections allowed) as string)
			
			if the_playlist is "false" then
				return
			else
				set the_playlist to playlist the_playlist
			end if
		end timeout
		
		try
			if not (exists (some track of the_playlist whose database ID is (get cur_track's database ID))) then ¬
				duplicate cur_track to the_playlist
		end try
		
	end if
end tell

Selected Tracks to (Select Playlist)
tell application "iTunes"
	if selection is not {} then
		set sel to selection
		
		-- comment out one or the other by placing "--" in front of the line:
		
		-- use for pre-iTunes 4.9
		set the_playlist to ((choose from list (get name of every user playlist whose smart is false and ¬
			name is not "Party Shuffle" and name is not "Purchased Music") with prompt ¬
			"Copy selected tracks to..." OK button name "This Playlist" without multiple selections allowed) as string)
		
		-- use for iTunes 4.9 and later
		set the_playlist to ((choose from list (get name of every user playlist whose smart is false and ¬
			special kind is none) with prompt ¬
			"Copy selected tracks to..." OK button name "This Playlist" without multiple selections allowed) as string)
		
		if the_playlist is "false" then
			return
		else
			set the_playlist to playlist the_playlist
		end if
		
		with timeout of 30000 seconds
			repeat with this_track in sel
				try
					if not (exists (some track of the_playlist whose database ID is (get this_track's database ID))) then ¬
						duplicate this_track to the_playlist
				end try
			end repeat
		end timeout
		
		try
			if button returned of (display dialog "Done" buttons {"Select " & (name of the_playlist), "Thanks"} default button 2 ¬
				giving up after 15) starts with "sel" then set view of front browser window to the_playlist
		end try
	else
		display dialog "No tracks selected..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
	end if
end tell

 
Scripts Posted For Download

Links will take you to the script's description and download page.

This column is printer-friendly.
home | scripts | tips & info | forum at iLounge | rssfeed rss
Site contents © 2001 - 2008 Doug Adams and weblished by Doug Adams, dougscripts AT mac DOT com. All rights reserved. Legal.
AppleScript, iTunes, and iPod are registered trademarks of Apple Inc.
This page was served using PHP. Be that as it may—whatever that means—this page was last modified by human hands on July 29, 2007.

"Anything can be music." - F. Zappa