Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Creating iCal event Cannot convert date to number .. ??

:'Hey All,


I am trying to make appointments with an email alarm to go to multiple recipients.


The error I keep getting is


"Can’t make "12-08-13" into type number."

And help for any other mistakes you may see would be helpful too.

Thanks



##Get the Date

set theDate to short date string of (current date)

set theCal to "Home" as text


display dialog "Enter event date:" default answer (theDate as text) ¬

buttons {"Cancel Apt", "Make Apt"} ¬

default button 2

set aptDate to text returned of the result



##Get the email list

set emailList to ""

set emailList to text returned of (display dialog "List the eMail's of Presentation participants" default answer "example@me.com, example2@me.com")


##Make the ical event

tell application "iCal"

set eventName to ("Presentation for " & emailList) as text

set alarmTime to (aptDate as number) * -1

set newEvent to make new event at end of events of calendar theCal with properties {description:"Event Description", summary:eventName, location:"Event Location", start date:aptDate, allday event:true, trigger interval:alarmTime}

set theAlarm to make new mail alarm at end of mail alarms of newEvent with properties {visible:true, recipient:emailList, subject:"Presentation Info", content:"eMail body"}

end tell

end run

Applescript-OTHER, Mac OS X (10.7.4)

Posted on Aug 13, 2012 7:58 AM

Reply
17 replies

Aug 13, 2012 9:59 AM in response to b3nnb

Not sure to perfectly understand what you are trying to do. Have a look at iCal's AppleScript dictionary. An event object has no “trigger interval” property. Such a property (a number of minutes) belongs to the “mail alarm” object, which also has a “trigger date” (date) property, but no other property.


Here's a slightly modified version of your script that you could use as as starting point:



##Get the Date

set shortDateString to short date string of (current date)

set theCal to "Home" -- no need to add “as text”


display dialog "Enter event date:" default answershortDateString ¬

buttons {"Cancel Apt", "Make Apt"} ¬

default button 2

set aptDate to date (text returned of the result) -- since you want a date, not a text string


##Get the email list

set emailList to text returned of (display dialog "List the eMail's of Presentation participants" default answer "example@me.com, example2@me.com") as list -- a list of email addresses


##Make the ical event

tell application "Calendar"

set eventName to ("Presentation for " & emailList)

set newEvent to make new event at end of events of calendar theCal with properties {description:"Event Description", summary:eventName, location:"Event Location", start date:aptDate, allday event:true}

repeat with k from 1 to (count emailList)

makenewattendeeat end of attendees of newEventwith properties {email:itemk of emailList}

end repeat

end tell

Hope it can help.

Aug 13, 2012 10:38 AM in response to b3nnb

Btw, in order for the “Cancel Apt” button in your first “display dialog” statement to actually cancel the execution of the script, that statement should be modified as follows:


set theResult to display dialog "Enter event date:" default answer shortDateString ¬

buttons {"Cancel Apt", "Make Apt"} ¬

default button 2

if button returned of theResult is "Cancel Apt" then return

set aptDate to date (text returned of theResult) -- since you want a date, not a text string

Aug 13, 2012 11:33 AM in response to b3nnb

b3nnb wrote:


Hey, that looks awesome thanks.

im still stuck getting a similar issue to before this current one that reads.


iCal got an error: Can’t get calendar "Home"


Is there some stipulation to calendar types or names that it can connect with?


A calendar named "Home" must already exist in iCal before you can use it in AppleScript. You can create such a calendar either manually or with the following code:


tell application "Calendar"

makenewcalendarwith properties {name:"Home"}

end tell

Aug 13, 2012 12:45 PM in response to b3nnb

b3nnb wrote:


Im baiscally trying to setup an ical appointment with a email alert to all the emails involved. and have it email them the day before the appointment with a templated email.


I don't think you can set an email alert, either manually or using AppleScript, with any other email address than one of your owns.


From Calendar's Help:

User uploaded file.

Aug 13, 2012 1:18 PM in response to Pierre L.

I know that is a limitation to the built in features of iCal.

I didnt think it would completely limit the recipients the same.

i guess i could make 2 scripts one to make the appointment and have it run an applscript as an alert to send an email.


Is there a way to make the emailList in the notes and then the alert script to read from the notes section?

to get the emails to send

Aug 13, 2012 6:54 PM in response to b3nnb

i guess i could make 2 scripts one to make the appointment and have it run an applscript as an alert to send an email.


Maybe you might want to try the following solution.


1. Save the first script below as an application on the Desktop under the name "Send emails.app".

2. Launch the second script from the AppleScript Editor window.


FIRST SCRIPT


## Get the email list from the temporary text file

set thePath to (((path to desktop) as text) & "temporary.txt")

set N to open for accessthePath-- N is just a reference number

set emailList to read N as list

close accessN

tell application "Finder" to deletefilethePath


## Send an email to each recipient

tell application "Mail"

activate

set newMessage to makenewoutgoing messagewith properties ¬

{visible:true, subject:"Presentation Info", content:"eMail body"}

tell newMessage

repeat with k from 1 to (count emailList)

makenewto recipientat end of to recipientswith properties ¬

{address:item k of emailList}

end repeat

send

end tell

end tell

SECOND SCRIPT


set theCal to "Home"

set thePosixPath to POSIX path of (((path to desktop) as text) & "Send emails.app")


## Get the event date

set shortDateString to short date string of (current date)

set theResult to display dialog "Enter event date:" default answer shortDateString ¬

buttons {"Cancel Apt", "Make Apt"} ¬

default button 2

if button returned of theResult is "Cancel Apt" then return

set eventDate to date (text returned of theResult)


## Get the email list

set emailList to text returned of (display dialog "List the eMail's of Presentation participants" default answer "example@me.com, example2@me.com") as list


## Save the email list into a temporary text file

set thePath to (((path to desktop) as text) & "temporary.txt")

set N to open for accessthePath with write permission

writeemailListtoN

close accessN


## Make the iCal event

tell application "Calendar"

activate

set eventName to ("Presentation for " & emailList)

set newEvent to make new event at end of events of calendar theCal with properties {description:"Event Description", summary:eventName, location:"Event Location", start date:eventDate, allday event:true}

tell newEvent to makenewopen file alarmat end of open file alarmswith properties {trigger date:eventDate - 1 * days, filepath:thePosixPath}

end tell

Aug 13, 2012 7:48 PM in response to Pierre L.

I was already headed that way 🙂 Thanks for the effort to this point!!


2 small questions. when i do

set shortDateString to short date string of (current date) -- the date swaps the month and year

bit if i do

set shortDateString to date string of (current date) -- its the extended date but gets formatted properly



How are you copying the text from applescript editor and keeping the formatting style and color?

Creating iCal event Cannot convert date to number .. ??

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.