Indesign-Copy/Paste page contents from one document to another

Hi

I’m trying to copy content from one page to another document and then move in to position.

I’m make the script below (sorry, but not the most elegant) and sometimes it works and sometimes it doesn’t.

Basic Process should be:

  • select doc 1
  • select all items on page X and group
  • copy items
  • select doc 2
  • paste items
  • move to position
  • ungroup
  • repeat with next page

If anyone can help please :slight_smile:

thanks

Shane


tell application "Adobe InDesign 2022"
	activate
	set active document to document "donor-doc-1.indd"
	--
	tell document "donor-doc-1.indd"
		select all page items of page 1
	end tell
	--
	delay 0.25
	-- group
	tell application "System Events"
		key code 5 using command down
	end tell
	--
	copy
	delay 0.25
	set active document to document "final-doc-2.indd"
	--
	--Select page
	tell application "System Events"
		-- Apple J
		key code 38 using command down
		delay 0.25
		-- page 3
		key code 21
		delay 0.25
		-- Hit Enter
		key code 76
	end tell
	--
	delay 0.25
	--
	paste
	--
	delay 0.25
	move selection to {10, 10}
	--
	--ungroup
	tell application "System Events"
		key code 5 using {shift down, command down}
	end tell
	--
	--
	delay 0.25
	-- select none
	tell application "System Events"
		key code 0 using shift down
	end tell
	--
	--//////////// Copy & Paste from page 2 of donor doc
	--
	set active document to document "donor-doc-1.indd"
	--
	tell document "donor-doc-1.indd"
		select all page items of page 2
	end tell
	--	
	delay 0.25
	-- group
	tell application "System Events"
		key code 5 using command down
	end tell
	--
	--
	copy
	delay 0.25
	set active document to document "final-doc-2.indd"
	--
	--Select page
	tell application "System Events"
		-- Apple J
		key code 38 using command down
		delay 0.25
		--page 2 (nbut it doesn't see this as page 2 and just pasts it on page 1)
		key code 19
		delay 0.25
		-- Hit Enter
		key code 76
	end tell
	--
	delay 0.25
	--
	paste
	--
	delay 0.25
	move selection to {10, 100}
	--
	--
	--ungroup
	tell application "System Events"
		key code 5 using {shift down, command down}
	end tell
	--
	--
	delay 0.25
	-- select none
	tell application "System Events"
		key code 0 using shift down
	end tell
end tell

You could try something like this:

tell application "Adobe InDesign 2022"
	activate
	set SourceDoc to document "donor-doc-1.indd"
	set TargetDoc to document "final-doc-2.indd"
	set AllMoved to (duplicate (every page item of page 1 of SourceDoc) to page 1 of TargetDoc)
	tell TargetDoc
		set NewGroup to (make new group with properties {group items:AllMoved})
	end tell
	move NewGroup to {10, 100}
	ungroup NewGroup
end tell

Hi both.

MacScripter’s [applescript] and [/applescript] tags are both lower-case only. I’ve corrected them for you above.

Many thanks Nigel.

(I would have sworn that had I used the button in the reply form to insert them . . . . )

Nick

thanks Nigel.

I’m sure I pressed the applescript button too.

Shane

Thank you nickpassmore, work’s great.

In Safari I frequently find that lower-case applescript tags get auto-corrected to AppleScript (just like that) if I press a return after the final tag. Easy to miss unless you preview your message before submitting it.

Hi all.

Thanks for the feedback regarding possible auto-correction of the [applescript] tags in Safari. I’ve not been able to reproduce this myself, but I imagine it’s something to do with the way your Spelling preferences are set up in System Preferences and in Safari itself. Obviously you must keep these the way you want them. It’s just something of which to be aware when posting here. Hopefully it’s getroundable. :confused: