Recent

Author Topic: Handle double click on a file associated with LCL Application in MacOS  (Read 292 times)

daniel_sap

  • Jr. Member
  • **
  • Posts: 89
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

  • Hero Member
  • *****
  • Posts: 711
  • Tweaking4All.com
    • Tweaking4All
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

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

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
« Last Edit: April 16, 2025, 09:16:18 pm by daniel_sap »

Hansaplast

  • Hero Member
  • *****
  • Posts: 711
  • Tweaking4All.com
    • Tweaking4All
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?

 

TinyPortal © 2005-2018