Help, Help, I need some Help (ical event creation)

First of all, thank you to all of you on this forum. I’ve been trying to put together a script that will allow me to set the days I worked (or will be working) as well as the shift and then put the whole thing into an ical event. Although I suspect it’s a simple script, it has given me fits, especially the whole date thing. I’ve only managed to get it to where I have with the help of this board. So thanks a bunch.

At any rate, I’m finally stuck. I’ve got everything exactly how I want it except for excluding certain days from the final ical event. For instance, suppose I worked from 8:00 am to 4:00 pm, Sun. - Tue., was off Wed. and Thur. and then finished out the week (Fri. & Sat.). I can make everything work, but I can’t seem to figure out how to exclude Wed. and Thur. from the event.

Rather than throw in my whole script, here is a slightly modified version that pertains to this problem.

set Sdate to (current date)
set Edate to Sdate + (13 * days)
set Xdate1 to Sdate + (2 * days) 
set Xdate2 to Sdate + (3 * days) 
set xdates to Xdate1 & Xdate2

tell application "iCal"
	set Work_Cal to (the first calendar whose title is "public")
	tell Work_Cal
		make new event at the end of events of Work_Cal with properties {summary:"test", start date:Sdate, end date:Edate, excluded dates:xdates}
	end tell
end tell

Any help you can toss my way is greatly appreciate.

ahenry:

Glad to hear that MacScripter is helping you out. I am no great iCal scripter, but this script will do what you ask:

set Sdate to (current date) --Only works when run on a Sunday
set Xdate1 to Sdate + (3 * days) --Creates the next Wednesday
set Xdate2 to Sdate + (4 * days) --Creates the next Thursday
set xdates to {Xdate1, (Xdate1 + (7 * days)), Xdate2, (Xdate2 + (7 * days))} --Creates the list of excluded dates, including the Wed/Thur of the second week
tell application "iCal"
	tell calendar "public"
		make new event at end of events with properties {allday event:true, summary:"Test", start date:Sdate, recurrence:"FREQ=DAILY;COUNT=14", excluded dates:xdates}
	end tell
end tell

It seems that the only way one can use the property excluded dates is in conjunction with the RFC 2445 iCalendar recurrence string data. For more exciting reading on that fun topic, check out this link. You can see in the script above that we give the event a start date (today), and then instruct iCal that it recurs daily for 14 days (recurrence:“FREQ=DAILY;COUNT=14”) and then we give it a list of excluded dates to ignore.

I hope this helps. I also believe this can be improved upon, so don’t be shy about asking for more assistance or clarifying your needs.

Hi,

the recurrence string for all days except Wed and Thu is

"FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,FR,SA,SU;WKST=MO"

That did exactly what I needed it to…

…but with excluded dates working as a function of recurrence, I’ve got to modify my script some. :expressionless: Hmm, I guess that’s how it goes. Still, that solved my problem. Thanks a bunch!

I’ve got everything on this script done (thanks for the help again), but I can’t seem to leave well enough alone so I keep finding myself trying to improve the script. So for this portion of my script:
(ADOD1 and ADOD2 are items of a list that are user selected from a list of days of the week; day1 - day7 are dates (in “Sunday, April 1, 2007 12:00:00 AM” format)


if ADOD1 = "sunday" then
	set Xdate1 to day1
else
	if ADOD1 = "monday" then
		set Xdate1 to day2
	else
		if ADOD1 = "tuesday" then
			set Xdate1 to day3
		else
			if ADOD1 = "wednesday" then
				set Xdate1 to day4
			else
				if ADOD1 = "thursday" then
					set Xdate1 to day5
				else
					if ADOD1 = "friday" then
						set Xdate1 to day6
					else
						set Xdate1 to day7
					end if
				end if
			end if
		end if
	end if
end if
if ADOD2 = "sunday" then
	set Xdate2 to day1
else
	if ADOD2 = "monday" then
		set Xdate2 to day2
	else
		if ADOD2 = "tuesday" then
			set Xdate2 to day3
		else
			if ADOD2 = "wednesday" then
				set Xdate2 to day4
			else
				if ADOD2 = "thursday" then
					set Xdate2 to day5
				else
					if ADOD2 = "friday" then
						set Xdate2 to day6
					else
						set Xdate2 to day7
					end if
				end if
			end if
		end if
	end if
end if

There has got to be a way to do all that in a more simple way. I’d like to have a handler do this as well, since I ultimately need to do this form of operation 4 times.

My thinking is to have a list of the variables day1 - day7 (and actually go through day 14 - lets call it day_list), and compare the specific day of each item of that list to one of the items from the user selected lists (ADOD1 and ADOD2 - call it ADOD_list).

I thought this would be simple but I somehow can’t seem to manage to extract a specific item of ADOD_list and compare it to the specific day of each item in day_list). There has to be a way, but so far I haven’t been able to figure it out. Any help would be appreciated.

Sunday, Monday, etc. are AppleScript terms.


set WD to Tuesday as number --> 3 (Sunday is 1)

Go from there.

Hi,

if you could assign AppleScript’s weekday constants to ADODx instead of strings,
the whole thing can be reduced to:

set dayList to {day1, day2, day3, day4, day5, day6, day7}
set Xdate1 to item (ADOD1 as integer) of dayList
set Xdate2 to item (ADOD2 as integer) of dayList