Tag Archive: “applescript”
XML Parsing in AppleScript
I recently wrote a script that posts bookmarks from Yojimbo to Pinboard. Now that I have a nice system for posting links, I find that I’d like even more integration. For instance, I’d like to be able to keep Yojimbo in sync by downloading any links I post to Pinboard via other interfaces.
The Pinboard/Delicious API provides a variety of methods for retrieving link information, but there isn’t a straightforward way to parse the results in AppleScript. In my posting script, I just search the response for code="done". This is sufficient to tell if the add method succeeded, but methods that return more detailed information need more rigorous handling.
Incidentally, AppleScript supports direct interaction with SOAP or XML-RPC web services; see the documentation here. However, the Pinboard API uses a different architecture, REST (sort of).
Essentially, a query is represented as a URL, with parameters, and the XML results are returned by the server like the content of any other web page. (I use do shell script and curl to make the request and get the raw results; I don’t know if there is a better AppleScript idiom for general HTTP transactions. URL Access Scripting is dusty and requires writing temporary files.) The task is to extract the relevant bookmark information from the response.
As it turns out, the System Events scripting dictionary includes an XML suite, pictured above. Some experiments based on the examples given in this discussion at MacScripter confirm that it can be used to parse data returned by the Pinboard API. So, all the pieces necessary to implement a more sophisticated AppleScript bookmark syncing system are available.
Posted on Saturday, February 20th, 2010.
Safari, NetNewsWire, Yojimbo, and Pinboard
Bookmark Page in Yojimbo
This is a script for Safari. It’s a variation on my Bookmark in Yojimbo script. The original “Bookmark & Edit” option has been replaced with “Bookmark & Post to Pinboard”. I rarely want to edit a bookmark or its properties, but soon I might start sharing some links on Pinboard.
Bookmark News in Yojimbo
This is a script for NetNewsWire, a free feed reader for Mac OS X. It works just like the above script for Safari. It saves a bookmark to the current news item, and provides an option to spread the news by posting the bookmark to Pinboard. This is what I’m going to do instead of sharing items in Google Reader.
Post Bookmark to Pinboard
This is a script for Yojimbo, the program I use to save bookmarks and other bits of information. It posts the selected bookmark items to Pinboard. This script is invoked [and thus required] by the “Bookmark & Post to Pinboard” option in both scripts listed above.
Before posting a bookmark, the script prompts you to enter a description. The initial value of the description is based on the Yojimbo item comments. If you click “Post”, the bookmark will be posted with the given description but the Yojimbo item comments will not be changed; “Post & Update Comments” will change the item comments to match the entered description.
To help you keep track of what you’ve shared, items posted to Pinboard are added to a “Pinboard” collection, which will be created if it doesn’t already exist. As an example, here’s what my collection looks like at the moment:
And here’s how it looks on Pinboard:
Limitations
These scripts don’t deal with tags, labels, stars, or other features offered by Yojimbo or Pinboard. These scripts aren’t likely to be very useful if you’re not me. I don’t know exactly what happens if you post the same bookmark to Pinboard twice; I think it’s updated automatically.
There are bugs.
Download
Download all three scripts here (24 KB)
Configuration
Some assembly is required. I recommend installing the scripts in the following locations (create the directories if they don’t already exist). Run them with FastScripts or the regular script menu.
~/Library/Scripts/Applications/Safari/Bookmark Page in Yojimbo.scpt ~/Library/Scripts/Applications/NetNewsWire/Bookmark News in Yojimbo.scpt ~/Library/Scripts/Applications/Yojimbo/Post Bookmark to Pinboard.scpt
Edit the _pinboard_script_path property at the top of both “Bookmark in Yojimbo” scripts to identify the full path to your copy of the Pinboard script. In my case, this reads:
property _pinboard_script_path : "/Users/anoved/Library/Scripts/Applications/Yojimbo/Post Bookmark to Pinboard.scpt"
Lastly, edit the _API_username and _API_password properties at the top of the Pinboard script to reflect your Pinboard login information. Since the Pinboard API is essentially a clone of the Delicious API, it should be straightforward to modify this script to work with Delicious – but unfortunately I haven’t quite got it working. Don’t hold your breath for an update, but please do share any fixes or improvements.
Acknowledgements
The code to post to Pinboard is derived from this NetNewsWire to Delicious script by Larry and Andrew. My sketchy URL encoding code is lifted from this example at Mac OS X Automation.
Posted on Monday, February 15th, 2010.
yjnote
yjnote is a Mac OS X command-line tool for creating note items in Yojimbo. You can use it to pipe the output or usage notes of other programs into Yojimbo for reference or logging purposes.
Download
Download yjnote.zip (1.7 KB)
Tested, minimally, with Yojimbo 2.1 on Mac OS X 10.6.2. yjnote is written in Perl with a pinch of AppleScript. Further testing, bug fixes, and improvements are welcome (and likely necessary).
Usage
You can display this documentation at any time with yjnote -help.
NAME
yjnote − Create Yojimbo notes from the command line.
SYNOPSIS
yjnote [options] [FILE...]
DESCRIPTION
yjnote creates a Yojimbo note by concatenating the contents of the
given files (or by reading standard input, if no files are given).
OPTIONS
−title TEXT
Sets the note item title.
−comments TEXT
Sets the note item comments.
−label TEXT
Sets the note item label. Ignored if the label does not exist.
−tags TAG[,TAG,...]
Sets the note item tags. Separate tags with commas.
−flagged
Flags the note item.
−reveal
Reveals the newly created note in Yojimbo. By default, the new note
is not displayed.
Posted on Sunday, December 13th, 2009.
Bookmark in Yojimbo compatible with Yojimbo 2.0
The current version of my Bookmark in Yojimbo script is compatible with the recently-released Yojimbo 2.0.
Posted on Wednesday, September 2nd, 2009.
FastScripts 2.4
Daniel Jalkut has updated FastScripts, my utility of choice for running scripts or opening favorite files with a keystroke or a trip to the menu bar.

