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


Click here to return to the 'Script to copy iCal2 calendars to the old iCal locations' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Script to copy iCal2 calendars to the old iCal locations
Authored by: dhirsch226 on Jun 22, '05 11:57:41AM

(I submitted this as a hint, but the python script hint was ahead of mine. These do not do exactly the same thing. My script will copy the iCal2 .ics files to ~/Library/Calendars on the same machine, optionally omitting calendars to which you've subscribed. It doesn't upload anything. It will erase anything in ~/Library/Calendars first, so by putting this script in a cron job, you can keep a set of perfect duplicates in the old location. Here's my hint:)

I had created some scripts to copy my .ics files from ~/Library/Calendars to a spot where PHP iCalendar could serve them up.

With Tiger and iCal2's hierarchical calendars, this broke and was not easily fixed. The calendar files now live in ~/Library/Application Support/iCal/[inscrutable folder name here]/Sources/corestorage.ics. Ugh. Anyway, I made a script to copy figure out the names of the calendars from the associates Info.plist files, and copy them to the old location with the correct names. There is a setting to optionally omit subscribed calendars from being copied.

Note that this script will delete anything currently in ~/Library/Calendars (so you can put it in a cron job, and keep the calendars updated). You will also, of course, lose your iCal2 hierarchies. Here's the script. I named it iCalCopier.command, so that I can double-click it if needed. You will also want to chmod +x it to make it executable.

#!/bin/bash

# iCalCopier 1.2
# by Dave Hirsch, 6/5/05
# This script will copy each iCal2 .ics file into the old iCal location, so that
# other scripts which expect to find the calendar files there will work.
#
# It also renames the files to reflect the calendar names.  Note that it does not preserve the
# iCal2 hierarchies!  Also note that it will delete the contents of ~/Library/Calendars when it
# first runs.
#
# To use this script, put it someplace you can get to, then make it executable 
# (chmod +x iCalCopier2.command)

# The script optionally omits copying of subscribed calendars.  Change the following line to
# determine this behavior
omitSubscribed=true




myUserName=`whoami`
ICAL2DIRECTORY="/Users/$myUserName/Library/Application Support/iCal/Sources"

# Create the destination directory if it doesn't exist
ICAL1DIRECTORY="/Users/$myUserName/Library/Calendars"
if [ ! -d "$ICAL1DIRECTORY" ]              # Test whether calendar directory exists,
then                                 
  mkdir $ICAL1DIRECTORY                           # and make it if it doesn't exist
else
  rm -f $ICAL1DIRECTORY/* > /dev/null             #  If it does exist, clean it out quietly.
fi

for CALDIR in `ls "$ICAL2DIRECTORY"`
do
        if [ -d "$ICAL2DIRECTORY/$CALDIR" ]     # If the item is a directory (exclude .DS_Store files)
        then
          CALFILE="$ICAL2DIRECTORY/$CALDIR/Info.plist"

              # This next line does the heavy lifting of getting the Calendar title out of the
              # Info.plist file.  It looks for a line containing the text "Title", then
             # sets the AWK field separators to be both "", and then prints out field
              # 3 from the following line.
          Title=`cat "$CALFILE" | awk '/Title/ { FS = "[]"; getline; print $3 }'`

              # Check the type field to see if the current calendar is one that comes from
          # a subscription
              TypeStr=`cat "$CALFILE" | awk '/Type/ { FS = "[]"; getline; print $3 }'`
            if [ "$TypeStr" == "com.apple.ical.sources.urlsubscribesource" ]
          then
                  Subscribed=true
               else
                  Subscribed=false
              fi

              if !($omitSubscribed && $Subscribed)
          then
                  # If the calendar is not a subscribed calendar or if we don't care
                   # whether it's subscribed or not
                     cp "$ICAL2DIRECTORY/$CALDIR/corestorage.ics" "$ICAL1DIRECTORY/$Title.ics"
             fi
    fi
done

exit


[ Reply to This | # ]
Script to copy iCal2 calendars to the old iCal locations
Authored by: dhirsch226 on Jun 22, '05 12:03:32PM

Also, if you're running phpiCalendar on your own server, you might choose to change the value of the ICAL2DIRECTORY variable to the server directory you want phpiCalendar to find the calendar files in.
-Dave



[ Reply to This | # ]