Reputation: 51
I use iCal to kept track of my shifts, the event info is the same three standard shift types and I usually copy and paste them as there's no pattern.
I'm trying to work out if theres away using Applescript to speed it up. I'd like to input some dates and shift type have Applescript create the events.
I tried to see if I could adapt this for each shift type:
Reading iCal info from file to make iCal event
eg so I just had a list of dates but I couldn't even get the original to run with out getting an invalid date error.
Upvotes: 0
Views: 7712
Reputation: 19030
Here's one way. Note I'm on Mountain Lion so the app is Calendar, not iCal... but the commands are the same if you're using iCal. Most likely your date error is because your dates have to be in applescript date format. Notice here that I take the start and end dates, which are initially in string format, and convert them to applescript dates before I add the event to Calendar.
set calendarName to "Home"
set theSummary to "Event Title"
set theDescrption to "The notes for the event"
set theLocation to "Karl's House"
set startDate to "July 4, 2013 6:30:00 PM"
set endDate to "July 5, 2013 1:00:00 AM"
set startDate to date startDate
set endDate to date endDate
tell application "Calendar"
tell (first calendar whose name is calendarName)
make new event at end of events with properties {summary:theSummary, start date:startDate, end date:endDate, description:theDescrption, location:theLocation}
end tell
end tell
Upvotes: 2
Reputation: 27613
You can create a date object with something like date "7/4/2013 6:00 PM"
, but the recognized formats depend on the region or date formats selected in System Preferences.
set input to "7/4 night
7/5 day"
set y to year of (current date)
set text item delimiters to " "
repeat with l in paragraphs of input
set d to text item 1 of l
set type to text item 2 of l
if type is "night" then
set sd to date (d & "/" & y & " 5:00 PM")
set ed to date (d & "/" & y & " 11:00 PM")
else if type is "day" then
set sd to date (d & "/" & y & " 9:00 AM")
set ed to date (d & "/" & y & " 5:00 PM")
end if
tell application "Calendar" to tell calendar "test"
make new event with properties {start date:sd, end date:ed, summary:"work"}
end tell
end repeat
Upvotes: 0