Forum > macOS / Mac OS X

Handle double click on a file associated with LCL Application in MacOS

(1/1)

daniel_sap:
Hi, I have desktop Windows application written in Lazarus FPC which checks
if FileExists(ParamStr(1)) then
          fileManager.Open(ParamStr(1));
else
  showWelcomeScreen();

The idea here is - if the user double clicks on a file in File Explorer it opens it,
when it opens the application it shows welcome screen
This works fine on Windows but now I build for MacOS and it always shows welcome screen.
What would be the proper approach for implementing when user double clicks on file in finder on MacOS

Hansaplast:
I haven't tested this, but this wiki page (link) has some suggestions that may help.
See the "Adding your custom URL scheme" section.

daniel_sap:

--- Quote from: Hansaplast on April 15, 2025, 09:25:14 am ---I haven't tested this, but this wiki page (link) has some suggestions that may help.
See the "Adding your custom URL scheme" section.

--- End quote ---

Thank you Hansaplast

I changed the code to work for file associations double click
Instead of ...kInternetEventClass, kAEGetURL); 
for files should be kCoreEventClass, kAEOpenDocuments);
And receive the event with proper file name.

What I don't know is how long should I wait for this event.
I don't want to slow down the start of the application too much, just because some event could possibly be triggered.

For me it will be better if I can check directly if there is file double clicked instead of waiting

Hansaplast:
I've never worked with this, so I have no idea.
Just being curious; how fast is the filename appearing in your app? I'd kind-a expect it to be there pretty quick (not having tested this myself).
Is there a reason why you should wait for it? Can't your application complete its startup without waiting?

rich2014:
TApplication.opDropFiles() for your reference

Navigation

[0] Message Index

Go to full version