How I catch an "open with..." with my app?

Mac OSX specific forum
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

How I catch an "open with..." with my app?

Post by Lebostein »

On Windows I use ProgramParameter() to get the filename. But on Mac OS it seems not work....
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: How I catch an "open with..." with my app?

Post by wilbert »

You need PB_Gadget_SetOpenFinderFiles(Callback)
viewtopic.php?p=391349
Windows (x64)
Raspberry Pi OS (Arm64)
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Re: How I catch an "open with..." with my app?

Post by Lebostein »

I have tried your code inside my app:

Code: Select all

ImportC ""
  PB_Gadget_SetOpenFinderFiles(Callback)
EndImport

IsGadget(0) ; Ensures the gadget lib is linked as this command is in it

ProcedureC OpenFinderFilesCallback(*Utf8Files)
    Protected filecnt,filesin$,filename$
    filesin$ = PeekS(*Utf8Files, -1, #PB_UTF8) ; Each file is separated by a 'tab'
    If Len(filesin$) ; Here you have the filename to open
        MessageRequester("Raw Load...",filesin$+" filecount="+Str(CountString(filesin$,Chr(9)))) ; Use StringField() to iterate easily
        For filecnt=1 To CountString(filesin$,Chr(9))+1
            filename$=StringField(filesin$,filecnt,Chr(9))
            filepath$=GetPathPart(filename$)
            filename$=GetFilePart(filename$)
            MessageRequester("Loading file...",filePath$+Chr(13)+filename$)
        Next
    EndIf
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop
But it don't work. I have edited my Info.plist before...
User avatar
Piero
Addict
Addict
Posts: 862
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: How I catch an "open with..." with my app?

Post by Piero »

Lebostein wrote: Sat Jun 14, 2025 7:52 pm it don't work. I have edited my Info.plist before...
Try this:
viewtopic.php?p=605670#p605670
Fred
Administrator
Administrator
Posts: 18150
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: How I catch an "open with..." with my app?

Post by Fred »

We use it in the IDE, so it should work: https://github.com/fantaisie-software/p ... MacMisc.pb
Mesa
Enthusiast
Enthusiast
Posts: 433
Joined: Fri Feb 24, 2012 10:19 am

Re: How I catch an "open with..." with my app?

Post by Mesa »

User avatar
Piero
Addict
Addict
Posts: 862
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: How I catch an "open with..." with my app?

Post by Piero »

Fred wrote: Thu Jun 26, 2025 8:44 am We use it in the IDE, so it should work: https://github.com/fantaisie-software/p ... MacMisc.pb
WTF Fred?!?!
wish I could help better, but the IDE """open file + quit stuff""" has lots of problems:
— using ⌘Q (instead of selecting "quit" on menu) makes it often hang…
— if you double-click a pb file already open in the IDE, it becomes frontmost tab, but then PB ALWAYS hangs on quit…
— seems to me a "sometimes you have to wait for filesystem/event" thing, or that you try to close already closed files, AND/or menuevent stuff
— (…)

anyway: my example linked above seems to work well for a PB app…

PS: TESTED ON SEQUOIA (upgrading was a pain, but it went better than I expected, for now…)
Post Reply