dougscripts.com

AppleScript

July 9 2020 - 1:09 pm

Big Sur Public Beta Program

It is now time for my annual message about using apps and AppleScripts from this site with the newest macOS beta.

I have tested a few AppleScripts in the Developer Betas (there have been only two released so far) and they all appear to work as expected. However, until an app has been specifically updated to work with Big Sur, I suggest users be cautious about depending on AppleScripts running on the beta in mission-critical situations. I think this will be probably be more important once computers with ARM-powered silicon start shipping.

If you are on the betas and come across any anomalies, please let me know.

October 14 2019 - 10:43 am

Catalina Stuff

I've said previously that the AppleScript scripting definitions for the Music and TV apps are pretty much lifted from iTunes. However, there are differences.

For example, a script that targets composer of a TV track will fail. Because TV doesn't use the Composer tag. Or the Album Artist tag. Or the artist property. Instead of artist, TV has a director property. And a Music track doesn't understand show, season number or episode ID; a TV track won't grok movement or work properties.

Stuff like that makes it difficult to write one script that can work in both Music and TV without doubling-up some of the code. Or adding some extra conditional tests. I'm not complaining; it is what it is, to be simply trite about it.

* * * * * *

When analyzing the pasteboard in a drag operation from the Music app, the dragging pasteboard types include “com.apple.tv.metadata”, but one would expect there to be “com.apple.music.metadata” type in place of—if not in addition to—the “tv.metadata” type. ¯\_(ツ)_/¯

* * * * * *

There is definitely an Artwork Issue. Files that I have downloaded from the cloud do not contain image metadata, but the artwork is certainly downloaded into the Music database because I can see it throughout my library. I just don't see the artwork being transferred to the files at all. The files do not have "Get Info" artwork and the artwork does not appear in a Quick Look panel. However, artwork appears as expected for files that have always been local.

* * * * * *

Files downloaded from the cloud also do not contain purchaser metadata. Not sure what that's about.

* * * * * *

The previous two metadata issues may be related.

* * * * * *

I still don't know what's causing the Invalid parameter error people are seeing with launching scripts. As far as I can tell, the issue "goes away" after a short time.

Frankly, there's so much stuff going on when you first launch anything in Catalina (with permissions and warnings and threatening security dialogs and other whatnots) that it just may be a minor system glitch.

July 1 2019 - 9:01 pm

Doug's Check For All Updates v1.0

In case it isn't crystal clear: scripts written for iTunes will not work on macOS 10.15 and later. Since the iTunes application isn't available on the new OS, scripts that target it will fail. So, almost every script on the site will need to be re-written to work with the macOS Music and/or Apple TV apps that replace iTunes in macOS 10.15.

Oh, I'm keeping busy, all right. I would like to be posting updates for use with the Catalina betas. But there are currently some issues in the betas that have precluded me posting any Catalina-compatible scripts yet. I have no doubt that Apple will fix these minor glitches well before Catalina's offical release; I just don't know how soon. And even then, there will be a gradual rolling-out of script updates through the summer and fall.

To help users keep track of what scripts for which operating system have been updated and when, I've posted Doug's Check For All Updates. It's an applet that will survey your computer for all the scripts you have installed from dougscripts.com and generate a report listing which have been updated. This is unlike the "Doug's Check For Update" script, which can only check one script at a time.

Doug's Check For All Updates will work right now on any version of macOS 10.10 and later, including the macOS 10.15 betas.

May I suggest that it may be helpful to get some work done on your iTunes library with the latest tools now, before you update to Catalina and the new media apps. Your favorite script(s) may not be Catalina-ready by then.


A security aside: This is the first download I am posting that has been notarized by Apple, a requirement for third-party software if it is to be distributed outside the Mac App Store. As such, it is also the first download to be packaged as a .dmg (disk image file) without the .zip wrapper. The code-signing and notarization process in my workflow make it easier to process a disk image without the additional ZIP compression. All future new and updated scripts will be likewise packaged as DMGs.

April 21 2019 - 2:59 pm

Shortcuts and AppleScript on the Mac

Dr. Drang has posted some thoughts and questions about the future of automation on the Mac.

December 10 2018 - 2:57 pm

Idle Wish List

Dear iTunes Santa,

It would be great if clearing Up Next could be done via AppleScript.

Also, I have wanted to

tell application "iTunes"

make new playlist window with properties {view:playlist "Mom's Favorites"}

end tell

for a long time.

I have been a good boy.

March 13 2017 - 3:26 pm

Preserve a Genius Shuffle Playlist

One of my favorite features of iTunes is Genius Shuffle. By pressing the Option key and Space Bar simultaneously, iTunes will construct a 25-track Genius-type playlist in Up Next around a "seed" track it chooses at random from your library. Typically, I'll slap Option-Space Bar repeatedly until I get the type of songs I'm in the mood for. Sometimes though—because I have an itchy DJ finger—I'll abandon the current set of tracks after a few songs and create a new different Genius Shuffle arrangement. But still I'd like to have been able to save the playlist I had abandoned because, at least for a while there, I really liked it. Well, you can do this with AppleScript.

When iTunes is playing Up Next like this the track references are available in current playlist. It is a simple matter to copy them to a new playlist. The script I've listed below asks for a name for the new playlist; I've set the default answer in the display dialog to "Genius Shuffle" and when I run the script I'll keep that in the name, for example: "Rockin' Blues - Genius Shuffle", "70's Funk - Genius Shuffle", and so on.

tell application "iTunes"

try

if not (exists current playlist) then error

set opt to (display dialog "Enter a name for the new playlist:" default answer "Genius Shuffle")

set newP to (make new user playlist with properties {name:text returned of opt})

duplicate every track of current playlist to newP

reveal newP

on error

return

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.

One issue is that if any of the tracks in Up Next are "dead" tracks then the script will fail (a repeat loop could duplicate each track individually to filter dead tracks, but I wanted to keep this simple). On the other hand, I think iTunes will ignore dead tracks when it creates a Genius Shuffle playlist.

Also I would only run this after creating a Genius Shuffle playlist; it doesn't make much sense to run it when anything else is playing.

February 26 2017 - 8:37 am

How to Blankety-Blank Blank

As you may have noticed, the last few versions of iTunes have been gradually "contextualizing" the interface. For example, the Info window will only display the kind-pertinent tags for a selected track. (Remember: it used to be that the Info window displayed the same configuration for any track; so that Music tracks had access to TV-kind tags, like Season and Episode ID, and so on.)

Despite this, when the iTunes browser window is in Songs view, non-contextual tags can still be displayed and tracks can still be sorted using them. This is because every track entry in the database has the same columns whether they are used for that kind of track or not. Thus, for example, Music tracks have "season" and "episode ID" track tags even though they are not used for Music tracks.

AppleScript can access these tags and a script of mine, Sort by Artwork Size, can store the dimensions of a track's artwork (eg, "600x600") to the Category or Episode ID tag. Tracks can then be sorted by their "artwork size" or those tags can be used when constructing Smart playlist criteria.

However, since these tags can't be accessed very easily it is a chore to clear them if they are no longer required. So here's a script that will blank a particular tag of all the selected tracks. In this case, it blanks the episode ID tag. For people who already know how to script such a thing, this will be easy as pie. But, if your skill level as a scripter is below Dabbler, you may want to use this as a template for your own blanking scripts: (more…)

August 20 2016 - 6:15 am

Copy Grouping to Work

As you probably know, the latest beta version of iTunes 12.5 includes Work and Movement track tags which Classical music listeners will appreciate. In many cases, you might want to use the text in the Grouping tag for the Work tag. While it might seem easy to just do a Multi-Edit on the tracks and copy-and-paste using the Get Info fields, you'd only be able to do this for individual batches of a single work at a time.

Here's an AppleScript that will simply copy the Grouping tag to the Work tag for any number of selected tracks:

tell application "iTunes"

set sel to selection of front browser window

if sel is {} then return

repeat with aTrack in sel

try

tell aTrack to set work to (get grouping)

end try

end repeat

end tell

Save this named whatever you like to your [home]/Library/iTunes/Scripts/ folder so that it will appear in the iTunes Script menu. Select some tracks and launch the script by selecting it from the Script menu. The text from the Grouping tag, even if it's blank, will be copied to the Work tag of each selected track.

UPDATE: This script can be downloaded as part of the Work and Movement Scripts.

August 15 2016 - 12:02 pm

Hassle-Free Playlist Description

One of the neat things that Apple added to iTunes not so long ago is the user-editable description that is available for regular Playlists (Smart, Folder, Genius and Master library playlists do not have this option) and is visible when the Playlist is in Playlist View. You can edit this description by clicking the Playlist's "Edit Playlist" button. But when you do this, the iTunes interface changes: a column appears at the right edge of iTunes listing the current tracks in the playlist to which you can drag tracks. It also will change the (now center column) browser window to display the full Music library, which totally discombobulates me.

I do not always care for this when I just want to edit the Playlist's description. I'd prefer to do so without shaking up the interface. This script will do it:

tell application "iTunes"

try

set thisPlaylist to (get view of front browser window)

tell thisPlaylist

if special kind is not none or smart or genius or shared then error

end tell

on error

beep

return

end try

set defaultAnswer to (get thisPlaylist's description)

if defaultAnswer is missing value then set defaultAnswer to ""

set newDescription to text returned of ¬

(display dialog "Enter the description text for the playlist" & return ¬

& thisPlaylist's name default answer defaultAnswer)

try

set thisPlaylist's description to newDescription

end try

end tell

Save this named whatever you like to your [home]/Library/iTunes/Scripts/ folder so that it will appear in the iTunes Script menu. Select a playlist and launch the script by selecting it from the Script menu. It will quit if the selected playlist is the wrong kind. It will display the current description for the playlist if it exists, otherwise the text field will be blank. Enter up to 255 characters, which is the most that the description can accept, and then click "OK".

Give this a keyboard shortcut to maximize your quality of life.

August 5 2016 - 6:38 am

The Next Track, Episode 12

In Episode 12 of The Next Track podcast, Kirk and I talk about iTunes and AppleScript. During the episode, we mentioned the following scripts:

Artist - Name Corrector
Remove n Characters from Front or Back
This Tag, That Tag
Search Replace Tag Text
Proper English Title Capitalization
List MIAs
Super Remove Dead Tracks
Music Folder Files Not Added
Move Playlists to Folder
Playlist Manager
Find Album Artwork With Google
Save Album Art as folder.jpg
Embed Artwork
Re-Embed Artwork
PDF Adder
View Cached Music
Copy Tag Info Tracks to Tracks
A Space Between

In case you don't know, The Next Track is a weekly 30-minute podcast in which Kirk McElhearn and I discuss how people listen to music today; it was inevitable we'd talk about iTunes and AppleScript at some point, right?

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.