Spotlight indexing of Papers keywords

So far, spotlight indexing of Papers’ keywords is not possible (while being planned for a future release according to an email that I received today from one author). In the meantime, here is a workaround.

1. Export the whole Papers database as tmp.csv

2. Cut down the database to the necessary two columns: filename und tags. This can be done manually by loading the while file into Excel and extracting only column 39=path and column 7=keywords.
If you feel comfortable with the terminal issue

cat ‘tmp.csv’ | awk -F”;” ‘{print $39 “;” $7}’ >ExportPapers.csv

3. Finally, use the following applescript for tagging (after adjusting all paths)

 1:
 2:
 3:
 4:
 5:
 6:
 7:
 8:
 9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
47:
(*
    m@wjst.de 3/11/2010
    tagging PDF files with Paper keywords
*)
on replaceText(find, replace, subject)
    set prevTIDs to text item delimiters of AppleScript
    set text item delimiters of AppleScript to find
    set subject to text items of subject
    set text item delimiters of AppleScript to replace
    set subject to "" & subject
    set text item delimiters of AppleScript to prevTIDs
    return subject
end replaceText

on readFile(unixPath)
    set foo to (open for access (POSIX file unixPath))
    set txt to (read foo for (get eof foo) as «class utf8»)
    close access foo
    return txt
end readFile

set fn to "PapersExport.csv"
set all to get readFile(fn)
set all to get replaceText(", ", ",", all)
set AppleScript's text item delimiters to return
set all to every text item of all

repeat with k from 1 to count (all) by 1
    set f0 to item (k) of all
    if (offset of ";" in f0) > 1 then
        set fn to text 1 thru ((offset of ";" in f0) - 1) of f0
    end if
    set tn to ""
    if (length of f0) > (offset of ";" in f0) then
        set tn to text ((offset of ";" in f0) + 1) thru -1 of f0
    end if
    if tn is not "" and (offset of ";" in f0) > 1 then
        tell application "Tags"
            set fn to tag items for paths {fn}
            set fn to first item of fn
            set AppleScript's text item delimiters to ","
            set tn to every text item of tn
            set tags of fn to tn
        end tell
    end if
end repeat