dougscripts.com

DIY

April 4 2018 - 6:06 am

Name New Playlist From Selection, Updated

I've mentioned my "Name New Playlist From Selection" script in the past. It emulates iTunes' "Playlist From Selection" command with the added feature of asking for the playlist name before actually creating the playlist. This just seems to make sense to me rather than naming it afterwards. I've given it the same keyboard shortcut as the iTunes command (Shift-Command-N) so that the script is launched instead of the command being carried out.

Here is an updated version of that script which adds an option to provide a playlist description. The default text presented will be "Created 4/4/2018", or whatever the current date is.
(more…)

March 20 2018 - 7:50 am

Errant Control Characters in Metadata

As you probably know: when you first mount a new CD and have a look at it in iTunes, the track information you see, for the most part, is not from the CD. (Well, there is such a thing as CD Text but it is not widely used.) Instead, this information is typically retrieved over the internet from Gracenote, a company that maintains an information database of virtually every CD.

Ostensibly, the record labels provide Gracenote with the correct metadata for their products. But users can contribute "corrected" track data to Gracenote from many music apps, including iTunes. Crowd-sourcing this information famously has its, uhm, pitfalls.

Recently, a Correspondent told me of an issue with finding return and linefeed characters in the Name tags of some of his tracks, metadata which were undoubtedly retrieved from Gracenote. These control characters aren't supposed to be used in iTunes tags. In fact, entering a return character in most iTunes text fields is usually a signal to end editing. At best, iTunes does not accommodate line ending characters very well. The ID3 Tag spec may not permit them either, but I am not certain. Of course, I suppose it is possible that some other music app does allow return or linefeed characters in its track entries database.

So, evidently, perhaps someone was able to upload Name metadata to Gracenote formatted with line breaks, something like so:

Cycle for Children v2 XI Jerring Song '
The Sun Shines Into The Church' 
 (allegro ironico) (Gyermekeknek Sz42)

(At first, I thought the problem was that a linefeed was somehow "attached" to the single quote character; but in the second instance the linefeed is followed by a space. So maybe this was just poor cursor placement or bad automation.)

Depending on the app and the UI element that is rendering this text, the linefeed characters may not actually "feed" a new line but instead will be replaced with a space character (on the screen, anyway). This leads me to think that perhaps the source machine was a WIndows box; there was a time when "Mac or PC" made a difference in this regard. I still see Windows XP-era text effluvia in some Comments tags, for example.

In any case, while it may seem that formatting Name text with control characters wouldn't be a problem, its the sort of thing that may "work fine...until it doesn't". My Correspondent found that several AppleScripts of mine that he was using weren't working to remove these errant control characters. (Who knows what kind of havoc may be unleashed when syncing these tracks to a device or iCloud?)

So, I created a simple script that removes any return or linefeed characters from the Name tags of a selection of tracks in iTunes.
(more…)

February 28 2018 - 8:55 am

Tip: Pesky iCloud Download Column

