Page 1 of 1

Class Calendar

Posted: 2009-08-23 20:36:07
by midwinter
Every semester, I create a syllabus for my classes that includes a table with a list of dates and assignments for those dates. I have always done this by hand. Would it be possible to have a macro spit out a list of days/dates within a certain range (for MWF and T/Th) so I don't have to do this by hand? Something like

Monday 8/24
Wednesday 8/26


Tuesday 8/25
Thursday 8/27

Thanks in advance!

Re: Class Calendar

Posted: 2009-08-24 23:10:54
by Kino
Does this work as you expected? It will ask you to specify the first date, the last date and days of week and insert a table at the current insertion point (in a new document if there is no open document).

This macro does not check the validity of date format and that of a date itself. So you may get an unexpected result or an error if you give a wrong one. E.g. "2009-4-31" (wrong date in the valid format).

Code: Select all

 Require Pro Version 1.3

$namesOfDay =
$namesOfDay[0] = Date.nameOfWeekday 7
$i = 1
while $i < 7
	$namesOfDay[$i] = Date.nameOfWeekday $i
	$i += 1

$indexToName =
foreach $i, $n in $namesOfDay
	$indexToName{$i} = $n

$now =
$today = $now.year & '-'
$today &= $now.month & '-'
$today &= $

$date1 = Prompt Input 'From...', '', '', $today
$date2 = Prompt Input 'To...', '', '', $date1
$date1 = $date1.split '-'
$date2 = $date2.split '-'

$checked = Prompt Checkboxes 'Check names of day', '', '', $namesOfDay
if ! $checked.count
	exit 'No item checked, exit...'

$checkedNames =
foreach $name in $checked
	$i = $namesOfDay.indexOfValue $name
	$checkedNames{$i} = 1

$output = ''

Set Exported Perl Variables 'date1', 'date2', 'checkedNames', 'indexToName', 'output'
begin Perl
	use Time::Local;
	$i = timelocal (0, 0, 12, $date1[2], $date1[1]-1, $date1[0]);
	$j = timelocal (0, 0, 12, $date2[2], $date2[1]-1, $date2[0]);
	while ($i <= $j) {
		@lt = localtime($i);
		if (defined $checkedNames{$lt[6]}) {
			$output .= sprintf ("%s\t%01d/%01d\t\n", $indexToName{$lt[6]}, $lt[4]+1, $lt[3]);
		$i += 86400;

$doc =
if $doc == undefined  # if no document is open...

Insert Text $output
Menu ':Table:Convert to Table'
This macro uses Perl because Nisus Macro language does not have a command for generating an arbitrary date object and properties such as year, month, day are Read-only. I hope these limitations will be removed in a future version. Also I'd like to have a command such as

Code: Select all

$dateObject = Prompt Date 'Message', 'Detail', 'Button', $defaultDateObject
which will prompt a dialog box having input fields with stepper for date and time, something like those in Date & Time system preferences pane.

Re: Class Calendar

Posted: 2009-09-27 13:19:55
by midwinter
I neglected to respond, but yes yes yes! This is perfect!