Skip to main content
andymalhan
Inspiring
January 28, 2025
Answered

Grouping selected objects in Indesign via AppleScript

  • January 28, 2025
  • 4 replies
  • 1114 views

As part of a larger script, I need to group a few preselected objects. Can't figure out what i'm doing wrong.

 

Here's a snippet: 

 

-- Select the image and caption, group them

set selection to {myRectangle, captionFrame}

set myGroup to group {myRectangle, captionFrame}

 

They get selected fine, but the group doesn't work:

 

error "Adobe InDesign 2025 got an error: Can’t get group {rectangle id 6639 of spread id 218 of document id 1, text frame id 6665 of spread id 218 of document id 1}." number -1728 from group {rectangle id 6639 of spread id 218 of document id 1, text frame id 6665 of spread id 218 of document id 1}

 

Any ideas?

 

Correct answer andymalhan
quote

first of all, you're not running it inside 'tell document' block. InDesign (the app) wouldn't know what 'page 7' is. 


By @leo.r

 

Pretty much at the same time 😉 

 


Thanks Leo and Robert... It's working!

 

tell activeDoc

-- it didn't work until I commented out the next line though

-- set selection to {myRectangle, captionFrame} 

make group at targetPage with data {group items:{myRectangle, captionFrame}}

end tell

4 replies

leo.r
Community Expert
Community Expert
January 28, 2025
make group at page 1 with data {group items:selection}

 

source:

https://www.macscripter.net/t/group-every-item-indesign-cs2/45280/4

andymalhan
Inspiring
January 29, 2025

I got this message: 

error "Adobe InDesign 2025 got an error: Can’t make class group." number -2710 from group to class

leo.r
Community Expert
Community Expert
January 29, 2025
quote

I got this message: 

error "Adobe InDesign 2025 got an error: Can’t make class group." number -2710 from group to class

By @andymalhan

 

Well. All I know is that it works here.

 

Are you running this inside 'tell document' block? Also, 'selection' is just an example. If you don't have anything selected, then use a list of your objects such as {myRectanglecaptionFrame} instead.

andymalhan
Inspiring
January 29, 2025

It doesn't seem to work. I tried Google before posting it here!! 😉

 

error "Adobe InDesign 2025 got an error: Can’t make class group." number -2710 from group to class

Robert at ID-Tasker
Legend
January 29, 2025
quote

It doesn't seem to work. I tried Google before posting it here!! 😉

 

error "Adobe InDesign 2025 got an error: Can’t make class group." number -2710 from group to class


By @andymalhan

 

Have you tried looking for the answer to error 2710? 

 

https://community.adobe.com/t5/indesign-discussions/applescript-not-adding-new-pages-in-indesign-cc-2018/td-p/9771139 

 

https://stackoverflow.com/questions/40940563/applescript-error-2710

 

leo.r
Community Expert
Community Expert
January 28, 2025
quote

set myGroup to group {myRectangle, captionFrame}

 

By @andymalhan

 

I don't have an immediate answer, but for starters there's no group command; group is a class.

andymalhan
Inspiring
January 29, 2025

Yes I think so too. 

error "Adobe InDesign 2025 got an error: Can’t make class group." number -2710 from group to class

Robert at ID-Tasker
Legend
January 28, 2025

I'm not Apple Script expert - but you need to CREATE a group - "set" in this case means "get a reference" - array of objects you're referring to is just bunch of objects - not a group.

 

In JS it would be something like: 

 

var myGroup = app.activeDocument.groups.add(...); 

 

Or something like that.