Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Create 'pre-alarmed' events in iCal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create 'pre-alarmed' events in iCal
Authored by: mark hunte on Jan 01, '06 06:32:29AM
As a request from matthewroth in a email, for me to submit a bit more of the applescscript I posted. I still had to take a small part out. But here it is.

set iCalendars to {}

set theCals to {}

tell application "iCal"
  set theCals to calendars whose writable is true
  repeat with i from 1 to count of theCals
    copy title of item i of theCals to end of iCalendars
  end repeat
end tell

tell application "Finder"
  
  display dialog "Enter Event Title " default answer "New Event"
  
  set theSummary to the text returned of the result
  display dialog "Enter Any Notes/Leave blank for None: " default answer ""
  
  set theDiscript to the text returned of the result
  
  set timestamp to current date
  set theday to (day of (current date)) as string
  
  
  set monthList to {January, February, March, April, May, June, July, August, September, October, November, December}
  repeat with i from 1 to 12
    if timestamp's month = item i of monthList then
      set theMonth to text -2 thru -1 of ("0" & i)
      exit repeat -- no point continuing once we have what we want
    end if
  end repeat
  
  set theyear to (year of (current date)) as string
  
  display dialog "Enter Date of the event: i.e  dd/mm/" & theyear default answer theday & "/" & theMonth & "/" & theyear
  
  set theSdate to the text returned of the result
  
  display dialog "Enter time of the event : (24 hour time)" default answer "12:00"
  
  set theTime to the text returned of the result
  
  display dialog "Enter ending time of event (24 hour time)" default answer "13:00"
  
  set theEtime to the text returned of the result
  
  display dialog "Number of Minutes or Hours before event to sound alarm(blank for no alarm): " default answer "1" buttons {"Minutes", "Hours", "Cancel"} default button 1
  copy the result as list to {theAlarmTime, button_pressed}
  
  
  set theChoice to choose from list iCalendars with prompt "Choose the Calendar to use" OK button name "Choose" without multiple selections allowed and empty selection allowed
  
  if theChoice is not false then
    set theCalChoice to item 1 of theChoice
  end if
  
  set theCalName to theCalChoice
  
  -- Run through our Calendar list and find the iCal id of the chosen Calendar
  
  set i to 1
  
  repeat with anitem in iCalendars
    if item i of iCalendars is equal to theCalName then
      set theNum to i
      exit repeat
    end if
    set i to i + 1
  end repeat
end tell

set currentCal to item theNum of theCals

set theDate to date theSdate

set theDate to date theTime of theDate

set endDate to date theSdate

set endDate to date theEtime of endDate


tell application "iCal"
  activate
  set theEvent to (make event at end of events of currentCal with properties {start date:theDate, end date:endDate, summary:theSummary, description:theDiscript & return & " : time-stamp :  " & timestamp})
  if theAlarmTime is not "" then
    if button_pressed is equal to "Hours" then
      set theAlarm to (theAlarmTime as integer) * -60
    end if
    if button_pressed is equal to "Minutes" then
      set theAlarm to (theAlarmTime as integer) * -60 / 60
    end if
    make new sound alarm at end of sound alarms of theEvent with properties {trigger interval:theAlarm}
    
    
  end if
  tell application "iCal"
    show theEvent
  end tell
end tell 

---
mh

[ Reply to This | # ]
Date conversion problems
Authored by: SeanAhern on Jan 02, '06 10:52:37AM

This script works for me, for the most part. The only problem is the parsing of dates. This might be affected by the "International" setting of the OS. When the date "3/1/2006" is parsed, I get March 1st, rather than the January 3rd I expected. I fixed up my copy of the script so that it prompts me the way I expect, but I think this is likely not a bug in the script. I'm guessing that the conversion of the string to a date is probably dependent on the user's settings, as I'm using U.S. formatting.



[ Reply to This | # ]
Date conversion problems
Authored by: mark hunte on Jan 02, '06 02:05:41PM
Yes I should have pointed that out I'm in the Uk so the format is the Uk style.

This should help.
Change

 display dialog "Enter Date of the event: i.e  dd/mm/" ¬
& theyear default answer theday & "/" & theMonth & "/" & theyear

to

 display dialog "Enter Date of the event: i.e  mm/dd/" ¬
& theyear default answer theMonth  & "/" & theday & "/" & theyear

---
mh

[ Reply to This | # ]

Date conversion problems
Authored by: osxpounder on Mar 07, '06 12:53:24PM
I'm trying to figure out how to modify this script, so that it gets the current time, adds a fixed number of minutes to it, and puts that in the dialog box as the default answer here:

display dialog "Enter time of the event : (24 hour time)" default answer XXXXX

... where the XXXXX would be replaced with whatever code can do the job. I'm thinking that it'd be helpful to set an iCal appointment for, say, a half-hour from now, and let the script figure out what time "now" is. Is it possible? I've searched the Dictionary, in Script Editor, for Finder, iCal, and System Events, but the search keyword "time turns up nothing that seems useful. I know almost nothing about AppleScript, so this might be obvious to some of you. I took a stab at it, but apparently "current time" doesn't work.

---
--
osxpounder

[ Reply to This | # ]

.03 icalfix released
Authored by: bcometa on Apr 09, '06 10:32:36PM

and works perfectly as far as i can tell... you can also set default alarm time and sound.



[ Reply to This | # ]