Show Window by clicking icon in Dock

I’ve got a floating window with a Hide button, and I want to be able to show that window when it’s hidden by clicking on my app’s icon in the Dock. I have code inside the Event Activate that works, except that if my app is still active in the macOS, it doesn’t work. You have to first click on another app or the desktop, then click back on my app icon to make the window show. Is there a way to have the app respond to the Dock icon being clicked regardless of whether it’s active or not?

When you click on your app icon in the Dock, the application receives an AppleEvent. So, you can catch this AppleEvent and restore your window.
In API2, you’d add the AppleEventReceived event to the app class with this code:

if eventClass+eventID="aevtrapp" then 'eventClass=aevt and eventID=rapp when the app is “reopened”
  //Restore the window
  Return True
end if

In API1, it’s the same except the event to add to the app class is HandleAppleEvent.
HTH

1 Like

I don’t know what API1 or API2 is.

Where this code be going exactly?

See:
https://documentation.xojo.com/api/user_interface/desktop/desktopapplication.html#desktopapplication-appleeventreceived

I don’t have an AppleEventReceived in my Event Handler options.

Oh dear oh dear.

What did @Arnaud_N say in his post?

1 Like

Thank you Arnaud! That did it!

You’re welcome :slightly_smiling_face: