location as text in ical

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?

Hi,

try this


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

set thelocation to location of theEvent

or

copy location of theEvent to thelocation

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.

sorry, I missed the reference


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

This works without an error but how do I get the “location” field in the event as text into my variable “thelocation”?

set thelocation to location of oneEvent

gives an error the variable oneevent is not defined.
I’m not sure how to get the text out of the loop into my variable.

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?

I usually test these scripts this way:

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

I set my calendar event in the “Activities” calendar to 7:59 am on 2-12-08 and ran the script
This is the event log I got

It doesn’t seem to be finding the event.
Is there a problem with the seconds when I enter in ical?

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

My event that I was testing was a recurring event.
When I made a new event, it worked.
thanks