The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Folder action for automatically adding new files to OmniFocus (http://forums.omnigroup.com/showthread.php?t=20161)

dave_m 2011-02-16 09:25 AM

Folder action for automatically adding new files to OmniFocus
 
1 Attachment(s)
A user emailed earlier in the week wondering if there was a way to automatically add bills that he was scanning as PDFs to OmniFocus as actions. He knew that he could have his scanning software place the PDFs in a particular folder, but wasn't sure how to get them into OmniFocus from there without too many clicks.

The answer I came up with is the attached Folder action script. It takes any files that are added to the folder and attaches them to individual actions in the quick entry window.

To use, extract the .scpt file from the .zip and place it in /Library/Scripts/Folder Action Scripts/. You can add the action to any folder by control-clicking that folder in the finder and choosing Services >Folder Actions Setup...

I am by no means an AppleScript expert so there may be some situations where the script fails, but in my testing here it works well. As always, your feedback is welcome

RobTrew 2011-02-16 10:23 AM

[QUOTE=dave_m;93442]To use, extract the .scpt file from the .zip and place it in /Library/Scripts/Folder Action Scripts/. [/QUOTE]

Looks good.

I would probably tend to install it in[INDENT]~/Library/Scripts/Folder Action Scripts
(where ~ is the user's home folder)[/INDENT]rather than[INDENT]/Library/Scripts/Folder Action Scripts
(under the root, affecting all users)[/INDENT]

kingsinger 2011-02-19 01:08 AM

I'm assuming it leaves the attached file in the folder with the folder action attached? Is that right?

whpalmer4 2011-02-19 08:19 AM

[QUOTE=kingsinger;93643]I'm assuming it leaves the attached file in the folder with the folder action attached? Is that right?[/QUOTE]
That's right, it doesn't do anything to the file, just opens the quick entry window and makes an action with the file embedded.

kingsinger 2011-02-19 12:40 PM

[QUOTE=whpalmer4;93680]That's right, it doesn't do anything to the file, just opens the quick entry window and makes an action with the file embedded.[/QUOTE]

What happens if you move the file later? Does OF put a copy of the file in its own directory somewhere that isn't affected by moving the file in the original folder? Or does the link adjust to the new location?

whpalmer4 2011-02-19 03:35 PM

Note that I said "embedded" :-) It puts a copy of the file in the database, and you'll sync it all around, if you are syncing. If it is a file you are going to change, you need to proceed with caution or you will be burned sooner or later by not getting your changes back into the database copy. I don't recommend embedding files that you plan to edit unless you really understand how it all works. Safer to put it somewhere like MobileMe or Dropbox where you can edit it directly, and just have a link to the file (or even just the name). On the other hand, if it is a file you are only going to reference, not change, and the size isn't too large, you shouldn't have any trouble.

If you do embed a large file, note that you won't be truly rid of it until after all of your syncing devices have synced the change where you delete it and had an opportunity to compact the database (normally at least an hour later).

If you've linked a file instead of embedding it, if the file is no longer present at the same location, attempts to open it will get you a file chooser dialog along with a warning that the file cannot be located at the old path. If you navigate to the new location, the link in the db gets updated, or you can cancel and deal with it at some other time. If this behavior makes you think "hmm, maybe they just store the path to the file at the time I attached it" you would be 100% correct. A nice side effect of doing it this way is that if you've stored the file in a place that has the same path on any system you use (MobileMe, for example), you don't actually have to cart the payload around.

KevinCoates 2011-03-03 10:24 AM

Close quick entry?
 
Hi

Thanks for the script. Does anyone have suggestions for an addition to the script that would close the quick entry window rather than leaving it open?

I've taken a look but so far it's beyond me.

Kevin

whpalmer4 2011-03-03 11:36 AM

1 Attachment(s)
Here's an updated version of the script that allows customization of the behavior. The two properties at the top of the file control whether files are embedded or linked, and whether actions are added to the Quick Entry window or filed directly in the Inbox without user intervention.

If you want different behavior in a bunch of different directories, it might be worth making a couple of copies of the script, setting the properties, and saving with descriptive names.

m_kuhn 2012-11-24 03:27 PM

Incredibly helpful
 
Being an absolute AppleScript novice, to say the least. Would there be a way to take this Folder action script and modify it to add a default Project and context to the action as well?

This would simply make my year.

Here on David Sparks site he describes how to make an action via applescript with a default project and context:

-- Lovingly crafted by David Sparks, The Omni Group, and Ben Waldie -- macsparky.com

set theDate to current date
set theTask to "Pay Life Insurance"
set theNote to "Lovingly Scanned by your Mac on " & (theDate as string)

tell application "OmniFocus"
tell front document
set theContext to first flattened context where its name = "Tech"
set theProject to first flattened project where its name = "Finance"
tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext}
end tell
end tell

I am trying to accomplish some rather in depth Hazel, Paperless, automatic OCRing mojo and I thought I could simply look at the applescripts and combine them myself, but... Way beyond me. I know someone with some AppleScript chops can do it, probably in an instant.

Thanks in advance.

Jim Correia 2012-12-20 12:32 PM

1 Attachment(s)
[QUOTE=m_kuhn;117775]Being an absolute AppleScript novice, to say the least. Would there be a way to take this Folder action script and modify it to add a default Project and context to the action as well?

This would simply make my year.[/QUOTE]

Attached is a modification of Bill Palmer's script which allows you to specify the project and context when adding the task. (You can't specify a project when using Quick Entry due to a limitation in OmniFocus 1, and the items are always left in the Inbox since I minimally modified the existing script.)

Hopefully you can adapt this to your Hazel workflow without too much difficulty.

—Jim


All times are GMT -8. The time now is 08:00 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.