PDA

View Full Version : Calendar


delu
2006-06-24, 06:08 AM
Hi there!

Is there a plugin or any other possibility, to create an calendar in OmniGraffle?
I mean to get all Dates automatically and maybe a layout structure ... it's a lot of work to do everything "by hand".

afb
2006-06-25, 11:09 AM
You could try running "cal" in the terminal, which will give you the calendar of the current month. "cal 7 2006" will give you next month's calendar. Just copy and paste into OG.

delu
2006-06-30, 12:11 PM
That's a nice workaround :-)
But I'm missing a calendar functionallity like magic draw has it.
But I guess it's hard to satisfy every special need ..

fall-line
2006-10-09, 04:46 PM
my workaround solution for this need is to use iCal to display a blank (I had to first uncheck all my calendars) month view (though this could be done in any other view as well), and "Print" to a PDF. Then I simply open the PDF in OmniGraffle and have a nicely formatted calendar to work with as a base for my diagrams/charts/what have you.

Cheers!

Luke

T.K.Egan
2007-02-12, 12:54 PM
Copy and paste the code below into Script Editor, compile and save as application. You will likely want to modify the code to suit your needs but I declare it public domain so have at it.


(* Written by T.K.Egan
* 12 Feb 2007
* inspired by need and http://forums.omnigroup.com/
*
* updated by T.K.Egan
* 14 Feb 2007
* added headers and "editing cells"
*
* requires bsd subsystem and Omnigraffle to be installed
*)

-- preferences (you might edit these...)
property kHorizontalPadding : 10
property kVerticalPadding : 10
property kTitleTextSize : 24
property kHeaderTextSize : 18
property kNormalTextSize : 12
property kUseShortDayNames : true


