dougscripts.com

Missing Menu Commands

February 17 2016 - 7:24 am

Name New Playlist From Selection

(This a repost from October 25, 2011. The previous post reminded me of it.)

I use the iTunes File > New > Playlist from Selection command a lot to create temporary playlists. Actually, I use the Shift-Command-N shortcut more often than clicking the command in the File menu. But I'm irritated at all the dancing I have to do to name the new "untitled playlist". It takes my attention away from what I was intending to do with the tracks. So, I rigged the script below to the keyboard shortcut Shift-Command-N—and, luckily, it works. Sometimes assigning a shortcut that iTunes is already using doesn't override the original command. The script does exactly what "Playlist from Selection" does except now I can enter the name for the playlist before it's created.

Here's the script:

tell application id "com.apple.iTunes"

try

set sel to selection

set theSource to container of view of front browser window

if sel is {} then error

set opt to (display dialog ¬

"Make new playlist from selected tracks named:" default answer ¬

"" with title "Name New Playlist From Selection" with icon 1)

set newName to (text returned of opt)

if newName is "" then error

on error

return

end try

set newPlaylist to (make new playlist at theSource with properties {name:newName})

repeat with t in sel

try

duplicate t to newPlaylist

end try

end repeat

reveal newPlaylist

end tell

I named it "Name New Playlist from Selection", saved it to ~/Library/iTunes/Scripts/ and gave it the shortcut using these instructions.

March 6 2014 - 1:33 pm

iTunes Store Power Search at Your Fingertips

Kirk McElhearn posted today about accessing the (kinda hidden) iTunes Store "Power Search" panel:

The trick to making this panel visible is to use this link, which I suppose you could bookmark in your web browser and Command-Tab to that whenever you wanted to power search. But in the last century human beings invented AppleScript to free themselves from time-consuming drudgeries like that.

Just enter this in AppleScript Editor (or click the little script icon to open it automatically):

tell application "iTunes"

open location "itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearch"

end tell

Name it whatever you like and Save it with the Format of "Script" in your ~Library/iTunes/Scripts/ folder. Then assign it a shortcut in iTunes.

This post was updated on March 9, 2014.

Also see this post: More iTunes Store Power Search at Your Fingertips.

February 2 2014 - 8:17 am

Disc 1 of 1

A Corespondent laments:

My personal preference when dealing with the disc count field (1 of 2, etc) is to leave it blank for single CD albums instead of tagging them as "1 of 1." There is something about 1 of 1 that just bugs me so I try to clear those out. Can you think of anything you have that can search in those fields? Sorting the library by disc number [is an unsatisfactory solution] because every disc 1—regardless if there is a second disc—gets sorted.

Yeah. It would be easy to do a Multi-Item edit on these guys if you could only corral 'em all together somehow. But: sorting by Disc # sorts by Disc Number alone and ignores the Disc Count so the "1 of 1" tracks are not necessarily sorted together; rather, they're sorted by Album (all the Disc 1 albums A-Z, followed by all the Disc 2 albums A-Z, and so on). Smart Playlists are of little use to gather up these tracks since Disc Count is not a smart criterion.

So here's a script that will look at each track in a selection or all the tracks in the selected playlist; if the track's Disc Count is 1 the script will set it to 0, effectively blanking it:

tell application id "com.apple.iTunes"

set thePlaylist to (get view of front window)

set sel to selection

if sel is {} then

# all tracks in playlist

repeat with i from 1 to (get index of last track of thePlaylist)

my processTheTrack(track i of thePlaylist)

end repeat

else

# selected tracks

repeat with i from 1 to (length of sel)

my processTheTrack(item i of sel)

end repeat

end if

end tell

to processTheTrack(t)

tell application id "com.apple.iTunes"

try

if disc count of t is 1 then set disc count of t to 0

end try

end tell

end processTheTrack

You can save that in AppleScript Editor named whatever you like and using "Script" as the file format to your ~/Library/iTunes/Scripts/ folder whereupon it will appear in the iTunes Scripts menu.

The script iterates through each track individually, so if you run it against your entire Music library playlist you'll have time to file nails, tidy bookshelves, re-string guitar, or perform some other menial task.

UPDATE: To eliminate the disc number as well (although I prefer to keep it) change the handler to this:

to processTheTrack(t)

tell application id "com.apple.iTunes"

try

if disc count of t is 1 then

set disc number of t to 0

set disc count of t to 0

end if

end try

end tell

end processTheTrack

October 25 2011 - 8:14 pm

Name New Playlist From Selection

I use the "New Playlist from Selection" command a lot to create temporary playlists. Actually, I use the Shift-Command-N shortcut more often than clicking the command in the File menu. But I'm irritated at all the dancing I have to do to name the new "untitled playlist". It takes my attention away from what I was intending to do with the tracks. So, I rigged the script below to the keyboard shortcut Shift-Command-N—it works, luckily; sometimes assigning a shortcut that iTunes is already using doesn't override the original command. The script does exactly what "New Playlist from Selection" does except now I can enter the name for the playlist before it's created.

Here's the script:
(more…)

September 28 2011 - 8:59 am

Column Browser Go Home

