12 Month from Now Calendar

I frequently find it useful to have a yearly calendar that starts in the present month and runs for one year.
The following script produces a two-column calendar that fits nicely on one page for printing.
It can probably be made more efficient, but this works for me.


set mo to (month of (current date) as number)
set Yr to " " & year of (current date)
set tab2 to tab & tab
set myCal to ""

-- Get a year of monthly calendars
repeat 12 times
	set myCal to myCal & (do shell script "cal " & mo & Yr)
	set mo to (mo + 1) mod 12
	if mo = 0 then set mo to 12
	if mo = 1 then set Yr to " " & ((year of (current date)) + 1)
	set myCal to (myCal & return) as Unicode text
end repeat

-- Make two colums of odd and even months
set newCal to ""
repeat with n from 0 to 5
	set j to n * 16
	repeat with k from 1 to 8
		set leftcol to pad(paragraph (k + j) of myCal)
		set newLine to (leftcol & tab & (paragraph (k + j + 8) of myCal))
		set newCal to newCal & newLine & return
	end repeat
end repeat

-- Save to a document on the desktop (I print it and trash it later)
try
	set theCal to open for access (path to desktop as text) & "Calendar" with write permission
	write newCal to theCal
	close access theCal
on error
	close access theCal
end try

-- Open in TextEdit
tell application "TextEdit"
	open alias ((path to desktop as text) & "Calendar")
	repeat with n from 1 to 48
		tell text of front document
			set paragraph n to tab2 & paragraph n
		end tell
	end repeat
	tell paragraphs of text of front document
		set font to "Courier"
	end tell
end tell

-- Handler to pad out lines so tab works properly
to pad(para)
	set len to length of para
	repeat (16 - len) times
		set para to para & space
	end repeat
	return para
end pad


Well, this is 3 columns, 2 full years, but 1 line:

do shell script “cal 2005 > ~/Desktop/cal.txt; cal 2006 >> ~/Desktop/cal.txt”

Neat. Since I’m not a whiz at shell script, I’m assuming that the >> means “append”. True?

I went to the bother above because I specifically wanted the year by months from now and
didn’t know how to get that as a shell script. Is there a way to start your script in one of
the first column months and end it four calendar rows later (other than by editing the document)?
That would be useful to me.

Right.

means create & output to this file; overwriting if its there.

means append if its there, creating a new one if its not.

Sorry, cal can either do 1 month (cal 8 2005) or 1 full year (cal 2005). That’s the price of simplicity - gotta cope with the results.