Page 1 of 1

Shorten Filename based on regular expression

PostPosted: Sun Jun 19, 2016 6:28 pm
by adamnj
Hello everyone,

I am new to Hazel but very excited about obvious unlimited capabilities. One of my first tasks is to create a rule to move and rename my mobile created scanned business expense receipts. I have the OCR task performed via PDFpen, the import to Evernote script working, but would really appreciate some assistance with the simple task of renaming the files.

In short, I am saving the receipts when scanning via my iPhone as "EXPLunch.PDF" to a Dropbox folder. The "EXP" string is my identifier for Business receipts versus other files. What I would like to do is strip the "EXP" off of the name once the Hazel rule runs and then rename the file as just "Lunch.PDF.". I am sure that this can be easily done, but it is escaping me.

Thanks for any help!

Adam

Re: Shorten Filename based on regular expression

PostPosted: Mon Jun 20, 2016 11:27 am
by Mr_Noodle
Search for "match patterns" in the help. There you can match the parts you want to keep and rename using those.

Re: Shorten Filename based on regular expression

PostPosted: Wed Jun 22, 2016 10:27 am
by adamnj
Mr_Noodle wrote:Search for "match patterns" in the help. There you can match the parts you want to keep and rename using those.


Thank you...that was exactly what I needed. The matching works great in a rule I created, but I'm having a bit of difficulty now with an AppleScript component (integration with Evernote and OmniFocus). Drawing upon David Sparks' script, I am trying to make my Rule rename a financial bill, extract the due date (accomplished), rename the file with the due date and other criteria (accomplished), add a new note to Evernote (accomplished) and then add an entry to OmniFocus to pay the bill, WITH the due date as an input from Hazel (almost accomplished).

Below are screen shots of my Rule and the scripting. The behavior I'm seeing now is that the note keeps re-creating in Evernote as an endless loop, and nothing gets added to OmniFocus. I would so greatly appreciate some guidance as I've spent quite a bit of time reading and trying to figure this out:

Image

Image

Image

Re: Shorten Filename based on regular expression

PostPosted: Wed Jun 22, 2016 11:00 am
by Mr_Noodle
Your screenshots are a bit small but based on what you described, I'd check the logs. I'm guessing there's an error in the Omnifocus script. As a result, Hazel retries the rule which might explain the behavior you are seeing.

Re: Shorten Filename based on regular expression

PostPosted: Thu Jun 23, 2016 4:18 pm
by adamnj
Mr_Noodle wrote:Your screenshots are a bit small but based on what you described, I'd check the logs. I'm guessing there's an error in the Omnifocus script. As a result, Hazel retries the rule which might explain the behavior you are seeing.


Could you kindly direct me to where the applicable logs are stored? I've played around with the script some more but still can't get it to work. I really appreciate the help!

Re: Shorten Filename based on regular expression

PostPosted: Fri Jun 24, 2016 8:18 am
by adamnj
adamnj wrote:
Mr_Noodle wrote:Your screenshots are a bit small but based on what you described, I'd check the logs. I'm guessing there's an error in the Omnifocus script. As a result, Hazel retries the rule which might explain the behavior you are seeing.


Okay...I eliminated any errors and the new task is appearing in Omnifocus, with the file also being moved/renamed and put into Evernote. The only snag now is that a link to the file attachment is not being added to the Omnifocus note. Any ideas as to what may be amiss with my script:

set theTask to "Pay Chase Sapphire"
set theDate to item 1 of inputAttributes

tell application "OmniFocus"
tell front document
set theContext to first flattened context where its name = "Online"
set theProject to first flattened project where its name = "Bills"
tell theProject to make new task with properties {name:theTask, context:theContext, due date:theDate}
tell the note of newTask
make new file attachment with properties {file name:theFile, embedded:false}
end tell
end tell
end tell

Re: Shorten Filename based on regular expression

PostPosted: Fri Jun 24, 2016 11:59 am
by Mr_Noodle
Try the script outside of Hazel. If you still have the same issue then the problem is more likely on the OmniFocus end. In that case you should maybe check their forums.