I'm thinking KM might be able to help me with this task. I want to enter a date, say Friday 16th December, and then get a list of every Friday for a certain number of weeks excluding particular dates that I would have in a text file. Essentially the academic year. Real case use is providing a list of dates for a class that is going to last x amount of weeks in the academic year.
So a macro that would ask for a start date, and how many weeks, would create a list of all those Mondays for example, and then delete all the public holidays, mid-term breaks etc, but still give me the full 8 weeks or however many I asked for.
The list could be created to clipboard or a textfile in mark down to be pasted into excel or an email.
Does this sound like something KM could do? I currently do it in excel and remove the dates by looking at the calendar. I'm not looking for a macro, just a suggestion as to a plausible way to proceed.
I'm thinking I'm going to convert the start date into an %ICUDateTimeFor% type variable, use %ICUDateTimePlus% to add 7 days, and then append that date to a text file. But before I append it, I would need to reg ex it against another text file containing a list of all unwanted dates (public holidays, etc), and use if/then statements to skip them. Rinse and Repeat until the number of repeats is complete?
Anyone have any words of wisdom before I start to save me from barking up the wrong tree?
This is awesome. I needed to adapt it to European or (Irish at least) dates. I did so by simply changing all 'MM/dd' to 'dd/MM'. The other thing worth noting is that exceptions seem to need to include the '0' before single digits, that is '01/02' for 1st Feb, not '1/2', which is fine, but in case anyone else wants to use this ever.
We don't have thanksgiving, so I tried to delete this section, but that resulted in an error.
on getThanksgivingDateThisYear(theYear)
set dateRef to current date
set year of dateRef to theYear
set month of dateRef to 11
set day of dateRef to 20
set time of dateRef to 0
repeat while weekday of dateRef ≠Thursday
set day of dateRef to (day of dateRef) + 1
end repeat
return its formatDate:dateRef usingFormat:"dd/MM"
end getThanksgivingDateThisYear
It is easy to cut and paste the results, but could you tell me how to get the results back into a KM Variable? Then I could do some more formatting from there.
Thanks again. I'd love to have a better grip on AppleScript but fear it may be beyond me given the time I have and my minimal background in programming.
You were on the right track, but you just removed the Thanksgiving handler and didn't remove the call to the handler. (A handler in AppleScript is a subroutine.)
Yes, that's because I'm using a fixed-length five character substring to test with:
MM/DD
It's much easier to not manage all the possibilities (M/D and MM/D and M/DD and MM/DD) and require the user to use a fixed date format.
Always start by looking at the help for a given action. (Right-Click on the action – bottom of the contextual menu.)