I've found that iTunes' Column Browser feature is one of the best ways to navigate the Music library. But I'm often annoyed that I can't easily restore the browser window to a full view of tracks after digging down to a particular set of tracks. To do so requires a lot of scrolling up and clicking. Correspondent Josh Rafofsky emailed me complaining of the same frustration and his solution was pretty good: Command-B to Hide the Column Browser, fn-Left Arrow to got to the top of the browser, and the Command-B again to Show the Column Browser. But even this gets tiresome and he asked if there might be a one-step scripting solution.

You know there is.

I put together this script which uses a combination of standard AppleScripting and GUI Scripting to emulate Josh's shortcuts solution:

tell application "iTunes" to activate
tell application "System Events"
	key code 11 using command down
	tell application "iTunes" to reveal track 1 of (get view of front window)
	key code 0 using {command down, shift down}
	key code 11 using command down
end tell


Save this as whatever you like—I call it "Column Browser Go Home"—save it to the ~/Library/iTunes/Scripts folder, and assign it a shortcut (make sure you have enabled GUI Scripting, too, as outlined in this article on using key codes). When launched after you've Column Browsed to a discrete set of tracks it will restore the entire list of tracks and jump to the top of the selected playlist. In my case this is usually the Music library playlist, but it will work with any playlist that's being viewed with the Column Browser.

[UPDATE] And after all that, @tonyhazeldine tweets: "The same can be done by clicking on the column titles at the top of the column browser." Yes, but each column has to be clicked.

September 10 2011 - 9:49 am

Key Code Searching

Here's a snippet I've been using for awhile which I just got around to posting on the key codes page. I keep my iTunes Column Browser set with Artists and Albums listed On Left. Whenever I'm looking for a particular album I run this script to select the Music library and put focus on the Search box:

tell application "iTunes"
	activate
	-- select the Music library
	reveal (some playlist whose special kind is Music)
end tell
tell application "System Events"
	-- bring focus to Search box - Command-Option-F
	key code 3 using {command down, option down}
end tell


I've given it a keyboard shortcut of Command-Option-S.

More information on AppleScripting iTunes with key codes and keystrokes is here.

March 13 2011 - 4:10 pm

Missing Menu Script Updated

Search Results to New Playlist, a script in the Missing Menu Commands section, has been updated to fix a bug when trying to copy a "dead track" if one happened to turn up in the search results. Regrettably, "dead tracks", those for which iTunes can find no corresponding file, cannot be copied between playlists and this would cause the script to error out. Thanks to Correspondent Nicole St. Laurent for the heads-up.

February 26 2011 - 11:49 am

Skip and Pretend We Played This Redux

A popular item on the Missing Menu Commands page is Skip and Pretend We Played This. If a song is playing that you don't really want to hear, you'd launch this script to increase its play count by 1 (since it would not be increased until the track actually finished playing), set the last played date to the current date and time (ditto), and play the next track. I use it in a live-updating Smart Playlist that, among other criteria, uses the last played date to only list songs not played in the past few weeks. This keeps any track I don't want to hear from re-appearing for another few weeks. Ideally launched via shortcut, and so on.

But ANYway.

Correspondent Dirk Scharff noted that "if used in the first 2-20 seconds of the song the skip counter is increased too and that's somewhat undesirable as this wouldn't happen if I played that song." I don't pay much attention to skips at my house, but he has a point. So Dirk submitted a mod to the script which I have incorporated below:

(more…)

August 11 2009 - 10:44 am

Re-Posting Stream Startup Script

A couple few days ago I posted a script here that would ping the Radio Paradise stream until its server accepted the connection, suppressing the error dialog that would appear when a connection was denied. Well, that was the wrong version of the script. Here is the correct version, and the one I fire up every morning. You must select a radio stream track first, then run the script:

tell application "iTunes"
	if selection is {} then return
	set strm to (item 1 of selection)
	if (get class of strm) is not URL track then return
	repeat
		try
			play strm
			exit repeat
		on error m number n
			delay 15
		end try
	end repeat
end tell


The earlier script used the open location command, errors from which could not be defeated with the try block.

April 9 2009 - 12:04 pm

Missing Menu and Spare Parts Sections

Some visitors may have noticed a few changes to the site's formatting. The main challenge with a site like this is trying to make it easy to find something, but too many links were making every page more cluttered than it needed to be. So I got rid a lot of the links that cluttered the left column; in fact, I got rid of the left column altogether. Most navigation can be done via the menu-like links in the header of each page.

I have tidied up the Missing Menu Commands page and added a Spare Parts page that lists a few helpful iTunes AppleScript routines and handlers for script-makers. I'll continue to add to this page.

Finally, I dislike the way Amazon MP3s sometimes download with " (Album Version)" at the end of their titles. Here's a simple script, Remove (Album Version), that will delete that text from the selected tracks.

Site contents © 2001 - 2024 (that's right: 2001) Doug Adams and weblished by Doug Adams. Contact support AT dougscripts DOT com. About.
All rights reserved. Privacy.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc. This site has no direct affiliation with Apple, Inc.
The one who says "it cannot be done" should not be interrupting the one who is doing it.