Can ical check if event exist?

I have this script:


set nome to "Calendar?"
set da to "Date?"
set ta to "Time?"
set nome to text returned of (display dialog "Nome Cliente" default answer (get nome as string))

set da to text returned of (display dialog "Data Attivazione Card (gg/mm/aaaa)" default answer (get da as string))
set ta to text returned of (display dialog "Orario (hh:mm:ss)" default answer (get ta as string))
set data_attivazione to date (da & "," & ta)

tell application "iCal"
	set calendario to (make new calendar)
	set name of calendario to nome
	tell calendar nome
		make new event at end of events with properties {summary:"Attivazione Card", start date:data_attivazione, end date:(data_attivazione) + 60}
	end tell
end tell

I want the applescript checks if the new event doesn’t exist at same time.
If exists at same time it makes the new event at 1 minute later (+60)
Thank’s

Hi,

in qualche modo l’ho saputo che tu sia italiano ;):wink:

I’ve added a handler which checks the start dates of all events of every calendar
and increments the start time of the entered data by one minute if any date matches.
You should also add an error routine to trap all typing or date format faults

set nome to "Calendar?"
set da to "Date?"
set ta to "Time?"
set nome to text returned of (display dialog "Nome Cliente" default answer (get nome as string))

set da to text returned of (display dialog "Data Attivazione Card (gg/mm/aaaa)" default answer (get da as string))
set ta to text returned of (display dialog "Orario (hh:mm:ss)" default answer (get ta as string))
set data_attivazione to date (da & "," & ta)

tell application "iCal" to set allEventsStartDate to start date of events of calendars

repeat
	if event_available(data_attivazione, allEventsStartDate) then exit repeat
	set data_attivazione to data_attivazione + 60
end repeat

tell application "iCal"
	set calendario to (make new calendar)
	set name of calendario to nome
	tell calendar nome
		make new event at end of events with properties {summary:"Attivazione Card", start date:data_attivazione, end date:(data_attivazione) + 60}
	end tell
end tell

on event_available(theDate, allDates)
	repeat with i in allDates
		if theDate is in i then return false
	end repeat
	return true
end event_available

Hi Stefan…Exellent! My friend!!! :smiley: !!!
And for add an error routine to trap all typing or date format faults?!? :confused:
I want put set da to now…but isn’t correct format… :confused:

I have visit your website… very interesting…
…can I contact you in private if you undestand Italian language?..

…it is easier to understand the Italian Langiage that my English!!! :lol:

It’s quite complex to check every digit, a simple error handler is

...
repeat
	set da to text returned of (display dialog "Data Attivazione Card (gg/mm/aaaa)" default answer (get da as string))
	set ta to text returned of (display dialog "Orario (hh:mm:ss)" default answer (get ta as string))
	try
		set data_attivazione to date (da & "," & ta)
		exit repeat
	on error
		display dialog "Wrong format. Try it again"
	end try
end repeat
...

Thanks, I wish, my italian were half as good as my english,
and I guess, your english is better than my italian :lol:
My native language is german :slight_smile:

But go ahead, if you like, you find my iChat nickname in my profile