Tag Archive: “applescript”
Yojimbo Tag Companions
I use this little script when I want to ensure that every Yojimbo item with a certain tag also has some other tags. For instance, to ensure that every leoben item is also tagged cylon, I run the script, select leoben from the first list of tags that appears, and cylon from the second list.
Posted on Thursday, January 17th, 2008.
Select Grep

This script for the Finder is derived directly from the venerable lselect. Rather than select files whose names match a certain pattern, Select Grep selects files whose contents match a certain pattern.
Subdirectories are not searched and the pattern is not case sensitive. Extended regular expressions are supported. Compatibility with binary files has not been tested. The specific options given to grep are -liE. The script is easily edited to use different option combinations; please share any improvements.
Put the script in ~/Library/Scripts/Applications/Finder and run it to select files in the frontmost Finder window that contain the search pattern.
Posted on Saturday, December 8th, 2007.
iTunes Library Item Transfer
My laptop has a 60 GB hard drive. I have a 500 GB external drive which houses my iTunes library and other media. I like to keep some iTunes content on my laptop, but using the Finder or the “Add to Library” file browser to move particular things between libraries gets tedious.
So, I wrote a script that makes it a little simpler. Now I can use iTunes itself to select the items to transfer instead of browsing for the actual files to pull into the target library. Might not sound like a big difference, but it seems like less fuss to me.
Here’s how it works.
Download the script (5k) and put it in ~/Library/Scripts/Applications/iTunes.
Select some items in iTunes and run the script. iTunes will quit and you will be prompted to reopen it with a different library:

Hold down the Option key as iTunes starts up to select a different library. If you’re transferring files to a new library for the first time, you could even create the new library at this point.

Once you have finished choosing a library, return to the prompt and click Transfer. The items you previously selected will be transferred to the current library and shown in a new “Transfer” playlist labeled with the current date and time.
Tested with Mac OS X 10.4.11 and iTunes 7.5 with the “Copy files to iTunes Music folder when adding to library” option enabled under Advanced→General preferences.
I reckon this could be done with iPhoto, too.
Posted on Thursday, November 15th, 2007.
Lselect Toolbar Icon
Henrik Nyh has created a great Leopard-themed toolbar icon for lselect. Read his post for more information about using lselect and other useful scripts as Finder toolbar buttons with custom icons.
For your convenience, I’ve prepared a copy of the script as a tiny application ready to drag to your toolbar:
Download lselect toolbar app 15k
This is a fine time to mention that lselect really is quite useful! Use it to quickly select all the files in a folder that match a simple pattern.
Posted on Tuesday, November 6th, 2007.
Resize Pages Graphics by Percent
Conspicuously missing from Pages is the ability to resize graphic objects by specific percents. You can say “make this graphic 2 inches wide,” but you can’t say “make this graphic 30% of its current width.” So, I wrote a script to do the dirty work for me:

It resizes the selected graphics by the specified percentage.
Download
The “Recenter” version keeps the graphic centered at its original location, which I have found to be rather annoying. Install in ~/Library/Scripts/Applications/Pages/ and invoke with a script runner of your choice.
Notes
Unfortunately, there doesn’t seem to be a scriptable way to determine whether the “Constrain proportions” options is set for a particular graphic. Since this option affects size changes, I simply make the assumption that it is set. It is, by default, for inserted images. For other graphics, check the “Metrics” inspector pane:

Note that images are not necessarily inserted at their original size. If you want to resize an image to some percentage of its actual size, be sure to click the “Original Size” button before resizing.
This script was written with Pages’ page layout mode in mind, but it should work with graphics in word processing mode, too. There are some rough edges, particularly where handling different sorts of selections is concerned.
Here is a video demonstration.
Posted on Monday, September 24th, 2007.
Script Runners
Rather than repeatedly explaining how to launch each script I write, I’m going to use this post as a generic reference.
AppleScripts are typically little bits of code that extend or connect your applications’ functionality. As such, they are not necessarily invoked like normal programs. Many fine utilities exist which provide convenient ways to run scripts, including LaunchBar, Butler, QuickSilver, Keyboard Maestro, and others. Here, however, I will describe the simple script runners I prefer, one of which is even built in to Mac OS X.
FastScripts
I favor FastScripts, which utilizes the same script folders as Apple’s Script Menu. It features assignable keyboard shortcuts, which help scripts act more like natural extensions of your applications. The FastScripts menu looks like this:

