-- Date: April 2nd, 2010, version 0.2
-- author: Micha Grandel, talk@michagrandel.de
-- Licence: Creative Commons 3.0 by-sa
--
-- LICENCE / LIZENZ
--
-- ENGLISH COPYRIGHT NOTE: (FOR THE GERMAN VERSION, SEE BELOW) -----------------------------------------------
--
-- This source code is distributed under Creative Commons Licence 3.0 Attribution-Share Alike.
-- This means, you are free to:
--
-- ... Share — to copy, distribute and transmit the work
-- ... Remix — to adapt the work
--
-- Under the following conditions:
--
-- 1) Attribution
-- You must attribute the work in the following manner (but not in any way that suggests that
-- they endorse you or your use of the work):
--
-- For printed media: author: Micha Grandel, www.michagrandel.de
--
-- For online media: author: <a href="http://www.michagrandel.de">Micha Grandel</a>
--
-- For internet boards: author: [URL=http://www.michagrandel.de]Micha Grandel[/URL]
--
-- For Twitter: by @michagrandel, [url]http://is.gd/bb62j[/url]
--
-- 2) Share Alike
-- If you alter, transform, or build upon this work, you may distribute the resulting work
-- only under the same, similar or a compatible license.
-- The author may give you a written permission to publish your adapted work under a licence
-- of the Free Software Foundation (like GNU Plublic Licence or BSD Licence). However, this
-- happens only on request and you need to ask the author!
--
-- More information about this licence you will get on [url]http://creativecommons.org/licenses/by-sa/3.0/[/url]
--
-- END OF ENGLISH COPYRIGHT NOTE ------------------------------------------------------------------------------------------
--
--
--
--
-- GERMAN COPYRIGHT NOTE: ----------------------------------------------------------------------------------------------------
--
-- Dieser Quellcode unterliegt der Creative Commons Licence 3.0 Attribution-Share Alike.
-- Das bedeutet, Sie dürfen:
--
-- ... das Werk bzw. den Inhalt vervielfältigen, verbreiten und öffentlich zugänglich machen
-- ... Abwandlungen und Bearbeitungen des Werkes bzw. Inhaltes anfertigen
--
-- unter den folgenden Bedingungen:
--
-- 1) Namensnennung:
-- Sie müssen den Namen des Autors/Rechteinhabers in der folgenden Weise nennen:
--
-- Für gedruckte Publikation: Autor: Micha Grandel, [url]www.michagrandel.de[/url]
--
-- Für Online Publikation: Autor: <a href="http://www.michagrandel.de">Micha Grandel</a>
--
-- Für Publikation in Foren: Autor: [URL=http://www.michagrandel.de]Micha Grandel[/URL]
--
-- Für Publikation in Twitter: von @michagrandel, [url]http://is.gd/bb62j[/url]
--
-- 2) Weitergabe unter gleichen Bedingungen
-- Wenn Sie das lizenzierte Werk bzw. den lizenzierten Inhalt bearbeiten oder in anderer Weise
-- erkennbar als Grundlage für eigenes Schaffen verwenden, dürfen Sie die daraufhin neu
-- entstandenen Werke bzw. Inhalte nur unter Verwendung von Lizenzbedingungen weitergeben,
-- die mit denen dieses Lizenzvertrages identisch oder vergleichbar sind.
-- Bei Bedarf kann dazu - nach Absprache und ausdrücklicher Erlaubnis des Autors/Rechteinhabers -
-- auch eine Lizenz der Free Software Foundation gehören, z.B. die GNU Public Licence oder
-- die BSD Lizenz.
--
-- Mehr Informationen zur Lizenz bekommen Sie auf [url]http://creativecommons.org/licenses/by-sa/3.0/de/[/url]
--
-- END OF GERMAN COPYRIGHT NOTE ----------------------------------------------------------------------------------------------
--
-- Changelog
--
-- version change
-- 0.2 Adds a canvas to the document and creates a table of contents on it.
-- The canvas can be choosen by using the tableOfContents property in the beginning
-- of the script and is set to page 2 by default.
-- 0.1 Saves all canvases of the document in a two-dimensional list
--
-- and now... have fun!
on run
set tableOfContents to {page:2, name:"Table of Contents"}
tell application "OmniGraffle Professional 5" to set graffleDocument to document of first window
set graffleCanvases to graffleCanvasesOf(graffleDocument)
addGraffleCanvasAt((page of tableOfContents), graffleDocument)
tell application "OmniGraffle Professional 5"
set name of canvas (page of tableOfContents) of graffleDocument to name of tableOfContents
tell canvas (page of tableOfContents) of graffleDocument
set sizeOfPageTitle to {400, 40}
set sizeOfCanvasTitle to {300, 20}
set sizeOfPageNumber to {100, 20}
set currentRepeat to 0
set startPoint to {(x of page size) / 2 - (item 1 of sizeOfPageTitle) / 2, 30}
make new shape at end of graphics with properties {size:sizeOfPageTitle, origin:startPoint, text:{text:"Table of Contents", font:"Helvetica", size:18, alignment:left}}
repeat with currentCanvas in graffleCanvases
set currentPageNumber to item 1 of currentCanvas
make new shape at end of graphics with properties {size:sizeOfCanvasTitle, origin:{item 1 of startPoint, ((item 2 of startPoint) + 50) + currentRepeat * 30}, text:{text:item 2 of currentCanvas, font:"Helvetica", size:12, alignment:left}}
make new shape at end of graphics with properties {size:sizeOfPageNumber, origin:{(item 1 of startPoint) + (item 1 of sizeOfCanvasTitle), ((item 2 of startPoint) + 50) + currentRepeat * 30}, text:{text:item 1 of currentCanvas as text, font:"Helvetica", size:12, alignment:right}}
set currentRepeat to currentRepeat + 1
end repeat
end tell
end tell
end run
--
-- addGraffleCanvasAt(positon, graffleDocument)
--
-- adds a canvas at <position> to the graffleDocument
--
-- @param position the position of the canvas to add.
-- allowed values are numbers greater than 0, "1st", "first", "begin", "start",
-- "beginning", "end" and "last"
-- @param graffleDocument the canvases of THIS document will be return
-- @return graffleCanvases a list of all canvases of this document, including id and name,
-- syntax: {{id, name}, {id, name}, ... }
--
-- @version 1.0 (April 2, 2010)
-- @author Micha Grandel, [email]talk@michagrandel.de[/email]
--
on addGraffleCanvasAt(position, graffleDocument)
tell application "OmniGraffle Professional 5"
if (position is "first" or position = "start" or position is "beginning" or position is "begin" or position is "1st" or position is 1) then
tell graffleDocument to make new canvas at beginning of canvases
else if (position is "last" or position is "end" or position is -1) then
tell graffleDocument to make new canvas at end of canvases
else
tell graffleDocument
try
set countOfCanvases to count of canvas
repeat with counter from position to countOfCanvases
if (counter is position) then
make new canvas
end if
set cName to name of canvas position
copy canvas position to the end of canvases
delete canvas position
set name of last canvas to cName
end repeat
on error
get canvases
end try
end tell
end if
end tell
end addGraffleCanvasAt
--
-- graffleCanvasesOf(graffleDocument)
--
-- returns all canvases of graffleDocuemnt
--
-- @param graffleDocument the canvases of THIS document will be return
-- @return graffleCanvases a list of all canvases of this document, including id and name,
-- syntax: {{id, name}, {id, name}, ... }
--
-- @version 1.0 (April 2, 2010)
-- @author Micha Grandel, [email]talk@michagrandel.de[/email]
--
on graffleCanvasesOf(graffleDocument)
set graffleCanvases to {}
tell application "OmniGraffle Professional 5"
set docCanvases to canvases of graffleDocument
set currentPageNumber to 1
repeat with currentCanvas in docCanvases
set currentCanvas to {currentPageNumber, name of currentCanvas}
copy currentCanvas to the end of graffleCanvases
set currentPageNumber to currentPageNumber + 1
end repeat
end tell
set return to graffleCanvases
end graffleCanvasesOf