The iCloud Download column cannot be removed from a playlist in Songs View for very long (it can't be removed at all from a playlist in Playlist View). You can hide it using View Options, but this will only be temporary and it won't be long before it pops back up again. Its default initial placement seems to be adjacent to the Name column.

Personally, I like having this column available since I sometimes want to know if a track I want to work on has a local file or one that resides in the cloud. But I have heard from Correspondents who would prefer this column to stay hidden when they hide it.

Well, the trick I use is to keep it visible...but not visible. If you're like me, you probably have the most important tag columns on the left side of a playlist in the browser window (while in Songs view). But I also keep non-essential/less-frequently-used columns far-off to the right so they are not visible when the playlist is horizontally scrolled full left in the browser window. So, click-and-drag the iCloud Download column all the way over to the right side of a playlist.

If you do this in the Music library (with Songs selected) then every playlist you create subsequently will be configured the same way when in Songs view. Existing playlists will need to be manually adjusted.

February 14 2018 - 9:31 am

Go to Music Library Shortcut

I'm often hopping around in iTunes among the "Library", "For You", "Browse", "Radio" and "Store" tabs and likewise apt to be in a specific media library, like Podcasts or Movies. As such, it can be a minor pain to get back to my local Music library.

Okay, it's only a couple of clicks. But it does elicit from me a small "arghh" burp from time to time.

So here's a very simple script to which you can assign a keyboard shortcut that will display the Music library in the Library tab:

tell application "iTunes" to reveal (some playlist whose special kind is Music)

Save this in your home/Library/iTunes/Scripts/ folder and name it "Go to Music Library.scpt". The script will appear in the iTunes Script menu. Then, open System Preferences and go to the Keyboard panel. Select "Shortcuts" and then "App Shortcuts" from the list on the left. Click the "+" button on the right side. In the drop down panel, select "iTunes" in the Application popup. Enter the name of the script, "Go to Music Library", in the Menu Title text field. Enter your shortcut combination in the Keyboard Shortcut text field (I use Control-Command-H, where the "H" stands for "home"). Click the "Add" button and then close out of System Preferences. Thus, whenever you want to get back to your Music library, just hit the shortcut.

I've done something similar for my Internet Radio Station playlist.

January 13 2018 - 11:06 am

Segregate Shufflable Tracks

A Correspondent queries:

"Do you have a script that can create a playlist of songs if they have the "Skip when shuffling" attribute ticked in the info panel? The reason is because when I sync those songs to the iPhone that feature doesn't sync along with it so they play regardless. The feature works on the Mac, just not on the iPhone."

The shufflable property of a track does not have a corresponding Smart playlist criterion or Songs view column. So, looks like the only way to identify these tracks en masse is with AppleScript.

Interestingly, the shufflable property works somewhat backwards. If the "Skip when shuffling" checkbox is set (and a checkbox when checked has a "true" value) the corresponding shufflable property is set to false; that is, "not shufflable". This might be the opposite of what you'd expect. For instance, when "Remember playback position" is set to true with a checkmark, its correponding bookmarkable property is set set to true (yes, allow this track to be bookmarked). Just kind of interesting. A little. But its important to keep in mind when you want to detect the correct (and not opposite) value.

Anyway, here's a script that will copy any tracks in the Music library set to "skip when shuffling" to an existing playlist:

tell application "iTunes"

set targetPlaylist to playlist "Skip Shuffle Tracks"

set musicPlaylist to (some playlist whose special kind is Music)

set theTracks to every track of musicPlaylist whose shufflable is false

repeat with aTrack in theTracks

set db to database ID of aTrack

try

if not (exists (get some track of targetPlaylist whose database ID = db)) then error

on error

try

duplicate aTrack to targetPlaylist

end try

end try

end repeat

reveal targetPlaylist

end tell

Open this in Script Editor by clicking the little script icon. Save it named whatever you like as a Script Bundle in your ~/Library/iTunes/Scripts/ folder so that it will be listed in the iTunes Script menu. I have already created a playlist in iTunes named "Skip Shuffle Tracks" so make sure you do, too. if you want to use a playlist with a different name then you will have to hard-code that name in the script where I have used "Skip Shuffle Tracks".

Whenever you run the script it will get a list of track references from the Music playlist where each has its shufflable set to false. It will iterate over this list and for each track it will first see if the track already exists in the target playlist; and if it does not the track will be copied to the playlist.

The second try block around the duplicate command ensures that if any track cannot be copied, such as a "dead" track, the script will skip it without erroring.

November 27 2017 - 10:40 am

Internet Radio Streams Playlist

I recently swapped receivers (or, I should say, amplifiers) in my office. I was using a decent mid-priced Sony receiver to power two zones of speakers: a set of Bose 301s and a "near-field" set of cheap desktop speakers and sub-woofer. I replaced it with an unused Onkyo amp I had purchased a few years ago. As a result of the switch, I no longer have a radio tuner in the configuration.

But, as it turns out, I don't need one. I'm lucky enough to have all the local Boston-area stations I listen to available in the Internet Radio section of iTunes. I never paid much attention to them before since I had a receiver. This gives me some nice advantages:

  • Internet radio feeds seem to precede the part of the broadcast audio chain where the signal has the life processed out of it. I no longer have to tolerate crappy broadcast audio.
  • Almost all my music sources are available digitally in one application, iTunes. Pandora is the only audio service I use requiring another app, but I mostly listen to it on mobile.
  • I can AirPlay iTunes all over my house.

The only downside so far is that I can't listen to live local play-by-play sports broadcasts because, for various "contractual obligations", these broadcasts can't be internet-'casted.

One quibble I've always had with iTunes Internet Radio is that it's not exactly easy to manage the stream tracks. Finding them in the Radio list can be a chore and sometimes stations will disappear and the re-appear with a different URL. There's not much I can do about either of those issues.

But to make life a little easier, I have created a "__Radio" playlist to which I have dragged the stream URLs I regularly listen to. I've also create a little script to quickly pull up the __Radio playlist with a keyboard shortcut:

tell application "iTunes" to reveal playlist "__Radio"

I've assigned Option-Command-R as a keyboard shortcut to the script.

One other thing I've done is to store the URL address of each stream track in the __Radio playlist. I grab the address property of each URL track and then paste it into a text document for safe keeping:

Later, if necessary for any reason, I can open the address with something like this:

set theStream to "https://audio.wgbh.org/otherWaysToListen/wgbh.m3u"

tell application "iTunes" to open location theStream

This will create a new URL track in a playlist called "Internet Songs". I then drag the track to my __Radio playlist and usually delete the "Internet Songs" playlist, although keeping it around isn't a bad idea either.

September 25 2017 - 9:05 am

Camelot Codes to Keys

For a brief time, back when I was radio DJ, a station I worked at experimented with using "key segues", whereby a recorded sounder would transition from a song played in one key to a song in another. Thus: Song in C fades -> sounder transitions from C to A minor -> seg next Song in A minor.

It was horrendous.

Anyway. Since I was an Actual Musician (few and far between in radio), it was my job to assign the correct key for each song we played. Which essentially meant that I sat in a studio a couple of times a week with a CD player and a Casio keyboard and diddled around until I determined the key of each song we added that week.

Nowadays, a lot of DJs use the musical key of the tracks they play to create "harmonic mixes"; tracks are mixed or segued according to harmonic rules. Some DJs probably aren't musically inclined either, so there is software and databases and such that can supply the key for their tracks. Then all they have to do is check the Camelot chart to see what might sound good.

(This, of course, is not perfect, since pitches can vary. Which is what made my old station's experiments with key segues so cringey. We had CD players that could adjust for pitch, but nobody wanted to spend that much time on creating perfectly harmonic segues. But, whatever.)

I heard from a Correspondent who uses this system. He has the Camelot codes in his iTunes tracks' Comments tags. These are codes that represent 24 musical keys and look like this: 1A, 2A, 3A...10B, 11B, 12B:


Courtesy of harmonic-mixing.com

He wants to convert the Camelot codes to the actual key. So here is a script that will do that: (more…)

September 5 2017 - 1:06 pm

Find Tracks with Multiple Artworks

This will corral all the tracks in the Music library that have more than one assigned artwork to a new playlist (whose name you supply; any existing playlist(s) with that name will be deleted beforehand):

tell application "iTunes"

try

set newPlaylistName to text returned of (display dialog ¬

"Enter a name for the playlist:" default answer "Multi-artwork tracks")

on error

return

end try

try

delete (every playlist whose name is newPlaylistName)

end try

set newPlaylist to (make new playlist with properties {name:newPlaylistName})

set musicLibrary to (get some playlist whose special kind is Music)

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

try

set aTrack to track i of musicLibrary

if (count of artworks of aTrack) > 1 then

try

duplicate aTrack to newPlaylist

end try

end if

end try

end repeat

display dialog "Done" buttons {"OK"} default button 1

end tell

Open this in Script Editor by clicking the little script icon. Save it named whatever you like as a Script Bundle in your ~/Library/iTunes/Scripts/ folder so that it will be listed in the iTunes Script menu. Launch the script and enter a name for the playlist; the default is "Multi-artwork tracks"; press OK.

March 28 2017 - 2:54 pm

Close a Playlist Window and Select Its Playlist

If it really drives you crazy that after closing a playlist window iTunes is compelled to put focus on the entire Music library, use the following script to close the frontmost playlist window and thereafter select the playlist it had contained in the main window:

tell application "iTunes"

try

set frontPlaylistWindow to front playlist window

set thePlaylist to view of frontPlaylistWindow

close frontPlaylistWindow

reveal thePlaylist

end try

end tell

Click on the little AppleScript icon above to open the script in Script Editor at your house—don't copy the text in the browser.

Save the script as a Compiled ".scpt" with Script Editor named whatever you like in your [home]/Library/iTunes/Scripts/ folder so it can be launched from the iTunes Script menu. You may want to assign it a keyboard shortcut.

When run, it will get a reference to the front playlist window; if none is open, the script will fail silently. It will proceed to get a reference to the playlist contained by the playlist window, close the playlist window and finally select (reveal) the playlist.

March 22 2017 - 9:53 am

Playlist Windows

iTunes 12.6 has brought back Playlist windows and, judging from the reaction in my Twitter feed, they're receiving a hearty welcome back. Couple of things, though: 1) The names of the open Playlist windows are not listed in the iTunes "Window" menu and 2) window names are blank for any Apple Music playlists opened as Playlist windows; they actually default to the name "iTunes" but this isn't displayed either To be clear, the AppleScript name for the window of a subscription playlist is "iTunes" and not the name of the playlist. (Update: And now I'm not seeing this at all and all seems correct as far as names go; don't know what I was seeing previously!)

I'm not so much concerned about the latter thing. But if you have a batch of Playlist windows open it can be an ordeal to select one you'd like to work in. This script will list all open Playlist windows in a choose from list panel so one can be chosen and then made frontmost:

tell application "iTunes"

if (count of playlist windows) < 2 then return

set windowList to playlist windows

set nameList to name of view of playlist windows

try

set chosenName to (choose from list nameList)

if chosenName is false then error

on error

return

end try

set chosenName to (chosenName as text)

repeat with i from 1 to (count of nameList)

if chosenName is item i of nameList then select item i of windowList

end repeat

end tell

Click on the little AppleScript icon above to open the script in Script Editor at your house—don't copy the text in the browser.

Save the script as a compiled Script (".scpt") with Script Editor named whatever you like in your [home]/Library/iTunes/Scripts/ folder. When there are too many Playlist windows open and you can't find any real estate to click on, launch the script to select the one you want brought to the front.

(Update: Of course, after I post this I immediately discovered that you can Command-tilde (~) through open Playlist windows.)

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.