Hello,

This is a quick and dirty AppleScript I've made for my personal use. It adds 
the PDF files linked to the currently selected publications to iTunes, so they 
can later be synced to the iBooks app on an iPhone or an iPad.

The PDF is tagged with the year, title and authors' last names in iTunes. While 
the script can manage multiple publications at once, it only adds the first 
linked PDF (I had no need for more, and no use case to test). It's quite slow 
and gives no feedback upon error or completion.

By all means, if you're interested, please criticize what's wrong with it!

Source file is here (text format) : 
http://meidosem.com/stuff/Add%20PDF%20to%20iTunes.applescript

Here's the code :

on run
        tell application "BibDesk"
                set sel to selection of document 1
                repeat with pub in sel
                        try
                                set authList to last name of every author of pub
                                set auth to my list_to_text(authList, ", ")
                                set y to publication year of pub
                                set tit_ to title of pub
                                set tit to my clean_brackets(tit_)
                                set fil to (first linked file of pub whose 
POSIX path contains ".pdf")
                                my add_to_iTunes(fil, tit, auth, y)
                        end try
                end repeat
        end tell
end run

-- Inspired by Doug Adams' PDF Adder, http://dougscripts.com/300.
on add_to_iTunes(fil, tit, auth, y)
        tell application "iTunes"
                set new_PDF to (add fil)
                tell new_PDF
                        set {name, artist, year} to {tit, auth, y}
                        set loc to location
                end tell
                return {(location of new_PDF), new_PDF}
        end tell
end add_to_iTunes

on clean_brackets(s) -- dirty handler to remove {} from publication titles. 
Nothing is done for the accents.
        set shellstring to "echo " & quoted form of s & " |sed 's/[\\{}]//g'"
        return do shell script shellstring
end clean_brackets

on list_to_text(l, delim)
        set oldDelim to AppleScript's text item delimiters
        try
                set AppleScript's text item delimiters to {delim}
                set newString to (every item of l) as text
        end try
        set AppleScript's text item delimiters to oldDelim
        return newString
end list_to_text

Enjoy!

Louis-Jean
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Bibdesk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-users

Reply via email to