I figured out a workaround to setting string constants in Hazel. I can run an AppleScript that returns constants to Hazel. (Be sure to configure Hazel to save the return parameters.) Then I can call my generic AppleScript that adds a transaction to Quicken. (Be sure to configure Hazel to pass the appropriate parameters to the AppleScript.) This allows me to use the "add new transaction" script for multiple bills/statements without copying the bulk into multiple rules.
Here's my "set constants" AppleScript:
- Code: Select all
-- Return two constants: the payee and the category.
return {hazelStop:false, hazelOutputAttributes:{"Small Town USA Trash Company", "UtilitiesTrash"}}
Then I have an external AppleScript that runs Quicken, creates a new transaction, and enters the data. Note that the account to which the new transaction is entered must be the default account. Also, the account must be configured for the correct number of columns. Otherwise this script would need to add or remove the extra tabs that skip over unused columns.
- Code: Select all
-- theFile contains the file that matched the rule
-- inputAttributes 1: dueDate
-- inputAttributes 2: payee
-- inputAttributes 3: category
-- inputAttributes 4: charges
on hazelProcessFile(theFile, inputAttributes)
tell application "Quicken 2017" to activate
delay 1.0
-- Without delay, text is typed too fast for Quicken. (MINIMUM 0.3 with a large Quicken file)
set myDelay to 0.4
set myDueDate to item 1 of inputAttributes
set myPayee to item 2 of inputAttributes
set myCategory to item 3 of inputAttributes
set myCharges to item 4 of inputAttributes
-- Read date attributes and create a string we can enter as text
set myMonth to month of myDueDate as integer as string
set myDay to day of myDueDate as string
set myYear to year of myDueDate as string
set myDueDateStr to myMonth & "/" & myDay & "/" & myYear
-- List of data to enter into transaction.
set myList to {myDueDateStr, tab, "EFT", tab, myPayee, tab, myCategory, tab, tab, tab, myCharges, return}
-- New transaction in quicken.
tell application "System Events" to keystroke "n" using {command down}
delay 1.0
repeat with myItem in myList
tell application "System Events" to keystroke myItem
delay myDelay
end repeat
-- Quit quicken.
tell application "System Events" to keystroke "q" using {command down}
-- Give quicken a chance to quit before we jump into another rule possibly with quicken.
delay 1.0
end hazelProcessFile
I guess this morphed from a
Support to a
Tips & Tricks.