I'm trying to create an auto-responder that will respond to any email from a certain address with something like:
Thank you for your email.
Your number is #0000042.
The number should increment every time it sends one of these emails.
After looking online at the expensive solutions it looks like my best bet is automating something with AppleScript – possibly saving the last number in a file and incrementing it.
What would such a script look like?
Best Answer
A simple way of implementing the auto incrementing would be to use an AppleScript property variable:
Property values are "remembered" between calls to your script. So, in your handler simply use:
However, the property value is reset whenever the AppleScript is compiled. So you would need to manually change the
1
inproperty responseNumber : 1
to the latest value when you changed the script. Using a file is therefore a more robust method and using a preference file to record the current property value means you can use built-in functionality.A basic AppleScript example (with no error checks nor testing, since I don't use Mail), to give you an idea:
Save this script in your
~/Library/Application Scripts/com.apple.mail
folder and set-up a Mail rule to call it.You'll also need to create the appropriate plist file in your
~/Library/Preferences
folder with the following contents: