List locally published iCal calendars on a web page

Feb 23, '04 10:07:00AM

Contributed by: Anonymous

I've been fooling around with iCal and WebDAV on an OS X Server this weekend, and came up with an ACGI that generates a web page listing the currently-shared iCal calendars on the server. The person accessing the page can subscribe to a listed calendar simply by clicking the link instead of having to type in a URL.

It's a little rough, as I just got it working a short while ago-- but I figured I'd share it in case anyone else out there could use it. This hint also needs James Sentman's ACGI Dispatcher.

Read the rest of the hint for the code (it's a bit wide due to some non-breakable quoted HTML lines)...


on handle CGI request path_args ¬
  searching for http_search_args executing by the_link given «class TraL»:NewFormData
   
  set return_page to http_header ¬
  & "<html><head><title>Local Shared iCal Calendars</title></head>" & ¬
  "<body bgcolor=\"#ffffff\"><div align=\"center\">" & ¬
  "<p><font size=\"6\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">Shared Calendars<br>" & ¬
  "</font><font size=\"3\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">" & ¬
  "The following calendars are currently being published by their owners:</font></p><p></p>"
    
  tell application "Finder"
    --Change the below pathy to the folder that contains your shared calendars.
    set thecalendars to name of document files of folder "Server:Library:WebServer:calendars"
             
    --The routine below currently only handles alphanumeric characters and spaces in calendar names.
    repeat with calendar from 1 to count of thecalendars
      set replacestring to space
      set olddelims to AppleScript's text item delimiters
      set AppleScript's text item delimiters to "32"
      set scratchspace to text items of (item calendar of thecalendars)
      set AppleScript's text item delimiters to replacestring
      set propername to scratchspace as string
      set AppleScript's text item delimiters to olddelims
      set propername to characters 1 through ((offset of "." in propername) - 1) of propername as string
      --Change the URL below as needed for your particular server.
      set return_page to return_page & ¬
      "<p><a href=\"webcal://[WebDAV server IP here]/[WebDAV calendar directory here]" & item calendar of thecalendars & ¬
      "\">" & "<font face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\" size=\"4\">" & propername & "</font></a></p>"
    end repeat
  end tell
      
  set return_page to return_page & ¬
  "<p></p><p><font face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">Click on a name to subscribe to that particular iCal calendar.<br>" & ¬
  "</font></p></div></body></html>"
       
  return return_page
end handle CGI request
Save the script as an application with the "stay open" attribute, and place it in the web folder where published iCal calendars reside. I named mine index.acgi, and configured my web server to use it as the default page.

Comments (0)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040215023707770