PDF's to OmniFocus

I was finding that I ended up with many unsorted PDF's in my downloads folder. With a bit of AppleScript and Hazel, I'm able to move older files right into my OmniFocus inbox, complete with the title of the PDF in the action name.
For some reason, it only works if I put it in as an embedded script. If I save it as a file, I get the following error in the Hazel log:
2009-01-26 12:45:37.781 (null)[0] pjos-2-1.pdf: Rule Documents matched.
2009-01-26 12:45:41.806 hazelfolderwatch[17264] [Error] AppleScript failed: Error executing AppleScript /Users/andrew/Desktop/Review Documents.scpt on file /Users/andrew/Downloads/pjos-2-1.pdf.
2009-01-26 12:45:41.806 hazelfolderwatch[17264] AppleScript error: {
OSAScriptErrorNumber = -1708;
}
Any suggestions as to why this might be?
Anyways, here's the script:
For some reason, it only works if I put it in as an embedded script. If I save it as a file, I get the following error in the Hazel log:
2009-01-26 12:45:37.781 (null)[0] pjos-2-1.pdf: Rule Documents matched.
2009-01-26 12:45:41.806 hazelfolderwatch[17264] [Error] AppleScript failed: Error executing AppleScript /Users/andrew/Desktop/Review Documents.scpt on file /Users/andrew/Downloads/pjos-2-1.pdf.
2009-01-26 12:45:41.806 hazelfolderwatch[17264] AppleScript error: {
OSAScriptErrorNumber = -1708;
}
Any suggestions as to why this might be?
Anyways, here's the script:
- Code: Select all
tell application "Finder" to set filename to (name of theFile)
set command to "mdls -name kMDItemTitle " & quoted form of POSIX path of theFile
set output to (do shell script command)
-- skipping PDF files which do not contain a PDF title
if output is not equal to "kMDItemTitle = (null)" then
-- extracting the PDF title
set pdftitle to (characters 17 through -2 of output) as text
else
set pdftitle to filename
end if
tell application "OmniFocus"
tell default document
set newTask to make new inbox task with properties {name:"Review " & pdftitle, note:filename}
tell note of newTask
make new file attachment with properties {file name:theFile, embedded:true}
end tell
end tell
end tell
tell application "Finder" to move theFile to the trash