Mac applescripting iCal

brandon.8602

macrumors member
Original poster
Jul 3, 2010
61
0
I would like creating an event to be a very simple process.
I have written this script and when I run it I get the error "iCal got an error: AppleEvent handler failed." The script seems sound, what am I doing wrong?

Code:
tell application "iCal"
	tell calendar "Home"
		display dialog "What is the name of the event?" default answer "Enter name here"
		set eventName to text returned of result
		display dialog "Describe this event" default answer "Enter description here"
		set eventDescription to text returned of result
		display dialog "Where is this event?" default answer "Enter location here"
		set eventLocation to text returned of result
		display dialog "What is the start date and time?" default answer "MM/DD/YY"
		set startDate to text returned of result
		display dialog "What is the end date and time?" default answer "MM/DD/YY"
		set endDate to text returned of result
		make new event at end with properties {description:eventDescription, summary:eventName, location:eventLocation, start date:startDate, end date:endDate, allday event:true}
	end tell
end tell
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
1
Dallas, TX
Code:
display dialog "What is the name of the event?" default answer "Enter name here"
set eventName to text returned of result
display dialog "Describe this event" default answer "Enter description here"
set eventDescription to text returned of result
display dialog "Where is this event?" default answer "Enter location here"
set eventLocation to text returned of result
display dialog "What is the start date and time?" default answer "MM/DD/YY"
set startDate to date (text returned of result)
display dialog "What is the end date and time?" default answer "MM/DD/YY"
set endDate to date (text returned of result)

tell application "iCal"
	tell calendar "Home"
		
		make new event at end with properties {description:eventDescription, summary:eventName, location:eventLocation, start date:(startDate), end date:(endDate), allday event:true}
	end tell
end tell
Seems to work for me.

-Lee
 

brandon.8602

macrumors member
Original poster
Jul 3, 2010
61
0
Code:
display dialog "What is the name of the event?" default answer "Enter name here"
set eventName to text returned of result
display dialog "Describe this event" default answer "Enter description here"
set eventDescription to text returned of result
display dialog "Where is this event?" default answer "Enter location here"
set eventLocation to text returned of result
display dialog "What is the start date and time?" default answer "MM/DD/YY"
set startDate to date (text returned of result)
display dialog "What is the end date and time?" default answer "MM/DD/YY"
set endDate to date (text returned of result)

tell application "iCal"
	tell calendar "Home"
		
		make new event at end with properties {description:eventDescription, summary:eventName, location:eventLocation, start date:(startDate), end date:(endDate), allday event:true}
	end tell
end tell
Seems to work for me.

-Lee
I tried it, even with it flipped around like you have it, and I am still getting the error. If it means anything the "make new event... event:true} end tell" portion is highlighted.
 

brandon.8602

macrumors member
Original poster
Jul 3, 2010
61
0
scratch that... i was just playing with it a little, and I think it must have something to do with my dates. I made a new variable "theDate" in place of startDate and endDate and set it as the current date. i put theDate variable in and deleted the startDate and endDate portions. It works... but I would like it to be custom dated.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
1
Dallas, TX
did you copy and paste what i posted, or just "flip around" what you had before? I also added "date" to the lines where it was getting the start date and end date.

-Lee
 

brandon.8602

macrumors member
Original poster
Jul 3, 2010
61
0
did you copy and paste what i posted, or just "flip around" what you had before? I also added "date" to the lines where it was getting the start date and end date.

-Lee
I just copied and pasted yours it works thanks :D
so where i went wrong was applescript not recognizing the input text as a date but rather a string?
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
1
Dallas, TX
I just copied and pasted yours it works thanks :D
so where i went wrong was applescript not recognizing the input text as a date but rather a string?
Yes. start date and end date had to be dates, and it had "text" or a "string". The 'date' keyword will turn a textual description of a date and return a date type.

-Lee
 

Similar threads

  • Aouttier
7
Replies
7
Views
587
  • Aouttier
5
Replies
5
Views
463
  • gpchess2k
6
Replies
6
Views
996
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.