String of the file that opened the app?

Mac OSX specific forum
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

String of the file that opened the app?

Post by J. Baker »

I didn't want to bump an old feature request topic...
http://www.purebasic.fr/english/viewtop ... 89#p391289

...but what am I missing? Global doesn't seem to work here. I just need the string outside of ProcedureC.

Code: Select all

Global FileIn$ = ""

ImportC ""
  PB_Gadget_SetOpenFinderFiles(Callback)
EndImport

IsGadget(0)

ProcedureC OpenFinderFilesCallback(*Utf8Files)
  FileIn$ = PeekS(*Utf8Files, -1, #PB_UTF8)
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback())
MessageRequester("Result", FileIn$)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: String of the file that opened the app?

Post by wilbert »

You can try to combine the global variable with a PostEvent inside the callback procedure.
That way you can respond to the event and be sure the global variable has been set.

Did you also think about CFBundleDocumentTypes in the Info.plist file ?
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: String of the file that opened the app?

Post by Danilo »

Works here.

Code: Select all

#My_Event_NewFiles = #PB_Event_FirstCustomValue

Global FileIn$ = ""

ImportC ""
  PB_Gadget_SetOpenFinderFiles(Callback)
EndImport

IsGadget(0)

ProcedureC OpenFinderFilesCallback(*Utf8Files)
    FileIn$ = PeekS(*Utf8Files, -1, #PB_UTF8)
    PostEvent(#MY_EVENT_NEWFILES)
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback())

OpenWindow(0,0,0,200,200,"OpenFinderFilesCallback",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

Repeat
    Select WaitWindowEvent()
        Case #PB_Event_CloseWindow : End
        Case #My_Event_NewFiles    : MessageRequester("Result", FileIn$)
    EndSelect
ForEver
Info.plist additions:

Code: Select all

    <key>CFBundleDocumentTypes</key>
    <array>
      <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
          <string>smpf</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>FileIcon.icns</string>
        <key>CFBundleTypeName</key>
        <string>Sprite Monkey Project</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
      </dict>
    </array>
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: String of the file that opened the app?

Post by J. Baker »

@ Danilo - That does work great, thanks! ;)

@Wilbert - Yeah, I have the icon made and everything.

Now I'm trying to get the file association done. For some reason it's not working. I've done it before, just like the plist example you posted and all was fine but not now for some reason. May have to log into OS X 10.6 and try there.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: String of the file that opened the app?

Post by J. Baker »

It's done! Thanks you both for the feedback and help! ;)

The weird thing was, I had to change my file icon name from "smpf.icns" to "FileIcon.icns". In the plist and the actual icon name, of course. I thought you could name them however you want. :shock:

Anyway, I've been testing it and all seems good but I'll do some more testing before uploading to iTunes Connect. :D
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Wolfram
Enthusiast
Enthusiast
Posts: 610
Joined: Thu May 30, 2013 4:39 pm

Re: String of the file that opened the app?

Post by Wolfram »

On thing what I've noticed is, that I often have to restart the Finder before the file drag and drop works on a fresh compiled app.
Or you can use a tool which is called Refresh Finder.

The Name of the Icon has definitely no effect for the drag and drop function.
macOS Catalina 10.15.7
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: String of the file that opened the app?

Post by J. Baker »

I don't have any issues with drag and drop but thanks. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Post Reply