And here is the AppleScript/Python solution that you can build to sit on your Desktop, and when you double-click on it, you will get prompted to enter the calendar required as mm/yyyy. Instantly, it will open a new web page with the requested monthly calendar displayed. You then apply the steps from my original post to select all days (including blank days) and paste into a Pages table.
Start the AppleScript Editor (Launchpad : Other : Script Editor). Copy/paste the following AppleScript into the Editor. Click the compile (hammer) icon. Click the Run ▸ button, and get your calendar results in a browser window. Save the AppleScript as htmlcal. When you click Text in the Format selector, the applescript extension will be applied to the filename. Now, option key + File menu : Save As… and use htmlcal as the name, but this time, choose Application from the Format selector, and hide the extension. Save it to your Desktop.
Code below:
-- Generate and display HTML Calendar (monthly) from user input (e.g. 4/2016). Subsequently, calendar
-- data can be copy/pasted from web page into existing Pages table for instant calendar data.
-- Name - htmlcal.applescript
-- Version 1.0
-- VikingOSX, 28-Apr-2016, Apple Support Community
-- property calfile : POSIX path of ((path to desktop) as text) & "caltab.html"
set html_pre to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\">"
set html_pre2 to "</head><body>"
set html_post to "</body></html>"
set atitle to "HTML Calendar Builder"
set amsg to "Enter the Month and Year for the calendar. No spaces." & return & "(e.g. 4/2016) "
try
set theDate to the text returned of (display dialogamsgdefault answer "" with titleatitle)
set {TID, AppleScript'stext item delimiters} to {AppleScript'stext item delimiters, "/"}
set {amonth, ayear} to text items of theDate
set AppleScript'stext item delimiters to TID
-- make Python handlers command-line arguments. Going directly to web page instead of file
set args to amonth & space & ayear-- & space & calfile's quoted form
-- the name for the new window tab shown as (e.g. HTML Calendar 4/2016)
set html_title to "<title>" & "HTML Calendar " & (amonth as text) & "/" & (ayear as text) & "</title>"
set caltable to make_HTML_calendar(args) as text
-- html5 web page to display including the new calendar table
set table_html to html_pre & html_title & html_pre2 & caltable & html_post
tell application "Safari" to open location "data:text/html," & table_html
on error errmsgnumbererrnbr
my error_handler(errnbr, errmsg)
end try
return
on make_HTML_calendar(args)
return do shell script "python <<'EOF' - " & args & "
#/usr/bin/python
# coding: utf-8
# Python script to generate a calendar table in HTML
import calendar
import sys
amonth = int(sys.argv[1])
ayear = int(sys.argv[2])
# ofile = sys.argv[3]
# Week starts on Sunday
c = calendar.HTMLCalendar(calendar.SUNDAY)
# with open(ofile, 'w') as hout:
# hout.write(c.formatmonth(ayear, amonth))
print(\"{}\".format(c.formatmonth(ayear, amonth)))
EOF"
end make_HTML_calendar
on error_handler(nbr, msg)
return display alert "[ " & nbr & " ] " & msg as critical giving up after 10
end error_handler