PDF's to OmniFocus

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

PDF's to OmniFocus Mon Jan 26, 2009 6:00 pm • by deviantintegral
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:

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
deviantintegral
 
Posts: 3
Joined: Mon Jan 26, 2009 1:48 pm

Re: PDF's to OmniFocus Mon Jan 26, 2009 6:09 pm • by Mr_Noodle
Check the help on applescript. If using a script in an external file, you need to put your code in a special handler that Hazel calls. The help contains a template you can use.
Mr_Noodle
Site Admin
 
Posts: 11196
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: PDF's to OmniFocus Mon Jan 26, 2009 6:57 pm • by deviantintegral
Thanks - sometimes I miss that prefpanes also have documentation :)
deviantintegral
 
Posts: 3
Joined: Mon Jan 26, 2009 1:48 pm

Re: PDF's to OmniFocus Sun Feb 06, 2011 10:16 am • by dg005978
I wonder if anyone could modify this script such that:

I can use my ScanSnap scanner to scan a file somewhere in a directory (for example downloads/omniscans) and then have Hazel move that file into a new action in Omnifocus. The file should become an extension rather than a link as I would have Hazel remove the file afterwards.

I did try some of the code in the apple script above but I noticed that Hazel tried to run the script even before the file had been completely scanned and OCR'd.

It would be nice that the Omnifocus new action dialog is opened after processing the file.

The idea is that I scan for example a bill that would end up in a new action in Omnifocus. I can then set the action to the date I need to pay the bill and it is then off my radar until it is time to pay. When the action shows up, I can open the file in the action for the payment details to pay it. When I complete the action in Omnifocus, I am sure the bill is paid.

The same workflow would work for seminars I want to look at at a later date because I am then in a better position to judge if I need to go.

I just hope there is anybody on this forum who can help me out here.

Thanks,

Jos van der Voort
dg005978
 
Posts: 3
Joined: Sun Feb 06, 2011 10:04 am

Re: PDF's to OmniFocus Fri Feb 11, 2011 10:38 am • by dg005978
Anybody? Please?

Jos van der Voort
dg005978
 
Posts: 3
Joined: Sun Feb 06, 2011 10:04 am

Re: PDF's to OmniFocus Sat Feb 12, 2011 7:40 am • by dg005978
I just found out that I can right click on any file and use the Send to Omnifocus menu command. This triggers exactly the behaviour I am looking for. Does anybody know how I can trigger this in Hazel?
dg005978
 
Posts: 3
Joined: Sun Feb 06, 2011 10:04 am

Re: PDF's to OmniFocus Mon Feb 14, 2011 12:07 pm • by Mr_Noodle
You should contact Omni (or check their forums) to see if there is an AppleScript equivalent of doing that command. Not being an OmniFocus user, I don't know what that does nor how its AppleScript support is.
Mr_Noodle
Site Admin
 
Posts: 11196
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: PDF's to OmniFocus Tue May 22, 2012 10:27 am • by Frederick
This is the clipping service. Assuming you have the default key code for it, the following should work:

Tell application "System Events"
Keystroke "m" using {command down, control down, option down}
End tell

Or....

You can use

Do script "SendtoOmniFocus"

Or....

You can copy the script itself. Go to your Applications folder Rightclick the Omnifocus file and choose Show Package Contents. The script will be under the Resources folder. Do not mess with the package.
Frederick
 
Posts: 8
Joined: Tue May 22, 2012 10:05 am


Return to Tips & Tricks - DO NOT POST QUESTIONS