My FastScripts menu, as it appears in the Finder.
Notably, there is now just one version of FastScripts, which may be used for free or upgraded to allow more than ten keyboard shortcuts.
Posted on Monday, June 22nd, 2009.
FastScripts as Apple Menu
Back in the day, the System Folder contained an Apple Menu Items folder, the contents of which appeared in the Apple menu. Choosing an item from the menu opened the item from the folder. It was easy to customize the Apple menu by adding folders and aliases to the Apple Menu Items folder.
Here’s what it looked like by default in Mac OS 8.5:
In Mac OS X, of course, the Apple menu is no longer customizable. It still contains some useful items, but it’s not quite the familiar place it once was. The Dock has taken its place as a quick way to access favorite files and folders.
So, if you want to access a bunch of applications from a tidy little menu, and you don’t find it useful to throw your whole Applications folder in the Dock, you turn to the world of third party launchers. Here’s an unlikely solution.
FastScripts is a program I recommend for running scripts with keyboard shortcuts. It’s a power user thing. However, a little-advertised fact about FastScripts is that it will open anything in your Scripts folder, not just scripts.
Choose Open Scripts Folder from the FastScripts menu, and put whatever you’d like—including subfolders—in the folder that appears. Now you can launch those files from the FastScripts menu:
The script items in the menu reside in a subfolder of the Scripts/Applications folder. The subfolders are named after specific applications, and appear in the menu only when that application is frontmost.
Posted on Saturday, September 13th, 2008.
Bricksmith Custom Categories
Here is a hack to add new categories to the Bricksmith part browser. The part catalog is normally organized into categories based on the type of each part (such as brick, plate, or tile). However, if you’re building a model based on a real set, it’s just as useful to present the parts from that set in one category.
Adding a category from a Peeron inventory
To create a category consisting of the parts from set 4891, enter 4891 and click Peeron Inventory:
The script will retrieve the corresponding list of parts and populate a new category containing them:
Adding a category from a file
To create a category based on an arbitrary group of parts, save a list of part file names, like this:
3005.dat
3004.dat
3003.dat
3001.dat
Then enter a name for your category and click From File. You’ll be prompted to select the list you just created.
The script will add the listed parts to the named category:
Limitations
The script is awfully slow. AppleScript’s property list commands are not well suited for making many changes.
Parts listed in the file or inventory which are not already present in your part library will not be included in the category.
New categories are not visible until you restart Bricksmith. (I recommend quitting Bricksmith before running the script anyway.) Custom categories are lost when you reload the part list from Bricksmith’s Parts preferences.
No feedback is provided while the script is running.
Errors are not handled particularly well.
Mac OS X 10.5 is required.
It’s really slow.
Download
Bricksmith Catalog Custom Categories 26.4 KB
Posted on Saturday, June 21st, 2008.
Note Poster
Here’s a script to create a new post in MarsEdit from a note selected in Yojimbo. Why use a script when it’s already as easy as copy and paste? Well, maybe your computer is running out of paste.
tell application "Yojimbo" set _items to selected items of browser window 1 if (_items is {}) or (_items is missing value) then return set _note to item 1 of _items if class of _note is not note item then return end tell tell application "MarsEdit" set _post to make new document set body of _post to contents of contents of _note set title of _post to name of _note activate end tell
Click here to open the script directly in Script Editor. Save it in ~/Library/Scripts/Applications/Yojimbo and you’re ready to run.
Posted on Sunday, May 11th, 2008.
Toggling Line Numbers and Soft Wrap in TextWrangler
As with most text editors, TextWrangler provides many options that allow you to customize the editing interface. Two settings I sometimes change are accessible only as preference options or as toolbar menu items. As I would prefer to toggle these features with a single keystroke, I wrote a pair of scripts to do the job. Two associated keyboard shortcuts later, there’s no need to display the toolbar or visit the preferences.
Toggle Line Numbers
This script toggles the show line numbers property of the frontmost text window.

Toggle Soft Wrap
This script toggles the soft wrap text property of the frontmost text window.

Download
- Toggle Line Numbers 1.3 KB
- Toggle Soft Wrap 1.3 KB
The color scheme seen in the screenshots is Gruber Dark.
Installation
Unzip the scripts and put them in ~/Library/Application Support/TextWrangler/Scripts. Keyboard shortcuts can be assigned with the Set Key button in the Scripts palette, found under Palettes in the Window menu.
Posted on Monday, April 28th, 2008.
Bookmark in Yojimbo for Camino
I’ve posted a Camino-compatible version of my venerable Bookmark in Yojimbo script.
Update: Revised for Camino 1.6. New in Camino 1.6 is the ability to add any script in ~/Library/Scripts/Applications/Camino to the toolbar, so you don’t even need to use a separate script runner.
Posted on Tuesday, March 4th, 2008.











