Selecting or grouping multiple items

I’m trying to group two picture boxes in Quark. I find all this information in the dictionary and applescript guide about working with boxes that are already grouped, but I’m not seeing information on how to group two boxes. Is there a way to either create a group in Quark with applescript or to select both boxes in Quark and use system events to press command g?

Any help is greatly appreciated! This is part of a larger script and the part that groups the two boxes together is the only part that I’m having trouble getting to work.


on open of droppedfiles
	
	tell application "QuarkXPress"
		activate
		repeat with afile in droppedfiles
			open afile as alias with Suppress All Warnings
			tell document 1
				
				--Looping through every picture box
				set pictureBoxes to every picture box
				repeat with i from (number of pictureBoxes) to 1 by -1
					set pictureBox to item i of pictureBoxes
					
					
					--Duplicating the picture box
					set duplicateBox to duplicate pictureBox to after pictureBox
					
					
					--Adding the drop shadow to the duplicated box
					select duplicateBox
					tell application "System Events" to key code 97 using {command down} -->Pressing Command F6 to activate the drop shadow item style
					set selection to null -->unselecting the duplicate box, otherwise the shadow is applied to both boxes
					
					
					--Trying to select the two boxes
					select duplicateBox
					select pictureBox
					
					
					--Trying to group the two boxes			
					try
						tell application "System Events" to key code 5 using {command down} -->Pressing Command G to group the items
					on error
						my do_submenu("QuarkXPress", "Item", "Group")
					end try
					
					
					set selection to null
					
				end repeat
				
			end tell
		end repeat
	end tell
end open


--The UI Scripting select submenu function
on do_submenu(app_name, menu_name, menu_item)
	try
		-- bring the target application to the front
		tell application app_name
			activate
		end tell
		tell application "System Events"
			tell process app_name
				tell menu bar 1
					pick menu bar item menu_name
					tell menu bar item menu_name
						tell menu menu_name
							pick menu item menu_item
							click menu item menu_item
						end tell
					end tell
				end tell
			end tell
		end tell
		return true
	on error error_message
		return false
	end try
end do_submenu

Hi! I’ve replied to post on Publi-Script :wink:

Hi there,

I created a new document with some different box types on and the code below worked:


tell application "QuarkXPress"
	
	set theGenericBoxes to every generic box of page 1 of front document
	
	select item 1 of theGenericBoxes
	select item 2 of theGenericBoxes
	
	set theBoxSelection to selection
	set grouped of theBoxSelection to true
	
end tell

I’m using QuarkXpress 2015 so it may need tweaking for an earlier version.

HTH

EDIT: I’ve tried this in QuarkXpress 9.5.4.1 and it works in that version too.