• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: create duplicate event in iCal
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: create duplicate event in iCal


  • Subject: Re: create duplicate event in iCal
  • From: Geoff Graham <email@hidden>
  • Date: Fri, 14 Nov 2008 12:27:02 -0500

On Oct 25, 2008, at 8:50 AM, Nigel Garvey wrote:

According to iCal's dictionary, its 'duplicate' command requires a
destination parameter, but I'm getting same result as you even when
specifying the end of the original calendar as such. The most reliable
solution seems to be to create each event from scratch:

I haven't posted in months. But I discovered something last night that seems little bit magic to me, and I have to share it.


Yes, everyone creates events from scratch, then populates the properties, which is a royal PITA to me. Recurrence, attendees, and attachments are among the things that I'm just too lazy to code for. So I started playing with the "duplicate" command.

I have a calendar, which I am subscribing to via WebDAV/CalDAV. iCal will read/write this calendar in version 3, but Mobile Me will not pick it up to send to the iPhone since the calendar does not live on my machine. So the solution is to duplicate the calendar on my local machine and sync that. Can't duplicate the whole calendar, but you can duplicate events. I want to constantly duplicate the real calendar to this shadow calendar so updates will filter to the iPhone. I need a timestamp to keep up with the last sync, and I like config files, so this is the script I came up with:

on idle {}
	set mypath to (((path to documents folder) as string) & "caldata.tab")
	set s to open for access file mypath with write permission
	set config to (read s before return using delimiter tab)
	set cal1 to (item 1 of config)
	set cal2 to (item 2 of config)
	set lastsync to date (item 3 of config)
	set t to ((current date) as string)
	tell application "iCal"
		set incal to a reference to events of calendar cal1 as list
		repeat with i in incal
			set thissync to stamp date of i
			if thissync is greater than lastsync then
				duplicate i to end of events of calendar cal2
			end if
		end repeat
		EofMe(s) of me
		WriteMe(cal1 & tab & cal2 & tab & t & return, s) of me
	end tell
	close access s
	return 300
end idle

on WriteMe(what, spec)
	write what to spec
end WriteMe

on EofMe(spec)
	set eof of spec to 0
end EofMe


The config file ("caldata.tab") has the following tab-delimited content:

Events	Events2	Friday, November 14, 2008 12:20:09 PM


The script iterates thru the events of the real calendar, and if the modified stamp is greater than the last run, it duplicates that event to the shadow calendar. It checks for new/updated events every 5 minutes as written. BTW, it is pretty fast; much faster than building events and populating them. The file writing handlers are necessary because iCal chokes on the read/write syntax, and I hate to call the Finder just to read and write files.


The shadow calendar is for all intents and purposes read-only; changes will not be pushed back to the real calendar. This is desired behavior (for now) as 3 people are already updating the served calendar, and any rescheduling on my part will necessitate a phone call/email to the secretary anyway, at which point she can make schedule changes which will be pushed to my iPhone.

The magic part: iCal remembers that the event in the shadow calendar was duplicated from the real calendar. So later, when a real event is updated and then is to be duplicated again to the shadow calendar, it doesn't stupidly duplicate a new event to the shadow calendar; it intelligently moves and updates the original duplicated event in the shadow calendar. A very nice surprise for me, and I bet for some others too.

Geoff
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: create duplicate event in iCal
      • From: Geoff Graham <email@hidden>
  • Prev by Date: Re: Maths Calculation Problem
  • Next by Date: Re: Maths Calculation Problem
  • Previous by thread: Fwd: Maths Calculation Problem
  • Next by thread: Re: create duplicate event in iCal
  • Index(es):
    • Date
    • Thread