dougscripts.com

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, you need to set some AppleScripting options that are accessible in AppleScript Editor's Preferences pane. I guess some people at Apple didn't want AppleScripting stuff in a more prominent spot in the System Preferences. So activate AppleScript Editor and open its Preferences pane. Click the "General" tab.

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 AppleScript Editor is fine
  • Default Language - Unless you have installed something else, leave as is
  • Show inherited items in dictionary viewer - This is a convenience while examining an application's AppleScript dictionary; OK to ignore
  • Show Script menu in menu bar - Be sure to check so that you can access scripts from the System-wide menu bar
  • Show Computer scripts - That is, show the scripts and script folders located in the current User's Library folder
  • 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 preference 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.

Note: As of OS X 10.7 (Lion), the user Library directory referred to below is hidden by default. Option-click the Finder's "Go" menu and select "Library" to make it visible.

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.

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:

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 call the handler below in any script that may fire iTunes when I'd prefer that not to happen:

if not iTunesIsActive() then return

-- proceed with the rest of the script

on iTunesIsActive()
	tell application "System Events" to return (exists (some process whose name is "iTunes"))
end iTunesIsActive


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!

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.