-- constant data... With so much built in to Applescript these seem like odd omissions
set kMonths to {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
set kFullDayNames to {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
set kShortDayNames to {"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"}

-- program body begins... Editing the below will almost certainely change the program's behavior
if kUseShortDayNames then
set myDays to kShortDayNames
else
set myDays to kFullDayNames
end if
display dialog "What year is this calendar for:" default answer (year of (current date))
set myYear to text returned of result
set myMonth to (choose from list kMonths with prompt "Now choose the month:" without empty selection allowed and multiple selections allowed)
set myDocumentName to myMonth & " " & myYear as string
set myArgs to (listIndex(myMonth, kMonths) as string) & " " & myYear
set myCalendar to (do shell script "cal " & myArgs)
set AppleScript's text item delimiters to ASCII character 13
set myLines to every text item of myCalendar
set AppleScript's text item delimiters to "" -- always restore delimiters
--first two lines are trash the third line has the day numbers
set myInterestingLine to item 3 of myLines
set myLeadingDayBoxWidthMultiplier to countLeadingSpaces(myInterestingLine) div 3
-- the last line is blank, the next to last line has the last date
set myInterestingLine to item -2 of myLines
set myLastDay to ((characters (length of myInterestingLine) through -2 of myInterestingLine) as string) as number
set myTrailingDayBoxWidthMultiplier to 7 - ((myLeadingDayBoxWidthMultiplier + myLastDay) mod 7)
tell application "OmniGraffle"
activate
make new document with properties {name:myDocumentName}
end tell

set myDayCounter to 0
set myVerticalCursor to kVerticalPadding
set myHeaderCellHeight to kNormalTextSize * 1.5
tell document myDocumentName of application "OmniGraffle"
set myCanvasSize to canvasSize of first canvas
end tell
set myFullWidth to (first item of myCanvasSize as number) - 2 * kHorizontalPadding
set myCalendarDayBoxWidth to myFullWidth div 7
set myCalendarDayBoxHeight to ((second item of myCanvasSize as number) - (2 * kVerticalPadding + myHeaderCellHeight + kTitleTextSize * 1.5)) div ((count myLines) - 3) -- first two and final lines are bogus
tell document myDocumentName of application "OmniGraffle"
--make header
make new shape at end of graphics of first canvas with properties {origin:{kHorizontalPadding, myVerticalCursor}, size:{myFullWidth, kTitleTextSize * 1.5}, draws shadow:false, draws stroke:false, name:"Rectangle", fill color:{65535, 65535, 65535}, text:{size:kTitleTextSize, alignment:center, text:myDocumentName}}
set myVerticalCursor to myVerticalCursor + kTitleTextSize * 1.5
repeat with theDay in myDays
make new shape at end of graphics of first canvas with properties {origin:{myDayCounter * myCalendarDayBoxWidth + kHorizontalPadding, myVerticalCursor}, size:{myCalendarDayBoxWidth, myHeaderCellHeight}, draws shadow:false, name:"Rectangle", fill color:{65535, 65535, 65535}, text:{size:kHeaderTextSize, alignment:center, text:theDay}}
set myDayCounter to myDayCounter + 1
end repeat
set myVerticalCursor to myVerticalCursor + myHeaderCellHeight
-- make leader
if myLeadingDayBoxWidthMultiplier is greater than 0 then
make new shape at end of graphics of first canvas with properties {origin:{kHorizontalPadding, myVerticalCursor}, size:{myCalendarDayBoxWidth * myLeadingDayBoxWidthMultiplier, myCalendarDayBoxHeight}, draws shadow:false, name:"Rectangle", fill color:{65535, 65535, 65535}, text:{size:kNormalTextSize}}
end if
set myDayCounter to 0
set myDayOfWeekCounter to myLeadingDayBoxWidthMultiplier
-- make normal calendar day boxes
repeat while myDayCounter is less than myLastDay
repeat while myDayOfWeekCounter is less than 7 and myDayCounter is less than myLastDay
--make a calendar day box
make new shape at end of graphics of first canvas with properties {origin:{myDayOfWeekCounter * myCalendarDayBoxWidth + kHorizontalPadding, myVerticalCursor + kHeaderTextSize + 1}, size:{myCalendarDayBoxWidth, myCalendarDayBoxHeight - (kHeaderTextSize + 1)}, draws shadow:false, name:"Rectangle", text placement:top, fill color:{65535, 65535, 65535}, text:{size:kNormalTextSize, alignment:left}}
make new shape at end of graphics of first canvas with properties {origin:{myDayOfWeekCounter * myCalendarDayBoxWidth + kHorizontalPadding, myVerticalCursor}, size:{myCalendarDayBoxWidth, myCalendarDayBoxHeight}, draws shadow:false, name:"Rectangle", text placement:top, fill color:{65535, 65535, 65535}, text:{size:kHeaderTextSize, alignment:right, text:myDayCounter + 1 as string}}
set myDayCounter to myDayCounter + 1
set myDayOfWeekCounter to myDayOfWeekCounter + 1
end repeat
set myDayOfWeekCounter to 0
set myVerticalCursor to myVerticalCursor + myCalendarDayBoxHeight
end repeat
-- make trailing box
if myTrailingDayBoxWidthMultiplier is greater than 0 then
make new shape at end of graphics of first canvas with properties {origin:{kHorizontalPadding + (7 - myTrailingDayBoxWidthMultiplier) * myCalendarDayBoxWidth, myVerticalCursor - myCalendarDayBoxHeight}, size:{myCalendarDayBoxWidth * myTrailingDayBoxWidthMultiplier, myCalendarDayBoxHeight}, draws shadow:false, name:"Rectangle", fill color:{65535, 65535, 65535}, text:{size:kNormalTextSize}}
end if
end tell

on listIndex(theItem, theList)
repeat with i from 1 to the count of theList
if item i of theList as string = theItem as string then return i
end repeat
return -1
end listIndex

on countLeadingSpaces(theLine)
set myCounter to 1
set myOldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set myLineAsCharList to every text item of theLine
set AppleScript's text item delimiters to myOldDelimiters
repeat while item myCounter of myLineAsCharList is " "
set myCounter to myCounter + 1
end repeat
return myCounter - 1
end countLeadingSpaces

tpwilcox
2007-02-21, 12:56 AM
T.K.,

I tried out your script. Really really nice. Thank you for the effort!

Cheers,

Tom

Dan Thomsen
2007-02-22, 08:20 PM
Thanks!

Note if you are using Omnigraffle Professional like me I found I had to change the tell statements to tell "Omnigraffle Professional" rather than "Omnigraffle"

Dan

mitchellm
2007-02-24, 10:18 AM
I've got the script to work fine, but I don't really know how to use AppleScripting.

Here's 2 things I'd like to change in the script:

1. The page orientation is landscape (and so all the parameters fit best on
this type of page).

2. Setting default font/size for various sections of the calendar.

Any hints on what specifically I change in the wonderful script provided? Of the two, the most time consuming fix is setting for landscape mode as this realistically changes probably some font size settings and so on.

JKT
2007-02-24, 04:38 PM
2. The font sizes are set in the "preferences" at the top of the script:

property kTitleTextSize : 24
property kHeaderTextSize : 18
property kNormalTextSize : 12

To change the font used in the cells, add font:"your font name here", to the text:{} syntax, throughout the script. E.g.
text:{font:"Gill Sans", size:kHeaderTextSize, alignment:right, text:myDayCounter + 1 as string}

JKT
2007-02-24, 04:46 PM
E.g. in this version, I have changed the font of the title to Trebuchet MS, the day names and numbers to Gill Sans, and added some shading to the boxes:

(* Written by T.K.Egan
* 12 Feb 2007
* inspired by need and http://forums.omnigroup.com/
*
* updated by T.K.Egan
* 14 Feb 2007
* added headers and "editing cells"
*
* requires bsd subsystem and OmniGraffle Professional to be installed
*)

-- preferences (you might edit these...)
property kHorizontalPadding : 10
property kVerticalPadding : 10
property kTitleTextSize : 24
property kHeaderTextSize : 18
property kNormalTextSize : 12
property kUseShortDayNames : true


-- constant data... With so much built in to Applescript these seem like odd omissions
set kMonths to {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
set kFullDayNames to {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
set kShortDayNames to {"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"}

-- program body begins... Editing the below will almost certainely change the program's behavior
if kUseShortDayNames then
set myDays to kShortDayNames
else
set myDays to kFullDayNames
end if
display dialog "What year is this calendar for:" default answer (year of (current date))
set myYear to text returned of result
set myMonth to (choose from list kMonths with prompt "Now choose the month:" without empty selection allowed and multiple selections allowed)
set myDocumentName to myMonth & " " & myYear as string
set myArgs to (listIndex(myMonth, kMonths) as string) & " " & myYear
set myCalendar to (do shell script "cal " & myArgs)
set AppleScript's text item delimiters to ASCII character 13
set myLines to every text item of myCalendar
set AppleScript's text item delimiters to "" -- always restore delimiters
--first two lines are trash the third line has the day numbers
set myInterestingLine to item 3 of myLines
set myLeadingDayBoxWidthMultiplier to countLeadingSpaces(myInterestingLine) div 3
-- the last line is blank, the next to last line has the last date
set myInterestingLine to item -2 of myLines
set myLastDay to ((characters (length of myInterestingLine) through -2 of myInterestingLine) as string) as number
set myTrailingDayBoxWidthMultiplier to 7 - ((myLeadingDayBoxWidthMultiplier + myLastDay) mod 7)
tell application "OmniGraffle Professional"
activate
make new document with properties {name:myDocumentName}
end tell

set myDayCounter to 0
set myVerticalCursor to kVerticalPadding
set myHeaderCellHeight to kNormalTextSize * 1.5
tell document myDocumentName of application "OmniGraffle Professional"
set myCanvasSize to canvasSize of first canvas
end tell
set myFullWidth to (first item of myCanvasSize as number) - 2 * kHorizontalPadding
set myCalendarDayBoxWidth to myFullWidth div 7
set myCalendarDayBoxHeight to ((second item of myCanvasSize as number) - (2 * kVerticalPadding + myHeaderCellHeight + kTitleTextSize * 1.5)) div ((count myLines) - 3) -- first two and final lines are bogus
tell document myDocumentName of application "OmniGraffle Professional"
--make header
make new shape at end of graphics of first canvas with properties {origin:{kHorizontalPadding, myVerticalCursor}, size:{myFullWidth, kTitleTextSize * 1.5}, draws shadow:false, draws stroke:false, name:"Rectangle", fill color:{65535, 65535, 65535}, text:{font:"Trebuchet MS", size:kTitleTextSize, alignment:center, text:myDocumentName}}
set myVerticalCursor to myVerticalCursor + kTitleTextSize * 1.5
repeat with theDay in myDays
make new shape at end of graphics of first canvas with properties {origin:{myDayCounter * myCalendarDayBoxWidth + kHorizontalPadding, myVerticalCursor}, size:{myCalendarDayBoxWidth, myHeaderCellHeight}, draws shadow:false, name:"Rectangle", fill color:{55535, 55535, 55535}, text:{font:"Gill Sans", size:kHeaderTextSize, alignment:center, text:theDay}}
set myDayCounter to myDayCounter + 1
end repeat
set myVerticalCursor to myVerticalCursor + myHeaderCellHeight
-- make leader
if myLeadingDayBoxWidthMultiplier is greater than 0 then
make new shape at end of graphics of first canvas with properties {origin:{kHorizontalPadding, myVerticalCursor}, size:{myCalendarDayBoxWidth * myLeadingDayBoxWidthMultiplier, myCalendarDayBoxHeight}, draws shadow:false, name:"Rectangle", fill color:{50000, 50000, 50000}, text:{font:"Gill Sans", size:kNormalTextSize}}
end if
set myDayCounter to 0
set myDayOfWeekCounter to myLeadingDayBoxWidthMultiplier
-- make normal calendar day boxes
repeat while myDayCounter is less than myLastDay
repeat while myDayOfWeekCounter is less than 7 and myDayCounter is less than myLastDay
--make a calendar day box
make new shape at end of graphics of first canvas with properties {origin:{myDayOfWeekCounter * myCalendarDayBoxWidth + kHorizontalPadding, myVerticalCursor + kHeaderTextSize + 1}, size:{myCalendarDayBoxWidth, myCalendarDayBoxHeight - (kHeaderTextSize + 1)}, draws shadow:false, name:"Rectangle", text placement:top, fill color:{60000, 60000, 60000}, text:{font:"Gill Sans", size:kNormalTextSize, alignment:left}}
make new shape at end of graphics of first canvas with properties {origin:{myDayOfWeekCounter * myCalendarDayBoxWidth + kHorizontalPadding, myVerticalCursor}, size:{myCalendarDayBoxWidth, myCalendarDayBoxHeight}, draws shadow:false, name:"Rectangle", text placement:top, fill color:{65535, 65535, 65535}, text:{font:"Gill Sans", size:kHeaderTextSize, alignment:right, text:myDayCounter + 1 as string}}
set myDayCounter to myDayCounter + 1
set myDayOfWeekCounter to myDayOfWeekCounter + 1
end repeat
set myDayOfWeekCounter to 0
set myVerticalCursor to myVerticalCursor + myCalendarDayBoxHeight
end repeat
-- make trailing box
if myTrailingDayBoxWidthMultiplier is greater than 0 then
make new shape at end of graphics of first canvas with properties {origin:{kHorizontalPadding + (7 - myTrailingDayBoxWidthMultiplier) * myCalendarDayBoxWidth, myVerticalCursor - myCalendarDayBoxHeight}, size:{myCalendarDayBoxWidth * myTrailingDayBoxWidthMultiplier, myCalendarDayBoxHeight}, draws shadow:false, name:"Rectangle", fill color:{50000, 50000, 50000}, text:{font:"Gill Sans", size:kNormalTextSize}}
end if
end tell

on listIndex(theItem, theList)
repeat with i from 1 to the count of theList
if item i of theList as string = theItem as string then return i
end repeat
return -1
end listIndex

on countLeadingSpaces(theLine)
set myCounter to 1
set myOldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set myLineAsCharList to every text item of theLine
set AppleScript's text item delimiters to myOldDelimiters
repeat while item myCounter of myLineAsCharList is " "
set myCounter to myCounter + 1
end repeat
return myCounter - 1
end countLeadingSpaces

mitchellm
2007-02-25, 12:18 PM
Jonathan,

Thanks so much for the extra info on fonts, sizes, etc. That really helps!

Is there any easy way I can adapt the script so the resulting calendar uses the landscape orientation (horizontal) rather than the portrait orientation (vertical)?

Thanks again.

JKT
2007-02-25, 02:55 PM
I'm afraid that is beyond my skills (fwiw, I just worked out the font settings by trial and error). I can't see any obvious code to add or change for the page layout.

mitchellm
2007-02-26, 10:14 AM
Thanks anyway! Your script is incredibly helpful.

Dan Thomsen
2007-03-06, 05:49 PM
Here is a quick way to create a calendar with landscape

Create a template called landscape (simply open a new document, go to the canvas panel and set the orientation to landscape, then save as a template). I called mine landscape.

Then change the following lines telling it to use the landscape template


tell application "OmniGraffle Professional"
activate
make new document with properties {name:myDocumentName, template:"landscape"}
end tell


the template:"landscape" is the new part.

It works great.