Get rid of the try
…end try
enclosures. There are very few reasons in AppleScript to have to use try
blocks. They’re almost always used (inappropriately) in fragile scripts that potentially break under certain conditions, but where the author of the script was either too lazy or unable to discern the nature of the issue, or how to fix it. It actually ends up making scripts a lot more difficult to debug.
Rule of thumb: only use a try
block when you know exactly what error will arise, and under what conditions; and you are using the catch to allow the script to handle the error in a specific, meaningful way.
There are a couple of exceptions, but none worth mentioning here.
The specific problem with the script is in this section:
There’s a space omitted between the words end
and tell
. On a separate note, the line above it is wrong, as RemindersList
will never equal "false"
.
The last half of your script is problematic too: you haven’t define a variable called answers
, so that will throw an error (or it would if it wasn’t in a try
block). And your subsequent use of RemindersList
is not a valid reference for the list
specifier to use.
I’ve cleaned your script up a bit:
tell (current date) to set [midnight, time] to [it, 0]
set reminder_options to {"Tonight", "Tomorrow Night", "End of Week", ¬
"1 Week", "1 Month", "3 Months"}
set daysFromNow to {0, 1, 8 - (weekday of midnight), 7, 30, 90}
set reminder_name to the text returned of (display dialog ¬
"What would you like to be reminded about?" default answer "")
set reminder_note to "You need to process something"
set {reminder_date} to (choose from list reminder_options ¬
default items {"End of Week"} OK button name {"Create"} ¬
with prompt {"Set follow-up time"} ¬
with title {"Create Reminder"}) as list
if the reminder_date = false then return
repeat with i from 1 to the number of reminder_options
if the reminder_date = item i in the ¬
reminder_options then exit repeat
end repeat
set numDays to item i of daysFromNow
set reminder_date to midnight + numDays * days + 20 * hours
set reminder_list_name to "My Reminders" -- change this to any name you'd like for your list
tell application "Reminders"
set myList to a reference to list reminder_list_name
if not (myList exists) then make new list with properties ¬
{name:reminder_list_name}
tell myList to set reminder_id to make new reminder ¬
with properties {remind me date:reminder_date ¬
, name:reminder_name ¬
, body:reminder_note} --
end tell