Page 1 of 1

Decrement Matched Date Pattern

PostPosted: Sat Nov 07, 2020 5:36 am
by Pelorus32
I've got a rule that matches the Due Date in a bill. I've called this PayDate. I want to decrement that matched date by 3 and pass it to an AppleScript to set up a task in OmniFocus. That is, I want the OmniFocus task to tell me to pay the bill 3 days before the Due Date which was matched in Hazel.

Is there a way to do this? I'm crap at AppleScript but I have a script working that does everything...except decrement the date by 3...and I have been unsuccessful in working out how to do that.

Many thanks
Mike

Re: Decrement Matched Date Pattern

PostPosted: Sun Nov 08, 2020 10:24 pm
by Pelorus32
So here's the solution I came up with...it might be ugly, but it works.

I do a search first, do some renaming of the file to add dates and type of utility then this script. The third line decrements the date by 3 days so that I pay the bill 3 days before the due date. It seems to work OK.

Code: Select all
tell application "Finder" to set file_name to (name of theFile)
set file_name to item 1 of inputAttributes
set item 2 of inputAttributes to ((item 2 of inputAttributes) - (3 * days))
tell application "OmniFocus"
   tell front document
      set theDueDate to item 2 of inputAttributes
      set theProject to first flattened project where its name = "Bills"
      tell theProject
         set theTask to make new task with properties {name:("Pay " & item 3 of inputAttributes), due date:theDueDate}
         tell the note of theTask
            make new file attachment with properties {file name:theFile, embedded:true}
         end tell
      end tell
   end tell
end tell


I pass in 3 variables in the inputAttributes list - respectively item 1 - item 3:

    name - filename
    paydate = the due date of the bill - the result of a search for a date pattern
    utility = a search result giving the name of the utility this bill refers to

Pelorus32 wrote:I've got a rule that matches the Due Date in a bill. I've called this PayDate. I want to decrement that matched date by 3 and pass it to an AppleScript to set up a task in OmniFocus. That is, I want the OmniFocus task to tell me to pay the bill 3 days before the Due Date which was matched in Hazel.

Is there a way to do this? I'm crap at AppleScript but I have a script working that does everything...except decrement the date by 3...and I have been unsuccessful in working out how to do that.

Many thanks
Mike