Missing Value

I’m pretty much a beginner to AppleScript and I’m positive this must have been discussed before, but how on earth do you deal with the missing value error?

I’m trying to get the trigger date from an alarm with this code:

set myTriggerDate to trigger date of item j of myAlarms (tis is in a repeat loop)

If there is no trigger date defined, this statement works, but any reference to myTriggerDate causes AppleScript to stop dead in it’s tracks with an error “myTriggerDate is not deifned”

I’ve tried “if trigger date ot item j of myAlarms = missing value then…” (still get an error) and putting the set within a try block with an error to set myTriggerDate to something else (the on error doesn;t happen because the set doesn;t throw an error).

So just how can you deal with this?

Pete

Hi Pete,

first of all you’re posting in the wrong forum.
The Code Exchange forum is actually to share completed scripts.
Please use the OS X forum to ask questions :slight_smile:

If the value of the alarm is empty, the variable myTriggerDate won’t be defined and recalling the variable throws an error
I recommend to catch the error and set the variable to a certain value like


tell application "iCal"
	tell myCalendar to set myTriggerDate to trigger date of open file alarm 1 of event 1
end tell
try
	myTriggerDate
on error
	set myTriggerDate to missing value
end try

Moved to appropriate forum

Stefan - thanks for the recommendation. I also subequently found out abou the exists test and am using that.

Adam, where did you move my post to? I don’t see it in the Code Exchange forum.

Adam has moved it to the OS X forum