I’m trying to get the location as text in an event that just triggered an alarm one minute after the event.
The alarm is set in ical and my script is as follows. I would like the text that is in the location blank of ical to be the variable thelocation. I have tried this several ways and still I get errors. Any advice?
t
ell application "iCal"
set theCalendar to the first calendar whose title is "Activities"
set theDateTime to current date
set theEvent to the last event of theCalendar whose start date is less than or equal to theDateTime and end date is greater than or equal to theDateTime
set theEvent to (last event of theCalendar)
set location of theEvent to thelocation
return thelocation
end tell
I have typed two ways to get the recently occurring event since the first one listed didn’t work but seems to be the more proper way to do it. Will I get possible errors with the second way?
tell (current date) to set ct to it - (its seconds)
tell application "iCal"
repeat with oneEvent in (get events of calendar "Activities" whose start date is (ct + 60))
if oneEvent is not missing value then return location
end repeat
end tell
Note: In your script you confused the direction of setting a variable.
These two forms are correct
Sorry I’m not getting it
In the script I submitted I am getting
and
in the event log in your script.
I tried using both
and
but I get the error “the variable theevent not defined”
The way your script is confuses me because I’m not sure what is in oneevent. Aren’t you returning the location and not oneevent.
tell (current date) to set ct to it - (its seconds)
tell application "iCal"
repeat with oneEvent in (get events of calendar "Activities" whose start date is (ct + 60))
if oneEvent is not missing value then return location
end repeat
copy location to thelocation
end tell
I tried this also but I get the error “iCal got an error: Can’t make location into type reference.”
which is what I’m trying to do but I don’t know how.
tell (current date) to set ct to it - (its seconds)
tell application "iCal"
repeat with oneEvent in (get events of calendar "Activities" whose start date is (ct + 60))
if oneEvent is not missing value then return location of oneEvent
end repeat
end tell
if the variable is empty (not defined) no matching event was found.
try (ct - 60), I was a bit confused with triggered an alarm one minute after the event
It may be that this script is a little hard to test. When I use the alarm on ical I’m assuming the script goes off without notice and not in the applescript editor pane. How can I get an event log to make sure it is working with such a test?
define an event with all parameters you want in iCal and start date e.g. 2/12/08 8:01 AM
-- tell (current date) to set ct to it - (its seconds)
set ct to date "2/12/08 8:00 AM" -- to match ct - 60
tell application "iCal"
repeat with oneEvent in (get events of calendar "Activities" whose start date is (ct - 60))
if oneEvent is not missing value then display dialog (get location of oneEvent)
end repeat
try
oneEvent -- throws error if not defined
on error
display dialog "not found"
end try
end tell
the seconds do matter, the dates must match exactly, but you can’t specify seconds defining an event.
Therefore the original script subtracts the seconds from the current time.
On my machine the script works with event = 7:59 am on 2-12-08
and ct = 8:00 am on 2-12-08