Skip to main content
Participant
November 9, 2018
Answered

afterOpen event listener triggers also before open... (applescript)

  • November 9, 2018
  • 1 reply
  • 906 views

Cheers.

First post here (I think) although I have been working with applescripting InDesign for a long time 😃

Yesterday I did my first try with an event listener, it works, but the problem is that it triggers twice, once before the document has opened and once when it is open.
I thought "afterOpen" should do what it sounds like... Am I doing something wrong here?

tell application "Finder"

  set TheDesktop to (path to desktop as text)

end tell

tell application "Adobe InDesign CC 2014"

  set TheScript to TheDesktop & "Startuptest.app"

  make event listener with properties {event type:"afterOpen", handler:TheScript}

end tell

Regards

Johan

This topic has been closed for replies.
Correct answer Manan Joshi

Hello Johan,

I tried using this event handler using JS as well and found that it's fired twice if the document is opened and once when a new document is created. I am afraid this is the way it behaves and has been reported before as well, see the thread below

Re: EventListener afterOpen, delay

Now you might need to code in some workarounds in your code to avoid one of the two handler calls, some suggestions relevant to the scenario of the poster are given in the thread that i gave above. In a nutshell you just need to maintain a state that you can check across the call of handlers to identify if the work has been done or needs to be done.

Hope this helps.

-Manan

1 reply

Manan JoshiCommunity ExpertCorrect answer
Community Expert
November 9, 2018

Hello Johan,

I tried using this event handler using JS as well and found that it's fired twice if the document is opened and once when a new document is created. I am afraid this is the way it behaves and has been reported before as well, see the thread below

Re: EventListener afterOpen, delay

Now you might need to code in some workarounds in your code to avoid one of the two handler calls, some suggestions relevant to the scenario of the poster are given in the thread that i gave above. In a nutshell you just need to maintain a state that you can check across the call of handlers to identify if the work has been done or needs to be done.

Hope this helps.

-Manan

-Manan
Participant
November 9, 2018

Thank you Manan,

I should be able to do a window check with applescript as well, I'll give it a go.

Will post the result here if I get it to work.

Big thanks for the hint!