The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle Extras (http://forums.omnigroup.com/forumdisplay.php?f=7)
-   -   Calendar (http://forums.omnigroup.com/showthread.php?t=873)

delu 2006-06-24 05:08 AM

Calendar
 
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 10: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 11:11 AM

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 03:46 PM

iCal -> Omnigraffle workaround
 
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 11:54 AM

Solution code
 
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 [url]http://forums.omnigroup.com/[/url]
*
* 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-20 11:56 PM

T.K.,

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

Cheers,

Tom

Dan Thomsen 2007-02-22 07: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 09: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 03:38 PM

2. The font sizes are set in the "preferences" at the top of the script:

[code]property kTitleTextSize : [COLOR="Red"]24[/COLOR]
property kHeaderTextSize : [COLOR="red"]18[/COLOR]
property kNormalTextSize : [COLOR="red"]12[/COLOR][/code]

To change the font used in the cells, add [COLOR="Red"]font:"your font name here",[/COLOR] to the [COLOR="Blue"]text:{}[/COLOR] syntax, throughout the script. E.g.
[code][B][COLOR="blue"]text:{[/COLOR][/B][COLOR="Red"][I]font:"Gill Sans", [/I][/COLOR]size:kHeaderTextSize, alignment:right, text:myDayCounter + 1 as string[B][COLOR="blue"]}[/COLOR][/B][/code]

JKT 2007-02-24 03: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 [url]http://forums.omnigroup.com/[/url]
*
* 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:{[COLOR="Red"]font:"Trebuchet MS",[/COLOR] 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", [COLOR="red"]fill color:{55535, 55535, 55535}[/COLOR], text:{[COLOR="red"]font:"Gill Sans", [/COLOR]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", [COLOR="red"]fill color:{50000, 50000, 50000}[/COLOR], text:{[COLOR="red"]font:"Gill Sans"[/COLOR], 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, [COLOR="red"]fill color:{60000, 60000, 60000}[/COLOR], text:{[COLOR="red"]font:"Gill Sans"[/COLOR], 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:{[COLOR="red"]font:"Gill Sans",[/COLOR] 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", [COLOR="red"]fill color:{50000, 50000, 50000},[/COLOR] text:{[COLOR="red"]font:"Gill Sans"[/COLOR], 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


All times are GMT -8. The time now is 09:54 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.