Skip to main content
Participant
May 1, 2009
Answered

Use Applescript to copy Layer Objects between documents

  • May 1, 2009
  • 3 replies
  • 5441 views

I am trying to script the following with AppleScript:

1. User chooses reference and target files

2. open the reference file

3. Select and copy the objects on a specific layer to the clipboard

4. Paste clipboard contents into specific layer in target file

The InDesign CS3 dictionary has a copy command, but I encounter an error every which way I try to use it

copyv : Copies the selection in the active document window to the clipboard.

My script so far:

-- prompt user for reference and target files

set the reference_file to choose file with prompt "Select the InDesign reference file:" without invisibles

--set the target_file to choose file with prompt "Select the target file:"

tell application "Adobe InDesign CS3"

activate

set myLayer to "Layer 1"

open reference_file

tell active document

set reference_layer to object reference of (layer myLayer)

select every page item of reference_layer

copy selection

--close reference_file saving no

end tell

end tell

ERROR MESSAGE:

"Adobe InDesign CS3 got an error: selection of active document doesn’t understand the copy message."

Any one know how to use the copy verb correctly?

This topic has been closed for replies.
Correct answer L__Guy_O_Rojo

Hi:

Try using

copy

by itself, without a following parameter. In my scripts, I tell the App to do this, not the document or page.

hth,

egr

3 replies

Inspiring
May 1, 2009

There's no need to copy -- use the duplicate command instead. It'll be quicker, and doesn't overwrite the clipboard's contents:

tell application "Adobe InDesign CS3"

set active layer of document 2 to "Layer 1" -- the target document

duplicate (every page item of document 1 where name of its item layer is "Layer 1") to page 1 of document 2

end tell

GFLOROAuthor
Participant
May 4, 2009

Thanks for the suggestion.

In testing I run into the following two errors:

1. The set active layer fails with the following message:

"Adobe InDesign CS3 got an error: Can’t set active layer of alias \"MAC4025:Users:gfloro:Desktop:copy_ref2target:Document2.indd\" to \"Layer 1\"."

2. the duplicate line erros with the following message:

"Adobe InDesign CS3 got an error: every page item of alias \"MAC4025:Users:gfloro:Desktop:copy_ref2target:Document1.indd\" whose name of «class pilr» = \"Layer 1\" doesn’t understand the duplicate message."

I'll continue testing away, but if you have any other suggestions, I'll be glad to try them out.

Thanks,

Gregory

Larry G. Schneider
Community Expert
Community Expert
May 4, 2009

I just tried it and it does work. Do both of your document have only a single page? If not the you will have to address which page of Document 1 you wish to duplicate. Have both documents open and Document 1 foremost, then run the script.

L__Guy_O_RojoCorrect answer
Inspiring
May 1, 2009

Hi:

Try using

copy

by itself, without a following parameter. In my scripts, I tell the App to do this, not the document or page.

hth,

egr

GFLOROAuthor
Participant
May 1, 2009

thank you both for your assistance. separating the copy into it's own tell block did the trick.

Larry G. Schneider
Community Expert
Community Expert
May 1, 2009

It might be as simple as

set selection to every page item of reference_layer