MacOS: Get Filename from "document interaction controller"

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

MacOS: Get Filename from "document interaction controller"

Post by Kukulkan »

Hi Fred and Team,

If a PB application handles a mime-type or file extension on MacOS, it gets startet after double clicking such a document. Sadly, the filename is not submitted as a commandline parameter. It is done using a document interaction controller. It is described here:
http://developer.apple.com/library/ios/ ... Types.html

Can you please check these UIApplicationLaunchOptionsURLKey values on executable start in MacOS and pass them as commandline parameters?

With this function the filename(s) from this interface will be usable with the ProgramParameter() function.

Thank you!

Kukulkan
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MacOS: Get Filename from "document interaction controlle

Post by wilbert »

You are mixing things up Kukulkan.
This is for the mobile operating system iOS only.
If you look at the title of the link you posted, you will see it mentions iOS.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: MacOS: Get Filename from "document interaction controlle

Post by Kukulkan »

Oh damn, you are right! :oops:

Anyway, we need a way to get the submitted filename. It is definitely NOT submitted as commandline parameter.

Any ideas around this issue? Or is this a PB bug only?

Kukulkan
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MacOS: Get Filename from "document interaction controlle

Post by wilbert »

You are right about the commandline parameter.

As for a workaround, I prefer to wait for a response from the PB team first.
All possible workarounds are not easy to accomplish. Maybe there's some simple solution I overlooked.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: MacOS: Get Filename from "document interaction controlle

Post by Kukulkan »

I found this page:
https://developer.apple.com/library/mac ... rence.html

The arguments parameter should return this values...

Kukulkan
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MacOS: Get Filename from "document interaction controlle

Post by wilbert »

I already had looked into that but it just mentions the application name itself, no documents the application has to open unfortunately.
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: MacOS: Get Filename from "document interaction controlle

Post by Fred »

Actually it was needed for IDE as well, so we did a quick hack. You can use it as well for now, it will probably change for something more integrated later (like using ProgramParameter() instead). As i'm away from home and don't have OS X, i can't test the following code but you get the idea:

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)
  Files$ = PeekS(*Utf8Files, #PB_Utf8) ; Each file is separated by a 'tab'
  Debug Files$ ; Use StringField() to iterate easily
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: MacOS: Get Filename from "document interaction controlle

Post by wilbert »

That's a much easier approach as other possible workarounds :D

The code form Fred is almost working except for the PeekS command

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)
  Files$ = PeekS(*Utf8Files, -1, #PB_UTF8) ; Each file is separated by a 'tab'
  MessageRequester("", Files$) ; Use StringField() to iterate easily
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: MacOS: Get Filename from "document interaction controlle

Post by Kukulkan »

Hello,

this works fine if the app was called with a filename. But how to detect if it was called without a filename?

My application works both as viewer (filename in parameter) or editor (no filename).

If I like to view a file it works good with this hack. But if, with opened viewer, someone likes to run the editor (start app in "Applications"), it only activates my current viewer. The callback here is not called in this case (there is no filename given).

Any idea? Is there a callback like PB_Gadget_SetOpenFinderFiles() for this case, too?

Kukulkan
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: MacOS: Get Filename from "document interaction controlle

Post by coder14 »

Fred wrote:Actually it was needed for IDE as well, so we did a quick hack. You can use it as well for now, it will probably change for something more integrated later (like using ProgramParameter() instead). As i'm away from home and don't have OS X, i can't test the following code but you get the idea:

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)
  Files$ = PeekS(*Utf8Files, #PB_Utf8) ; Each file is separated by a 'tab'
  Debug Files$ ; Use StringField() to iterate easily
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop
Hi Fred! You said a quick hack - is it still safe to use it?

For my own education is PB_Gadget_SetOpenFinderFiles hooking AEOpenDocuments from OS-X?

Thank you!
Post Reply