Activating an AppleScript - but not processing a file

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

To help organize my simple finances, I have written a series of AppleScripts to automatically generate iCal events and fill in the appropriate fields whenever a bill arrives via email and when I pay a bill.

For the payment process, once I make the payments via web browser, I print to PDF and use Hazel to automatically re-name the PDFs and sort them into the appropriate folders. At the end of this is where I want Hazel to simply run one of the scripts to create the iCal events. The scripts work perfectly on their own, but not from Hazel. Optimally, I would like the files to link to the events that are created, but I've read that is not possible with iCal via AppleScript. Instead, I just need the scripts to be activated by Hazel. Is there a way to just have Hazel run a script without it actually doing anything with the file after it has been placed in its final destination?

This is one of the scripts that I want to have activated by Hazel:


tell application "iCal" to activate

set temp to display dialog "Enter payment amount and any additional notes, separated by a comma..." default answer ""
set text_user_entered to the text returned of temp
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
set variable1 to the first text item of text_user_entered
set variable2 to the second text item of text_user_entered
set AppleScript's text item delimiters to old_delimiters
set mainList to {"From checking", "From Credit Card1", "From Credit Card2", "From Credit Card3"}
choose from list mainList with prompt "Choose Payment Method"
set listchoice to result as text


set now to (current date)
set eStart to now + 1 * minutes
set eEnd to now + 2 * minutes
set eName to "AT&T PAYMENT MADE - $" & variable1
set theContent to listchoice & " - " & variable2
set eURL to "******"
set alarmTime to 30 -- alarm at the exact moment of the event


tell application "iCal"
set newEvent to make new event at end of events of calendar "Financial" with properties {summary:eName, description:theContent, url:eURL, start date:eStart, end date:eEnd}

end tell

display dialog "AT&T Payment of $" & variable1 & ", " & listchoice & " made and recorded."

tell application "iCal" to activate

tell application "iCal"
activate
set home_cal to calendar "Financial"
set the_event to first event of home_cal whose summary is eName
show the_event
end tell

tell application "Finder" to activate



I'm sure that this is a simple fix, but I've no clue yet. I've looked through dozens of the topics here, but there are none so far that address this.

Thanks!
Bulldogarf
 
Posts: 3
Joined: Thu Nov 18, 2010 2:27 pm

Could you post the hazel rule you are using now that does not work? What happens exactly? it fails to activate or...?
dhy8386
 
Posts: 94
Joined: Tue Nov 09, 2010 12:19 pm

It's perfectly fine to ignore the file argument that is passed in. It's not like you HAVE to use it.

That said, more details are needed. Is that script embedded in the rule or in a separate file. If the latter, you should check the help on how to do that properly.

Also, you can't do "display dialog" since this is being invoked from a GUI-less process. In the very least, you should do a 'tell application "System Events"' to do anything requiring a user interface.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I've tried both embedded as well as a separate file. Following is one of the Hazel rules that I'm using that I wish to have activate an AppleScript:

If ANY of the following conditions are met:
CONTENTS CONTAIN Acct Number XXXXXX
CONTENTS CONTAIN XXXXXX

Do the following:
RENAME FILE with pattern: DATE CREATED-AT&T Payment
MOVE FILE to folder: AT&T
REVEAL IN FINDER
OPEN FILE with application DEFAULT APPLICATION
RUN APPLESCRIPT ATT-PaymentMade.scpt

The script works just fine if activated outside of Hazel. I will try the "System Events" option when I get more time. Perhaps that is the hangup?
Thanks!
Bulldogarf
 
Posts: 3
Joined: Thu Nov 18, 2010 2:27 pm

RE: what happens exactly?

The rule does everything that it is programmed to do except run the AppleScript. It renames the file, moves it to another folder and the shows the file in the Finder.
Bulldogarf
 
Posts: 3
Joined: Thu Nov 18, 2010 2:27 pm


Return to Open Discussion