Managing Scripts With Script Menu

Are you like me? Do you have over 200 AppleScripts in your iTunes "Scripts" folder?

OK, you're probably not like me.

But maybe you're having trouble managing just a few dozen scripts in the Script menu. Maybe it's time to migrate your iTunes AppleScripts over to the system-wide Script Menu where you can use sub-folders for organizing. Here are a few tips.

 

Outgrown Your iTunes Script Menu?

If you've found that scrolling your iTunes Script menu is taking valuable time out of your day, you may want to place your iTunes AppleScripts in the much more versatile system-wide Script Menu, which is accessible from anywhere in the upper-right corner of the menubar. I refer to it as much more versatile because, unlike the Script menu in iTunes and other Apple applications, the Script Menu can recognize nested folders.

As my wife would say, "Let's get organized!"

Advantages?

Let's weigh the pros and cons of each Script menu, shall we?

iTunes Script Menu Pros & Cons:

    iTunes Script Menu - Pros
  • Makes compiled and application AppleScripts readily available from within iTunes
  • Organizes scripts by alpha-numeric file names
  • Recognizes scripts inside of folders—one-deep
  • Virtually unlimited number of scripts can be viewed, if you can tolerate scrolling. (Oop! Should that be in the "Cons" list?)
    iTunes Script Menu - Cons
  • Can't use sub-folders to organize groups of like-tasking scripts
  • Can't Option-click a script to edit in Script Editor
  • Can't dynamically organize scripts based on current iTunes activity—OK, wishful thinking

Don't get me wrong. I love my iTunes Script menu.

 

System Script Menu Pros & Cons:

    Mac OS Script Menu - Pros
  • Organizes scripts and folders by alpha-numeric file/folder names
  • Dynamically makes relevant compiled and application AppleScripts readily available for the frontmost application
  • Recognizes and displays sub-folders—several depths—containing scripts
  • Option-clicking a script in Script Menu opens it in Script Editor; Shift-clicking reveals it in the Finder
  • Installed scripts can be made available for all users
    Mac OS Script Menu - Cons
  • Some compiled iTunes scripts can run exteremely slow when run from Script Menu...see below
  • Somewhat complex setting up Script folders for local/all users

Hmm....

 

Set Up Your Script Menu

When you first install Mac OS X, you won't have a system-wide Script Menu unless you tell your machine to git it going.

To do so, go to your "Applications" folder on your startup disk (or select "Applications" from the Finder's "Go" menu) and open the "AppleScript" folder. Inside this folder is an application called "AppleScript Utility". Double-click it to activate it.

Now, you have to set some of its Preferences.

Here's how mine are set:

Review:

  • Default Script Editor - Should be set to your preferred application for creating and editing scripts. The current version of Script Editor is OK
  • GUI Scripting - Enable to use GUI scripting, which is a way of automating menu commands, buttons, tabs, and other GUI elements of applications
  • Show Script Menu in menu bar - Be sure to check so that you can access scripts from the menu bar
  • Show Library Scripts - That is, show the scripts and script folders located in the current User's Library
  • Show application scripts at - I use "top" so that any scripts for the frontmost application appear at the top
 

Set Up Your Script Folders

This can be a little confusing at first. In order for scripts to appear properly in the correct order in the Script Menu they have to be placed in different locations, which doesn't always seem intuitive.

If you have set up your "AppleScript Utility" settings as I have above then AppleScripts for the frontmost application—if any—will be displayed at the top, next will be a section containing any scripts available for all users, and the lower section will contain scripts and folders for the current user.

AppleScripts for the frontmost application should be placed in the username / Library / Scripts / Applications / nameOfApplication folder. The username / Library / Scripts folder is not installed by default, so you will have to create these folders. Thus, in order to have AppleScripts for iTunes appear at the top of the Script Menu when iTunes is active, you will have folders set up like username / Library / Scripts / Applications / iTunes and your iTunes AppleScripts should be installed there.

AppleScripts for the current user should be placed in the username / Library / Scripts folder. As mentioned above, this is not installed by default, so you will have to create the Scripts folder yourself.

AppleScripts for all users should be placed in the startupdisk / Library / Scripts folder. Apple has pre-installed several folders of AppleScripts here already. If you prefer not to display these AppleScripts in the Script Menu, uncheck the Show Library Scripts setting in "AppleScript Utility".

Now, once you've acclimated yourself to those configurations, you can start organizing your scripts.

Open the username / Library / Scripts / Applications / iTunes folder and place your iTunes scripts in it. Now, create folders in this folder so you can organize your iTunes scripts by task, such as "Managing Tracks", "Managing Track Info, "iPod", "Internet", and so on.

Another advantage to using the Script Menu is that aliases to scripts you have already installed can be placed inside those Scripts folders. So, rather than make copies of the scripts you have already installed in your iTunes Scripts folder, you can drag aliases of them to the username / Library / Scripts / Applications / iTunes folder.

Your active Script Menu display may look something like this. iTunes is the active application so the iTunes scripts appear grouped at the top (remember I told "AppleScript Utility" this is where I want them):

Now, here's another tip. Rather than create an iTunes folder in username / Library / Scripts / Applications, organize your iTunes scripts in the username / Library / Scripts / iTunes folder and put an alias to that iTunes folder in the username / Library / Scripts / Applications folder. Now, your iTunes scripts will be available from any application in the User area of Script Menu and at the top when iTunes is active.

Remember that if you run an iTunes script and iTunes is not active, the script will probably activate iTunes. This may not always be desirable. Sometimes, I will put this snippet of code at the top of any script that may fire iTunes when I'd prefer that not to happen:

tell application "System Events" to if name of every process does not contain "iTunes" then return

-- continue with the rest of the script here...

This will prevent the script from continuing if iTunes is not active.

 

Trouble With Compiled Scripts!

OK, one drawback that I only hinted at above is that compiled AppleScripts work much slower when run from Script Menu than they do when they are run from the iTunes Script menu. This is because, in essence, compiled AppleScripts run from within iTunes work directly with iTunes. When compiled AppleScripts which target iTunes are run from Script Menu, a whole bunch of extra AppleScript stuff happens in the background. The extra activity can really slow things down. The difference in processing speed can be as great as 10 times! You may not care about this if the script only does a couple of tasks. But when checking every track of a playlist or large selection of tracks the time the script can take to run can make it virtually useless.

(This phenomenon does not apply to application scripts. They run "outside" of iTunes no matter where they are activated from.)





  Compiled AppleScript icon




  Application AppleScript icon

A brilliant suggestion made by Correspondent David Powers is to leave your compiled AppleScripts in the iTunes "Scripts" folder, but create individual—shall we say—"trigger" scripts and place them in the Script Menu folder. These "trigger" scripts are simple one-line scripts that target a specific compiled script in the iTunes "Scripts" folder. For example, to run a script called "Swap Song Name With Artist", you would create a "trigger" script that looked like this...

tell application "iTunes" to run script (((path to library folder from user domain) as string) & "iTunes:Scripts:Swap Song Name With Artist.scpt") as alias

This script would be saved in the appropriate folder in your Script Menu folder with a name like "*Swap Song Name With Artist" and when it is activated would run the "Swap Song Name With Artist" compiled AppleScript in the iTunes "Scripts" folder; "Swap Song Name With Artist" would perform as quickly as if it had been activated from the iTunes Script menu!

 

These AppleScripts Will Do It For You!

1. Make The Folders

Here is a script that will:

  • Create a username / Library / Scripts folder (if none exists)
  • Create a username / Library / Scripts / iTunes folder (if none exists)
  • Create a username / Library / Scripts / Applications folder (if none exists)
  • Create an alias to the username / Library / Scripts / iTunes folder in username / Library / Scripts / Applications (if none exists)
  • Create "tasking" sub-folders in the username / Library / Scripts / iTunes folder (if none exist)


  Sub-folders created with the script

Afterwards, place your collection of iTunes AppleScripts in the username / Library / Scripts / iTunes folder, distributing among the tasking sub-folders if you wish. (Or, see the script below which creates "trigger" scripts for your compiled iTunes scripts.) iTunes scripts will then appear in an "iTunes" sub-folder in Script Menu's user scripts section; when iTunes is active, the scripts will appear in the application scripts section.

Click on the little script icon below to open the script in your Script Editor. "Save" it as "Make Script Menu Folders" (or whatever) wherever you wish.


2. Make The "Trigger" Scripts

The script below will allow you to select a compiled script from the iTunes "Scripts" folder and then it will create the "trigger" script for it. You can save the "trigger" script where appropriate in the Script Menu folders which you created with the script above. The "trigger" script will be named using a space prefixing the actual name of the script; thus, a "trigger" script for "Swap Song Name With Artist" would be named " Swap Song Name With Artist".

Click on the little script icon below to open the script in your Script Editor. "Save" it as "Make Trigger Script" (or whatever) wherever you wish. It can be saved as a compiled script or an application script. Smarties can probably even figure out how to convert it to a droplet!


Both of these scripts are available for download as Migrate to Script Menu.

 

For more information about using Script Menu, see these pages at Apple. As of this writing the information there is slightly outdated—there is no info on "AppleScript Utility"—but the explainations about Script Menu and the various folder locations is current.

This column is printer-friendly.
Site contents © 2001 - 2010 Doug Adams and weblished by Doug Adams, dougscripts AT mac DOT com.
All rights reserved. Legal.
AppleScript, iTunes, and iPod are registered trademarks of Apple Inc.
Image 01 Image 01 Image 01 Image 01 Image 01 Image 02 Image 03 Image 03 Image 03 Image 03