applescripting iCal

Discussion in 'Mac Programming' started by brandon.8602, Aug 3, 2010.

  1. brandon.8602 macrumors member

    Joined:
    Jul 3, 2010
    #1
    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
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. brandon.8602 thread starter macrumors member

    Joined:
    Jul 3, 2010
    #3
    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.
     
  4. brandon.8602 thread starter macrumors member

    Joined:
    Jul 3, 2010
    #4
    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.
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    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
     
  6. brandon.8602 thread starter macrumors member

    Joined:
    Jul 3, 2010
    #6
    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?
     
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    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
     

Share This Page