Re: create duplicate event in iCal
Re: create duplicate event in iCal
- Subject: Re: create duplicate event in iCal
- From: Geoff Graham <email@hidden>
- Date: Thu, 20 Nov 2008 10:41:34 -0500
Hi all,
I posted recently on the magic of the duplicate command in iCal, and
how it remembers which event was duplicated thru the event UID. The
only weak point is when the original event is deleted. The duplicate
event briefly disappears from ical but then reappears, now of course,
disconnected from the original. I modified my script so that after all
the duplicated events are updated, it then goes thru the duplicates to
find any now missing from the original calendar and deletes them. It
has worked pretty good so far for about 3 days on 3 different macs. I
have it saved as a stay open application, in the user's startup items.
To recap: if you subscribe to a calendar, in this case using webdav/
caldav running on an IceWarp groupware server; that calendar won't be
picked up by Mobile Me to be wirelessly synced to your iPhone. My
solution was to create a "shadow calendar" on the local machine that
updates itself from the "live calendar", and this shadow calendar can
be picked up and synced by Mobile Me. This shadow calendar is
effectively read-only, as changes will not be pushed back up to the
live calendar; indeed they will be overwritten at the next sync
interval. I may at some point investigate two-way syncing, but that
will turn this simple script into a monster I think.
A warning: When one runs this script for the first time, you pick your
"Live" calendar and then your "Shadow" calendar. Choose wrong and
whatever events you had in the shadow will be quickly and efficiently
obliterated and replaced with events form the live one. It occurs to
me that perhaps I should have the script always create a new calendar
to avoid this possibility.
(the select handler has some long lines that I'm sure will wrap in
email...)
Anywho, enjoy:
geoff
-- begin script
property defaultPref : {"Live Calendar", "Shadow Calendar", "Tuesday,
January 1, 2008 12:00:00 AM"}
global logspec
on idle {}
try
if CheckPrefs() then
select {}
end if
set logspec to OpenLog()
try
read logspec
end try
set {cal1, cal2, lastsync} to ReadPrefs()
set d to ((current date) as string)
Logit("Begin")
Logit("Syncing from:" & lastsync as string)
set Cal1UIDs to {}
tell application "iCal"
set incal to a reference to events of calendar id cal1 as list
repeat with i in incal
set thesd to (stamp date of i)
set end of Cal1UIDs to (uid of i)
if thesd is greater than lastsync then
try
duplicate i to end of calendar id cal2
on error errmsg
Logit(errmsg & tab & (uid of i) & tab & (summary of i) & tab &
((start date of i) as string)) of me
end try
end if
end repeat
Logit("Purging") of me
set outcal to a reference to events of calendar id cal2 as list
repeat with i in outcal
set thisid to uid of i
if thisid is not in Cal1UIDs then
Logit("Deleted" & tab & cal2 & tab & thisid) of me
delete (every event of calendar id cal2 whose uid is thisid)
end if
end repeat
WritePrefs(cal1, cal2, d) of me
end tell
Logit("Finish")
close access logspec
on error errmsg
Logit(errmsg)
close access logspec
--quit of me
end try
return 300
end idle
on CheckPrefs()
set {cal1, cal2, lastsync} to ReadPrefs()
tell application "iCal" to set callist to uid of every calendar as list
if cal1 is in callist then
if cal2 is in callist then
return false
else
return true
end if
else
return true
end if
end CheckPrefs
on select {}
tell application "iCal"
set callist to name of every calendar as list
set calidlist to every calendar as list
repeat with i from 1 to (length of callist)
set item i of callist to ((item i of callist) & space & space & "•"
& (uid of (item i of calidlist)))
end repeat
end tell
display dialog ("Live Calendar: " & return & "Shadow Calendar: ")
with title "Calendar Sync Setup" with icon note buttons {"Cancel",
"Setup"} giving up after 30
set cal1 to item 1 of (choose from list callist with title "Calendar
1" with prompt "Pick the live Calendar to pull events from..." OK
button name "Live Calendar" default items (item 1 of defaultPref)
without empty selection allowed)
set cal2 to item 1 of (choose from list callist with title "Calendar
2" with prompt "Pick the shadow Calendar to push events into..." OK
button name "Shadow Calendar" default items (item 2 of defaultPref)
without empty selection allowed)
set cal1 to (text ((offset of "•" in cal1) + 1) thru (length of cal1)
in cal1)
set cal2 to (text ((offset of "•" in cal2) + 1) thru (length of cal2)
in cal2)
WritePrefs(cal1, cal2, (item 3 of defaultPref))
end select
on ReadPrefs()
try
set config to (read SpecPref() 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)
on error
set s to SpecPref()
EofMe(s) of me
WriteMe(item 1 of defaultPref, item 2 of defaultPref, item 3 of
defaultPref, s)
set config to (read s from 0 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)
end try
return {cal1, cal2, lastsync}
end ReadPrefs
on WritePrefs(cal1, cal2, ts)
set s to SpecPref()
EofMe(s) of me
WriteMe(cal1, cal2, ts, s) of me
close access s
end WritePrefs
on WriteMe(what1, what2, ts, spec)
write (what1 & tab & what2 & tab & ts & return) to spec
end WriteMe
on EofMe(spec)
set eof of spec to 0
end EofMe
on SpecPref()
set mypath to (((path to preferences folder) as string) &
"CalendarSyncer.pref")
try
return (open for access file mypath with write permission)
on error
try
close access file mypath
end try
return (open for access file mypath with write permission)
end try
end SpecPref
on OpenLog()
set lpath to (((path to documents folder) as string) &
"CalendarSyncer.txt")
try
return (open for access file lpath with write permission)
on error
try
close access file lpath
end try
return (open for access file lpath with write permission)
end try
end OpenLog
on Logit(someinfo)
write ((current date) as string) & tab & someinfo & return to logspec
end Logit
-- end script _______________________________________________
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