File hand-off on Silicon

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

File hand-off on Silicon

Post by WilliamL »

Fred provided this code over 10 yrs ago (on Intel) and it doesn't work on M1-Silicon. When I double-click on a file I get the app opening but no file loaded (see 'MessageRequester'). If I drag the file onto the app (after it is open) it loads. If I drag the file onto the app before it is open then the app opens but the file doesn't load.

Can this code be modified or is there another solution?

Code: Select all

;Fred's file hand-off
ImportC ""
  PB_Gadget_SetOpenFinderFiles(Callback)
EndImport

IsGadget(0) ; Ensures the gadget lib is linked as this command is in it
; if you put a MessageRequester before this the .app will not intercept incoming file!
ProcedureC OpenFinderFilesCallback(*Utf8Files)
    Protected cnt,filecnt,filesin$,filename$
    filesin$ = PeekS(*Utf8Files, -1, #PB_UTF8) ; Each file is separated by a 'tab'
        MessageRequester("Raw Load...",filesin$+" filecount="+Str(CountString(filesin$,Chr(9)))) ; Use StringField() to iterate easily
    If Len(filesin$) ; Here you have the filename to open
        For filecnt=1 To CountString(filesin$,Chr(9))+1
            filename$=StringField(filesin$,filecnt,Chr(9))
            MFilePath=GetPathPart(filename$)
            filename$=GetFilePart(filename$)
            MessageRequester("Loading file...",filename$+" filecnt="+Str(filecnt))
; remove code
            EndIf
        Next
    EndIf
EndProcedure

PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback()) ; should be put very early in the code, before any event loop
; end Fred's hand-off
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: File hand-off on Silicon

Post by Wolfram »

I have this problem too. On Intel macOS Ventura.
On Catalina it works.
Does someone has an idea to fix this probelm?
macOS Catalina 10.15.7
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: File hand-off on Silicon

Post by WilliamL »

Until this get fixed I have been using several methods to get around the lack of auto-loading.

In one program, that I use daily, when the associated file is double-clicked, the program opens and doesn't see a file in the callback so I use a pre-defined file as a stand-in and it loads.

In my monthly budget program, when I click on one of those associated files and there isn't anything in the callback I use the Date functions and create this month's file name and load that.

In everything else when the associated file is clicked on I just have to use the 'load file' function I wrote into the program after the program has loaded.
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
User avatar
Piero
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: File hand-off on Silicon

Post by Piero »

-- As a temporary solution, you can use an applescript:

on open tf
    ignoring application responses
        tell application "YOUR_PB_APP_NAME"
            activate
            
open tf
        end tell
    end ignoring
end open

-- Saved as app (droplet) it will also allow you to use drag and drop "directly" (no need to modify your PB app's plist…)
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: File hand-off on Silicon

Post by WilliamL »

Thanks Piero!

I'm not familiar with applescript but I managed to make your code into an app. It works if I drag my file onto the applescript app I created. Is this the way it should work? If so, then I would keep the applescript I created in the folder of my files and drag my file onto it each time?

This would work and be an improvement. :)
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
User avatar
Piero
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: File hand-off on Silicon

Post by Piero »

WilliamL wrote: Wed Aug 09, 2023 5:27 pm an improvement
If you select a file.xxx in finder and get Info (⌘-I) you can make all files.xxx open with your (applescript) app ("change all..." button)
Also, better, you can mess with the info.plist values into your script/app to set precisely what it can open...
...and then use get info...
Please forgive me for being so concise!
User avatar
Piero
Enthusiast
Enthusiast
Posts: 281
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: File hand-off on Silicon

Post by Piero »

Solved? This works on my Mac (thanks mk-soft!):

viewtopic.php?p=605670#p605670
Post Reply