Friday, May 18, 2012

All About AppleScript

Delicious Library is deeply integrated with the Mac platform. As part of this, it supports AppleScript — a great way to add new and custom features to Delicious Library. Perhaps you already use them, but what are they? And why should you care?

AppleScript is a programming language used to connect apps together on the Mac. AppleScripts are used to command applications to perform a sequence of tasks, and to manipulate the data managed by those apps. Here’s a simple example that counts the number of items in your library rated 4 stars or higher, and makes a TextEdit document saying so:

To try this out, open “AppleScript Editor” in your Applications/Utilities folder, paste it in, and click the Run button.

Delicious Library provides AppleScript access to most of the things you can do by hand, such as adding new items; modifying existing items; and managing shelves, friends, and loans. Scripts can take this data and combine it in new ways. For example, you could write a script that finds all your unwatched movies, and picks a random one for you to watch (try it here). With some more work, you could write a script that looks up Oscar-winning movies by year, and then makes Library shelves with the ones that you own.

Delicious Library comes with a few pre-written scripts that you can use with just a few simple clicks. To get started, go to Preferences (located in the menu bar under ‘Delicious Library’) and check the box next to ‘Enable example scripts’. This will add a new menu item with the icon of a script.

One of the most-used examples is to add Library of Congress (LoC) call numbers to books. As most of you know, we use Amazon to look up information on each item, but sometimes you might want details that Amazon doesn’t provide. You could go through and add LoC numbers by hand, but you could also use an AppleScript to do most of the work for you. After enabling the example scripts, open the script menu, select “Sample AppleScripts” and then “Fill in Library of Congress Call Numbers on Books”. The script will look up each selected item on the LoC website and try to fill in the numbers.

Delicious Library has a little-known feature where you can place scripts anywhere in the menus. Here’s a script to show a book on Open Library. Because it has the special “Menu Path” at the start, it shows up where it belongs:

Script in Item menu

(This also works for shell scripts, Ruby, Python, and whatever else!)

Not seeing the script you want? Interested in writing one of your own? You can start by looking at the included examples by opening the scripts folder, and the ones linked above. Feel free to use any of them as a base to modify however you like. There’s lots of information on AppleScript around the web, easily found with a simple search. We’re around on the forum for any Delicious Library-specific questions you have.

If you write a script that you’re proud of, tell us about it! You can either post it as an ‘idea’ on the forum or email Lia, our customer support extraordinaire at lia@delicious-monster.com. Be sure to include the script and a brief explanation of what it does.

Labels: ,