dougscripts.com

Archive for the
‘AppleScript’ Category

August 20 '16 - 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 '16 - 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 '16 - 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?

January 11 '16 - 6:15 am
Playlist Time to Playlist Name

Here’s a simple script that was inspired by a question Kirk got asked in his Ask the Tunes Guy column in Macworld last week. A user lamented that the playlist length (that is, its total time) is not available in the Music app on iOS. Kirk recommended adding this information to the playlist name in iTunes and then re-syncing. A good solution but kind of a chore. This script will do the renaming part for you.

Just select a playlist in iTunes and launch the script. It will display a confirmation dialog and then rename the playlist by appending the time length to its current name:

tell application “iTunes”

try

set thisPlaylist to view of front browser window

if special kind of thisPlaylist is none then

set newName to (my fixName(thisPlaylist’s name) & ” | ” & thisPlaylist’s time) as text

— confirm

try

display dialog “Rename selected playlist to:” & return & return & newName

on error

return

end try

tell thisPlaylist to set name to newName

else

error

end if

on error m number n

try

display dialog “Can’t change the selected playlist’s name.” buttons {“OK”}

end try

return

end try

end tell

to fixName(n)

if n does not contain “|” then return n

return text 1 thru ((offset of “|” in n) – 2) of n

end fixName

Couple of things to note: only user-created scripts (plain and Smart) can be affected. Also the script uses the “pipe” character to separate the actual name with the appended data. When you run the script again on a playlist that has previously been affected by the script, it uses the “|” as a marker to erase the appended text; thus, the playlist name can be updated if the contents changes at a later date. So, if you happen to already use “|” in your playlist names you may have a problem. You can edit the script in Script Editor to change each of the occurrences of “|” to some other text character that you aren’t likely to use.

November 24 '15 - 10:22 am
NEW: Doug’s Check For Update

While some applets and all apps from this site have a menu command to “Check for Update…”, many AppleScripts do not. To make it easier to check if a script you downloaded at one time or another has a newer version available, use Doug’s Check For Update. Just drop an AppleScript file on it (or launch it and use an Open Panel to navigate to a specific script) and it will check the website for the latest version of that script:

Doug's Check For Update

Sure, it’d be great if I could include a Sparkle-like mechanism to automatically check and install updates—as my apps do. But the code required to do so would just add too much overhead to a—very likely—simple AppleScript.

More information and download is here.

August 26 '15 - 1:19 pm
“10 things that iTunes does right”

Kirk lists ten things iTunes does right at Macworld.

I’m very partial to #10.

July 25 '15 - 2:34 pm
Get Asked This A Lot

“Do you have any scripts that work with iCloud Music Library/iTunes Match tracks? Like, to delete the cloud uploads and re-upload tracks?”

No. AppleScript cannot access anything in the cloud. Here’s one of the reasons why: While it’s certainly possible for me to write a script that arbitrarily deleted local tracks and files on your computer (with or without your knowledge), that’s OK because presumably you knew stuff was going to get deleted by running the script. It’s your responsibility, and Apple doesn’t care what you do on your machine. You could set in on fire if that’s what you wanted to do. Or install Flash. However, stuff in the cloud is Apple’s responsibility. And they have pretty much guaranteed you that your goods up there are safe. So they’re not going to let an AppleScript (of all things!) have arbitrary access to your goods in the cloud where it could potentially be a bad actor.

AppleScript can manipulate cloud tracks locally; for instance, copy such tracks to a new playlist or edit their tags. But anything to do directly with the cloud is strictly out-of-bounds.

July 17 '15 - 1:50 pm
iTunes 12.2 and AppleScript Issues, Volume 2

I have already noted the new loved properties for tracks and playlists. I must admit that an update to the iTunes sdef was heartening (pun not much intended). However, there are some lingering issues and new issues with the latest incarnation of iTunes. Perhaps they have yet to be got to. Yeah, that’s it. They’ll fix it, fingers crossed.

Pretty much anything to do with the Apple Music tabs is off limits to AppleScript. So, for example, you can’t select a track or playlist in “For You” and get info about it or manipulate it. I don’t mind this so much. Once tracks are added to “My Music”, they are accessible as shared tracks. It’d been the same with iTunes Match tracks. You can get and set the conventional track properties, you just can’t access file metadata because, by definition, there are no local files for tracks in the cloud. Still, access to tracks and playlists in “For You” and “New” might be convenient, if even for accessibility purposes.

I am disappointed that current track does not work with playing Apple Music tracks (if playing from within the “For You” tab). I’m not sure if there’s a security issue here, or it’s just not hooked up yet. Definetly screws up anything watching for current track to change. Notifications is aware of playing Apple Music tracks, so why not AppleScript? Even as read-only. I’d be cool with that.

The new Playlist view doesn’t seem quite hooked-up yet either. This is the new default view for local playlists. Anyone who’s ever worked with broadcast automation will note that the abridged track information in Playlist view is reminiscent of a music log. (Note to Apple: please let us change this default view. As much as I really like the Playlist view I prefer Songs view as default to work with track tagging and only switch to Playlist view on formal occasions.) AppleScript-wise, it’s all OK. But the reason I don’t think it’s hooked-up properly yet is by observing the pasteboard data from a playlist in Playlist view. Now, pasteboard data for dragged tracks and playlists typically contain metadata about the playlist and tracks being dragged. Except when the drag originates from a local playlist in Playlist view. In such cases, only the file paths are available in the pasteboard. And if cloud tracks are included in the drag, well, they don’t have local files, so nothing about them at all appears in the pasteboard. However, when the very same playlist is in Songs view, the metadata is available from the dragged tracks’ pasteboard as expected. So the data is already permissibly available, just not (yet?) in Playlist view. I suspect that, because it seems to be the same view used in “For You” when you play a playlist there, it has no provision for includiing metadata. Someone should get on that.

Also, there’s no AppleScript way to access the artwork(s) or description that is a part of the new playlist header. It would be convenient to be able to script a playlist’s description at least.

Many of my scripts and apps access the iTunes Library.xml file to get information about tracks and playlists. That’s what it’s there for. iTunes 12.2 has, uhm, mucked around with the format of this file. As a result, there’s been a big scramble by all of us who develop iTunes apps to re-jigger our stuff. The XML now contains information about mobile apps, Ringtones, iTunes LP, iTunes Extras, and books. The “Master” playlist has a name of “####!####” where it used to be “Library”. “Smart Info” and “Smart Criteria” keys are now being used with playlists other than the Smart variety. Additionally, there is now no way to tell the difference between Genius and Smart playlists; they look identical in the XML. Previously, a Genius playlist would key the persistent ID of its seed track and this would be a differentiating factor. But the “Genius Track ID” key is gone.

The new “Share iTunes Library XML with other applications” Preference setting is still a mystery to me, but I suppose there could be situations whereby you’d want this off. Sometimes I’m just plain dumb about things like that. But because some users think it looks like the perfect thing to uncheck I’ve needed to include a check for access to the XML at the start of many apps. Because if it’s off, the script or app won’t work.

On the bright-side though, despite the Apple Music considerations, iTunes still has pretty robust AppleScript support! So thanks for that, Apple.

December 29 '14 - 4:48 pm
MacVoices Podcast

Chuck Joiner invited me to join him on his MacVoices podcast. We talk about iTunes and AppleScript (of course) and obsessive-compulsive music organization, among other topics.

October 23 '13 - 12:00 pm
But There’s Good AppleScript News, Too

While losing iWorks AppleScript support is anxiety-inducing, some great new features have been added to AppleScript in Mavericks that are pretty exciting. I’ve played a little with libraries and Notifications in the DPs, but haven’t incorporated anything into my scripts since most a few of these features are not backwards-compatible on earlier operating systems.

Don Southard has a good article at MacStories outlining the latest stuff.

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