BibDesk Script Hook Sample 2

Here is an example for an AppleScript you can set for a Save Document script hook. It exports an RSS representation of the document in the same folder as the BibTeX file whenever the document is saved.

 
property theTemplateName : "Default RSS template"
property theFileExtension : ".rss"

using terms from application "BibDesk"
    on perform BibDesk action with publications thePubs for script hook theScriptHook
        -- get some properties from the script hook
        set theName to the name of theScriptHook
        set theDocument to the document of theScriptHook
        -- check if we get the right script hook event
        if theName is not "Save Document" then return
        -- get the document's file
        set theDocFile to the file of theDocument
        tell application "Finder"
            -- extract containing folder and file name
            set theFolder to the container of theDocFile as text
            set theFileName to the name of theDocFile
            -- change extension to "rss"
            if the name extension of theDocFile is not "" then
                set AppleScript's text item delimiters to "."
                set theFileName to text items 1 thru -2 of theFileName as text
            end if
            set theFileName to theFileName & theFileExtension
            -- create a reference to the file
            set theFile to (theFileName & theFolder) as file specification
        end tell
        -- now export using the template
        tell theDocument
            export using template theTemplateName to theFile
        end tell
    end perform BibDesk action with publications
end using terms from

The main thing that should be done in the script is to define a `perform BibDesk action with publications' subroutine to handle the script hook. An important thing to note is that you should bracket the whole subroutine in `using terms from application "BibDesk"', so that certain AppleScript definitions (such as the subroutine name) are recognized.

For another sample script, look in the Scripts Menu of BibDesk. To view its source, select the "Sample Script Hook" menu item with the Option key held down.