## Automating Tasks with AppleScript

You can use AppleScript to write small programs, or scripts, to automate common tasks in BibDesk. For example, you can have a script process all the titles of your references, cleaning them up or capitalizing them. Or you can use a script to download bibliography information for references from the web. Scripts can be made accessible from the Scripts Menu.

Here is an example of an AppleScript to process the titles of all selected references. (The definition of the subroutine to actually do the processing is not shown).

    tell application "BibDesk"
        set theSelection to the selection of document 1
        repeat with thePub in theSelection
            -- accessing field values
            set theTitle to the value of field "Title" of thePub
            -- processString is a subroutine defined elsewhere in the script
            set theTitle to my processString(theTitle)
            set the value of field "Title" of thePub to theTitle
        end repeat
    end tell

A more extensive sample of AppleScript support for BibDesk can be found in the script ``Sample Script.scpt'`. You can view it through the Scripts Menu.

To see the AppleScript commands you can use with BibDesk, open "Script Editor" (located in `Applications/AppleScript`). In "Script Editor", choose "File > Open Dictionary" (shortcut ⇧⌘O) and select BibDesk in the dialog. You can also drag the BibDesk icon onto the "Script Editor" icon to open the dictionary.