AppleScript loop works only the first time

Daria Shmaria <[email protected]>
Newsgroups gmane.comp.graphics.omnigraffle.user
Message-ID <[email protected]>
Hi,

I'm writing an AppleScript to transfer OmniGraffle documents into Adobe
Illustrator. It works - until you hit the second canvas, at which point it
pumps out copies of the most recent successfully transferred layer (the last
layer of the first canvas). Any suggestions on how to fix this loop would be
greatly appreciated.

set myDocument to (choose file with prompt "Choose an OmniGraffle file to
transfer to Adobe Illustrator")

tell application "OmniGraffle 5"
    set oDoc to open myDocument

    repeat with theLayer in every layer in every canvas in oDoc
        set visible of theLayer to false
    end repeat

    repeat with currentCanvas in every canvas in oDoc

        set canvasName to name of currentCanvas

        repeat with currentLayer in every layer in currentCanvas

            set visible of currentLayer to true
            set layerName to name of currentLayer

            (* this allows the second layer to be copied *)
            tell application "OmniGraffle 5"
                activate
            end tell

            tell application "System Events"
                keystroke "a" using {command down}
                keystroke "c" using {command down}
            end tell

            tell me to nameHolder(canvasName, layerName)

            set visible of currentLayer to false
        end repeat

    end repeat

    repeat with theLayer in every layer in every canvas of oDoc
        set visible of theLayer to true
    end repeat

end tell

(*store the initial visible settings of layers, return to that state after
program is finished *)
(* make the dimensions of the AI file the same as the Graffle file
(landscape v. portrait *)

on nameHolder(canv, lay)
    set canvasN to canv
    set layerN to lay
    set result to pasteToAI(canvasN, layerN)
end nameHolder

on pasteToAI(canv2, lay2)
    tell application "Adobe Illustrator"
        activate
        set canvasName to canv2
        set layerName to lay2
        set AIDoc to (make new document)
        save AIDoc in canvasName & "-" & layerName & ".ai"
        paste
    end tell
end pasteToAI
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.