Skip to main content
orib7317974
Known Participant
March 28, 2023
Question

Tell if a given object is selected (scripting)

  • March 28, 2023
  • 2 replies
  • 433 views

Hello,

 

I was looking for a property or a function that would tell whether an object is selected or not. I couldn't find anything. Is there no such thing?

 

(I know I can work with app.selection, but that has issues. Besides efficiency concerns, the structure could be complex. For example, if multiple cells in a table are selected, they aren't directly included in app.selection. Instead a single Cell object is included with a Cells property that holds each individual cell.)

 

Thanks!

This topic has been closed for replies.

2 replies

m1b
Community Expert
Community Expert
March 28, 2023

Hi @orib7317974, what would a hypothetical function look like? Perhaps

function isSelected(item) {

    // do stuff to work out
    // if item is selected

    return itemIsSelected;

};

Is this the sort of thing you need? It should be possible to write such a function.

- Mark

Robert at ID-Tasker
Legend
March 29, 2023

If OP have array / collection of the monitored items - it would be just a quick iteration of both lists and comparison of the IDs - or in case of a text - Parent Story ID + first & last characters indexes? 

 

Robert at ID-Tasker
Legend
March 28, 2023

No, there is no "selected" property - you need to use Selection. 

 

Not sure what do you mean by "complex" - if you have a range of cells selected - no other kind of objects can be selected. 

In text - only range of text can be selected. 

 

Yes, it gets tricky when in the 3rd case - free selection of the objects on the page - but then you can skip checking for cells and texts 😉 

 

orib7317974
Known Participant
March 28, 2023

So selected table cells or selected text rule out any other selected objects, and any other selected object will be included in app.selection directly? Thanks!

Robert at ID-Tasker
Legend
March 28, 2023

Yes, the same as in the UI - you can't select part of the text inside a TextFrame - and also objects outside of this TextFrame. 

 

The same with cells - you can only select continuous area - and nothing outside.