Skip navigation
Currently Being Moderated

[JS/CS4/CS5] Catching a selection event in a ScriptUI interface.

Oct 6, 2011 7:39 AM

Tags: #javascript #events

I've got this ScriptUI interface (javascript based), and now I wonder if it would be possible to change one of its button captions depending on whether anything is selected or not, in the active document (would also have to be updated if the user selects or opens another document).

 

1. Is it possible to write event listeners for this?

2. Would it be possible to include this in the same script as the rest of the Script UI interface code (that is, I'd prefer avoiding a separate file in the startup folder).

3. What's the best source of information regarding events, which ones there are, and how to handle them in javascript?

 

Andreas

 
Replies
  • Currently Being Moderated
    Oct 6, 2011 9:37 AM   in reply to Andreas Jansson

    1. Yes. The selection events work well in my experience.

     

    2. Yes, you don't have to add them at startup. You can do something like:

     

    app.addEventListener("afterSelectionChanged", selectionChangedFunction);
    

     

    before you open your window. Remove the listener in the onClose event of the window. I think you'll have to have some error trapping in the selectionChangedFunction to deal with app.selection erroring after a document close or during a revert.

     

    3. See this thread for an extension that lets you see events as they're happening.

     

    Jeff

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 11, 2011 9:03 AM   in reply to Andreas Jansson

    It looks like the selection events were added in CS5, along with a lot of other ones.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 11, 2011 9:32 AM   in reply to Andreas Jansson

    That's right. CS3 and CS4 had many fewer events than CS5 and later.

     

    Harbs

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points