dougscripts.com

DIY

December 5 2025 - 12:11 pm

Count Selected Tracks in Songs View?

Did I tell you that, evidently, the Music app doesn't show the number of selected tracks in the playlist's Status Bar when the playlist is in Songs View? Yup.

Wait, it doesn't show the Status Bar at all when the playlist is in Songs View. Luckily, no chains can keep me from writing this simple AppleScript:

tell application "Music"

try

set sel to selection

set numberOfSelected to (count of sel)

set s to " tracks"

if numberOfSelected is 1 then set s to " track"

display dialog ((numberOfSelected & s & " selected") as text)

end try

end tell

Comes out like this:

December 3 2025 - 12:33 am

Swap Light-Dark Modes

Just did some fiddlin' with the site to make it a little responsive to dark mode settings. So, to celebrate, here's a script to swap modes rather than jogging into System Settings whenever. I have it in the system-wide Scripts menu.

tell application "System Events"

tell appearance preferences

set dark mode to not dark mode

end tell

end tell

December 2 2025 - 3:14 pm

Folder Action to Add Files to Year/Month Folders

So now that I'm a Playlist XML exportin' maniac, I created a Folder Action to automatically file the exports to my "Playlist Exports" folder into Year/Month folders, according the date of save. Here it is. When a file is added to the folder the script is attached to, it moves it to a newly-created or existing Year/Month hierarchy:

on adding folder items to thisFolder after receiving theseItems

repeat with anItem in theseItems

tell me to processThis(anItem, thisFolder)

end repeat

end adding folder items to

to processThis(anItem, thisFolder)

set yearMonthPath to (do shell script "date '+%Y:%m_%b'") as text

-- Y=year, m=month number (for sorting), b=month abreviation. eg, 2025:06_Jun

try

set folderPath to (thisFolder & yearMonthPath) as text

tell application "Finder"

try

exists folder (folderPath as POSIX file as alias)

on error

do shell script "mkdir -p " & quoted form of POSIX path of (folderPath as text)

end try

move anItem to folder folderPath with replacing

end tell

end try

end processThis

November 25 2025 - 6:10 pm

Select None Lives

Did I say there was no "Select None" in Music app's Edit menu? Something had to be done.

tell application "Music"

tell (get view of front browser window)

try

reveal track 1 of it

reveal track 1 of it

end try

end tell

end tell

Run this when tracks are selected in a playlist and muscle memory has you going for Shift-Command-A. It first selects (reveal) the first track of the playlist, which clears any other selection. Then, (because of a bug?) the reveal command run a second time de-selects the first track, leaving no tracks selected.

November 25 2025 - 5:41 pm

Bug or Feature: No Shortcut to Delete a Playlist

Now one of the Things a Music app playlist doesn't do lately is obey a Delete keypress. Used to be a Delete or Command-Delete or something like that would delete the selected playlist. Magical. Nowadays, we have to right-click on it for the contextual menu and choose "Delete From Library"—which is wicked loaded title for a playlist contextual menu item lemma tell you just sayin'. So what a guy like me does is make a piddly little AppleScript:

tell application "Music"

tell (get view of front browser window)

if special kind of it is none then

try

delete it

end try

end if

end tell

end tell

Click the script icon above to open this script in your Script Editor, save it with the File Format of "Script" named "Delete Selected Playlist" in your ~/Library/Music/Scripts/ folder.

And then you just know I'm going to tell you to assign it a Shift-Command-D shortcut.

There's also no "Select None" in any Edit menus anywhere. But I digress.

November 22 2025 - 3:30 pm

Playlist XML Onloader

There came a time at my house when I had to get rid of a bunch of playlists. Like about 100. That I was very attached to. So I didn't really want to trash them. Instead, I exported each one as an XML file.

But wait! After exporting just three of them (click "File", click "Library", click "Export Playlist...", click "Save"), the first thing I did was assign a Command-E keyboard shortcut to the "Export Playlist..." menu item. Are you kidding? Of course I did.

Then it occurred to me that if I could only export one playlist at a time, what are the chances that I can only import them one at a time. Unfortunately, the chances are excellent for that.

So I wrote a really simple script that can choose a batch of exported playlist XML files—providing they are all in the same folder, like ~/Music/Export Playlist XMLs/ or something—and load them into the Music app.

try

set thePaths to (choose file with prompt "Choose one or more Playlist XML files:" of type {"xml"} with multiple selections allowed)

