How to Use External AppleScript Handler?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

How to Use External AppleScript Handler? Wed Jun 02, 2021 11:31 pm • by Sebastian-Eli
Hey guys,

Sorry for asking, but I just don't know how to use the external applescript handler.
I Dont even know how to insert picture in this post...

well, below is my script
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set text item delimiters to theSearchString
set theTextItems to every text item of theText
set text item delimiters to theReplacementString
set theText to theTextItems as string
set text item delimiters to ""
return theText
end findAndReplaceInText

on hazelMatchFile(inputAttributes)

return true
end hazelMatchFile
set Amount to inputAttributes
set Amount to findAndReplaceInText(Amount, "$", "") as number
set murl to "moneywiz://expense?amount=" & Amount & "&category=Subscription&tag=membership&account=HSBC"

tell application "Safari"
tell window 1
set current tab to (make new tab with properties {URL:murl})
end tell
end tell


My purpose is that to monitor a folder full of receipt, get amount of expense from receipt.pdf (using custom text match in hazel "$123"), and using an applescript to import the amount variable, delete the currency mark in amount variable, and run a moneywiz url-scheme to auto record an expense.

this script runs perfectly if i change the imported variable into set variable inside this script. but the problem is that, if i use the embedded script, the "on FindandReplace..." will not be recognised and complied. but due to my poor knowledge and experience in programing, I just don't understand how to use the "on hazelMathFile" handler so that I can run this external script perfectly in hazel.

Thanks a lot if anyone can help!
Sebastian-Eli
 
Posts: 1
Joined: Wed Jun 02, 2021 12:38 pm

Your hazelMatchFile handler only has "return true" in it so it won't do anything except return that the file matches. All the stuff after "end hazelMatchFile" should be within that handler instead of outside of it.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron