I’m trying to convert a block of text into a button. As you would do with Window > Interactive > Buttons and Forms > Convert to Button
I’ve searched the web and I’ve only found solutions that create new buttons, not to convert a frame to a button
Invoke menu action is totally reliable, unlike SE.
There’s no command like ‘convert to button’ in InDesign.
You can find a convert shape but it’s useless here.
If you want to, you can toy with something like the following:
tell application id "InDn"
-- get the original frame
set theFrame to item 1 of selection
-- make a button
set theButton to make new button at beginning of parent of selection with properties (properties of theFrame)
-- convert its 'content box' to a text frame
set (content type of (rectangle 1 of group 1 of theButton)) to text type
set theBox to (text frame 1 of group 1 of theButton)
end tell
This snippet will create a button above your text frame, leaving the latter in place.
After that you’ll need to re-build any property of the text frame inside the button to retrieve it aspect.
This because there’s an inconsistance in InDesign scripting : set properties of theBox to properties of theFrame will have no effect.
Here are some examples:
set fill color of theButton to fill color of theFrame
set contents of theBox to contents of contents of theFrame
set top left corner option of theBox to top left corner option of theFrame
set top left corner radius of theBox to top left corner radius of theFrame
tell text frame preferences of theBox
set vertical justification to vertical justification of text frame preferences of theFrame
end tell
set justification of paragraphs of theBox to justification of paragraphs of theFrame