on error

return

end try

repeat with f in thePaths

tell application "Music"

try

add POSIX path of (f as text)

on error m

display dialog m with title "Music sez:" with icon 2

end try

end tell

end repeat

Click on the little script icon there to open this in your Script Editor and then save it as a "Script Bundle" named whatever you like, perhaps "Playlist XML Onloader". Save it in ~/Library/Music/Scripts/ so that it will appear in the Music app's "Script" menu.

April 19 2021 - 8:55 pm

Can't Believe I'm Posting About GUI Scripting

It is a fact universally acknowledged—in my house—that GUI Scripting stinks. But the flip side of that is that sometimes it can be the only way to automate something with AppleScript. Especially so if the developers of the app you are 'scripting have long been ignoring your suggestions. Again, my house.

GUI Scripting is a way to write AppleScript that works by simulating mouse clicks, selections, key presses and other "touches" of the GUI elements of an app in order to get the app to do what those clicks and presses do. For instance, you can simulate a mouseclick on a menu item in a menu and whatever happens when you usually click that menu item will happen. GUI Scripting is clunky to work with for a number of reasons, but the two most discouraging are that it's tough to know what and how and where to click and press for the Thing you want to do; and that if the developer changes an app's layout in the future the scripts could break because something isn't where it was before.

Despite all that, I've been playing with GUI Scripting lately. It's what I use to change playlist views in Playlist Manager and how Needle Drop clicks the "Clear" button in the Playing Next panel. If you've used those scripts, you've had to give permission in "Accessibility" to allow those scripts to use the "System Events" app. System Events is what enables AppleScript to target GUI elements.

Here's a little scripting project that uses some GUI Scripting to do three things that I like to do somewhat regularly in the Music app: open the selected playlist in its own window; change the playlist View to "as Songs"; reposition the playlist window to a standard place, rather than BANG right over the main browser window. (Note that I could only get it to work on the latest version of Big Sur with the latest version of Music, which bears out my thoughts above about clunkiness.)

(more…)

February 23 2021 - 4:33 pm

View as Songs with Column Browser

One of the things that disappoints me about the Music app (and iTunes before) is that there is no way to set a default playlist View. Whenever a new playlist is created it will default to View as Playlist. I suppose this is fine and I don't dislike View as Playlist; it has its useful moments when a minimal look is desirable. But I prefer View as Songs because I do most of my tag editing and track sorting in that View under which much more information can be made visible.

* * *

For several years I've been pointing out the Keyboard Shortcut trick of assigning Shift-Command-S to View > as Songs and Shift-Command-P to View > as Playlist in order to quickly toggle the playlist View on the fly.

* * *

So I find myself typing Shift-Command-S followed by Command-B to turn on the Column Browser. A lot. Wonder if there's anything I can do about that...

(more…)

August 19 2020 - 3:08 pm

Have a Quick Look

I was going to write this up for downloading but it's almost too simple.

Select a track in the Music app and run this script to open a Quick Look panel displaying the track's file, ready to play.

tell application "Music"

try

set sel to selection

if sel is {} then return

set theTrack to item 1 of sel

tell me to doQuickLook(POSIX path of ((get theTrack's location) as text))

on error

return

end try

end tell

on doQuickLook(loc)

try

do shell script "qlmanage -p " & quoted form of loc & " >& /dev/null &"

end try

end doQuickLook

February 4 2020 - 8:54 am

Track Description Tag

Apple's Music app still provides a Description tag for music tracks but the only way to see or change this tag is through the browser window while in Songs view:

While this is a, ahem, serviceable means to enter data, if you visit my house you'll have to use this script attached to a keyboard shortcut:

Here's the script to view and edit the description tag of a single selected track:

tell application "Music"

set singleSelection to item 1 of selection

set defaultDescription to (get description of singleSelection)

set ddResult to (display dialog "Description for \"" & (get name of singleSelection) & "\":" default answer defaultDescription)

-- if Cancel button pressed, script ends here

try

set description of singleSelection to text returned of ddResult

end try

end tell

Copy the script into Script Editor or click the little Script icon to begin the Trial by Permissions Dialogs to *automatically* open the script in Script Editor. Save it named whatever you like as a "Script" to your ~Library/Music/Scripts/ folder. Then assign it a keyboard shortcut.

Site contents © 2001 - 2025 (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.