Apple Script Menu
To enable the Script Menu, open “AppleScript Utility” (in /Applications/AppleScript/) and check the “Show Script Menu in menu bar” option:

A “script” icon will appear in your menu bar. It displays a menu like this:

Scripts stored in ~/Library/Scripts/Applications/Finder/ are listed in the “Finder Scripts” section, which appears only when the Finder is the frontmost application. Scripts stored in ~/Library/Scripts/ are listed in the unlabeled section and are always accessible. You can create application subfolders for application-specific scripts yourself. The tilde (~) represents your home folder.
Here is a video demonstration of the Script Menu.
Posted on Monday, September 24th, 2007.
Yojimbo Script Updates
Minor updates to a few Yojimbo AppleScripts are available: Export with Comment Tags, Archive Bookmarks, and Backdate Items. These updates allow the scripts to act on items even when Yojimbo’s item list pane does not have input focus. This means you can run the scripts when editing items as well as when selecting them.
Posted on Friday, August 31st, 2007.
Yojimbo Export with Comment Tags
In response to this query, I wrote a script which allows Yojimbo items to be exported with their tags preserved as Spotlight comments. I don’t really use Spotlight, so I’m not sure if the comment format is ideal, but it works fine for a first draft.
Now updated for compatibility with Mac OS X 10.5.
Download ExportwithCommentTags.scpt.zip 1.2 4k
Put the script in ~/Library/Scripts/Applications/Yojimbo, select some items, and choose “Export with Comment Tags” from your script menu.
Posted on Thursday, August 30th, 2007.
“Open As” Pseudo-Stationery Finder AppleScript
Use this AppleScript to create and open an explicitly named copy of the selected file or folder. You will be prompted to specify the name and location of the new copy. Clicking “Save” will duplicate the item and open the new duplicate.

This script is the result of dissatisfaction with some applications’ lack of support for Stationery Pad files. Specifically, the default behavior appears to be for the Finder to create and open a generic duplicate with “copy [#]” appended to the original base filename. I find it more convenient to name the new instance directly, so that is the functionality this script provides. Stationery pads are not required as it works with regular files.
Rigorous testing has not been performed. Be advised that duplication is performed with cp, which ignored the resource fork in early versions of Mac OS X. Therefore, Mac OS X 10.4 is strongly recommended for compatibility with all files.
Download FinderOpenAs.scpt.zip 3.4K
I suggest saving the script in ~/Library/Scripts/Applications/Finder and assigning it the keyboard shortcut Shift-Command-O via FastScripts.
Posted on Friday, August 17th, 2007.
Archive Yojimbo Bookmarks
Yojimbo can catalog bookmarks as well as web archives, which are basically local copies of web sites. This script creates web archives from existing bookmarks you select.
tell application "Yojimbo"
-- get the selected items, if any
set _items to selection
if _items is missing value then return
-- archive all the selected bookmark items
repeat with _item in _items
if class of _item is bookmark item then
-- bookmark properties the archive should inherit
set _name to name of _item
set _url to location of _item
set _tags to tags of _item
-- archive the bookmarked page
try
set _archive to make new web archive item with contents _url with properties {name:_name}
add tags _tags to _archive
end try
end if
end repeat
end tell
Download ArchiveYojimboBookmarks.scpt.zip 1.1 3k
Install the script in ~/Library/Scripts/Applications/Yojimbo. The script does not check whether there is already a web archive for the bookmarked location, but it could be done.
Posted on Sunday, July 15th, 2007.