The Omni Group Forums

The Omni Group Forums (
-   OmniGraffle General (
-   -   Applescript help (

Shek 2012-09-03 01:06 PM

Applescript help

I have a series of questions regarding applescript for omnigraffle professional 5.

Let me start by this:
Let's say I have 10canvases in my document, and I want my script to append/insert a new canvas after the fourth canvas.
I'd imagine it'll be something like this
[CODE]tell the first document
set myCanvas to (make new canvas at fourth canvas)
end tell
However this script overwrite my fourth canvas instead of inserting a new canvas.


RobTrew 2012-09-03 01:40 PM

One approach might be:

[CODE]tell application id "OGfl"
tell front document
set myCanvas to (make new canvas with properties {name:"New blank sheet"})
move myCanvas to after canvas 4
end tell
end tell[/CODE]

Shek 2012-09-03 02:48 PM

Hi RobTrew,
Thanks for the answer. It worked.

I think the following is my final question before I get this script working fully..
Let's say again, I have 10 canvases, and I have a loop like this
tell application "OmniGraffle Professional 5"
set theCanvases to every canvas of the first document
set myCanvas to fourth canvas of the first document
set numCanvas to 0
set maxItemsPerCanvas to 3
tell the first document
repeat with theCanvas in theCanvases
tell myCanvas
end tell
set numCanvas to numCanvas + 1
if numCanvas > maxItemsPerCanvas then
set myCanvas to canvas after myCanvas --@HERE
set maxItemsPerCanvas to maxItemsPerCanvas + maxItemsPerCanvas
end if
end repeat
end tell
end tell


@HERE : I wanted to set myCanvas to the next Canvas in the document after myCanvas. But this code doesn't work. It is essentially "set myCanvas to fifth canvas" but I want to do this without hardcoding it.

RobTrew 2012-09-04 04:02 AM

May be easier, if you want to loop through the last N canvases, to loop with an index range.

[CODE]tell application id "OGfl"
set oWin to front window
tell front document

set lngCanvas to count of canvases
repeat with i from 4 to lngCanvas
set oCanvas to canvas i
set canvas of oWin to oCanvas
end repeat

set canvas of oWin to canvas 5
end tell
end tell[/CODE]

All times are GMT -8. The time now is 03:16 AM.

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