I am working on making a script which will allow me to print out yearly event schedules for our dj’s in html table format. I searched high and low for a way to do this inside of iCal, with no luck I am left to applescript. So far i have this…
---Script Variables
set printDays to 2000
set yearlist to {}
set myStart to date (date string of (current date))
set endofthisyear to date ("12/31/" & (year of (current date)))
set myEnd to date "Wednesday, December 31, 2008 12:00:00 AM"
--Design Variables
set thecontent to ""
tell application "iCal"
--Get List Of Calendars
set callist to title of every calendar
--Prompt User With Calendar Choice
set thecalendarname to choose from list callist
--Get the selected calendar
set thecalendar to (first calendar whose title is ((thecalendarname) as text))
--Get the qualifying range of events (defined by 'print days')
set myEvents to (events of thecalendar whose start date is greater than or equal to myStart and start date is less than or equal to myEnd)
--Get a list of what years events occur in by going through each event
repeat with myEvent in myEvents
set eventyear to (year of ((start date of myEvent) as date) as text)
if eventyear is in yearlist then
else
set yearlist to yearlist & eventyear
end if
end repeat
--Creating Tables for each year
repeat with theyear in yearlist
set thecontent to thecontent & return & thecalendarname & "'s " & theyear & " schedule" & return & return
--Add events from this year
repeat with myEvent in myEvents
set eventyear to (year of ((start date of myEvent) as date) as number)
if ((eventyear) as text) is ((theyear) as text) then
set eventdate to start date of myEvent
set eventsmonth to month of (eventdate)
set eventsday to day of (eventdate)
set eventsstart to time string of (eventdate)
set eventslocation to location of myEvent
set eventtitle to summary of myEvent
set thecontent to thecontent & eventsmonth & space & eventsday & eventyear & ", " & eventsstart & ": " & eventtitle & return
end if
end repeat
end repeat
display dialog "Good to go!!"
end tell
set the clipboard to thecontent
Right now, I am not focusing on the HTML part, I am copying the results into textedit to make sure the code end works fine, and it does. Only thing is, all the events are out of order, somewhat. You can test that script and it should work. I am wondering what it would take to get the events into sequential order. Any help is greatly appreciated.
I may not understand what your wanting to do, but why not
Create your calendar
Publish the calendar online from iCal’s “Calendar” menu
Print the webpage the calendar is in or download the html once they build a calendar for you!
SC
No scripting involved!
When you publish an iCal document (.ics) it just uploads the calendar file to the webdav or .Mac server you specify, this file cannot be viewed in Safari, but you subscribe to that calendar from iCal on another computer. What I needed was a simple way to print off an entire calendar in list format by the year. That first guy figured it out, I still don’t understand his section of code but it works like a charm. iCal has such limited print abilities, and I know a lot of other people have been dying to find a simple way to print off years schedules (Like for bands, or DJ’s) in table format. It now saves them as html files and opens them with safari
And if anyone interested, heres my working beta…
set calsavepath to "Macintosh HD:Users:teresadorsey:Desktop:Printable Calendars:"
set altcolor1 to "#FFFFFF"
set altcolor2 to "#CCCCCC"
set bgcolor to "#FFFFFF"
set headingbgcolor to "#333333"
set alternatebg to true
set myStart to date (date string of (current date))
set myEnd to date "Wednesday, December 31, 2008 12:00:00 AM"
set htmlheader to "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<title>Schedule</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<style type=\"text/css\">
<!--
.style1 {
font-size: 18px;
font-weight: bold;
color: #FFFFFF;
}
-->
</style>
</head>
<body>"
set htmltables to ""
set htmlfooter to "</table><br><br>
<h6>" & (current date) & "</h6>
</body>
</html>
"
tell application "iCal"
--Get List Of Calendars
set callist to title of every calendar
--Prompt User With Calendar Choice
set thecalendarname to choose from list callist
--Get the selected calendar
set thecalendar to (first calendar whose title is ((thecalendarname) as text))
--Get the qualifying range of events (defined by 'print days')
set myEvents_To_sort to (events of thecalendar whose start date ≥ myStart and start date ≤ myEnd)
set index_list to {}
set myEvents to {}
set Nbr_events to (count of myEvents_To_sort)
repeat Nbr_events times
set low_item to ""
repeat with i from 1 to Nbr_events
if i is not in the index_list then
set this_item to start date of item i of myEvents_To_sort
if low_item is "" then
set low_item to this_item
set low_item_index to i
else if this_item ≤ low_item then
set low_item to this_item
set low_item_index to i
end if
end if
end repeat
set the end of myEvents to item low_item_index of myEvents_To_sort
set the end of index_list to low_item_index
end repeat
set The_year to 0
repeat with myEvent in myEvents
set eventyear to (year of ((start date of myEvent) as date) as number)
if eventyear > The_year then
set htmltables to htmltables & "</table> <table width=\"655\" border=\"0\">
<tr bgcolor=\"" & headingbgcolor & "\">
<td colspan=\"5\"><div align=\"center\" class=\"style1\">" & thecalendarname & "'s " & eventyear & " Schedule</div></td>
</tr>
<tr>
<td width=\"100\"><div align=\"center\"><strong>Date</strong></div></td>
<td width=\"150\"><div align=\"center\"><strong>Time</strong></div></td>
<td width=\"219\"><div align=\"center\"><strong>Location</strong></div></td>
<td width=\"179\"><div align=\"center\"><strong>Event</strong></div></td>
<td width=\"5\"><div align=\"center\"></div></td>
</tr>"
set The_year to eventyear
set changecolornow to false
end if
set eventdate to start date of myEvent
set eventenddate to end date of myEvent
set eventsmonth to month of (eventdate)
set eventsday to day of (eventdate)
set eventsstart to time string of (eventdate) as text
set eventsend to time string of (eventenddate) as text
if location of myEvent exists then
set eventslocation to location of myEvent
else
set eventslocation to "Unknown"
end if
set eventtitle to summary of myEvent
set shorteventstarttime to (characters 1 through ((count of characters of eventsstart) - 6) of eventsstart) & (characters ((count of characters of eventsstart) - 1) through ((count of characters of eventsstart)) of eventsstart)
set shorteventendtime to (characters 1 through ((count of characters of eventsend) - 6) of eventsend) & (characters ((count of characters of eventsend) - 1) through ((count of characters of eventsend)) of eventsend)
if (shorteventendtime as text) is "12:00AM" then
set shorteventendtime to "Mid"
--Alternate Background Color Code
end if
if alternatebg is true then
if changecolornow is true then
set bgcolor to altcolor1
set changecolornow to false
else
set bgcolor to altcolor2
set changecolornow to true
end if
end if
set htmltables to htmltables & " <tr bgcolor=\"" & bgcolor & "\">
<td><div align=\"left\">" & eventsmonth & space & eventsday & "</div></td>
<td><div align=\"center\">" & shorteventstarttime & "-" & shorteventendtime & "</div></td>
<td><div align=\"center\">" & eventslocation & "</div></td>
<td><div align=\"center\"></div> " & eventtitle & "</td>
<td><div align=\"center\"></div></td>
</tr>"
end repeat
set fullhtml to htmlheader & htmltables & htmlfooter
end tell
set file_spec to (calsavepath & thecalendarname & ".html") as file specification
set ref_num to (open for access file_spec with write permission)
try
set eof of ref_num to 0
write fullhtml to ref_num starting at eof
close access ref_num
on error
close access ref_num
end try
tell application "Safari"
open file_spec
end tell