f.launch does not work under Catalina

Sounds simple enough, right ?

My update class uses f.launch to run the Mac Installer .pkg file, but under Catalina, it simply won’t work.

I will have to scour MBS documentation to find the equivalent, and hope it works…

Christian, which plugin can execute another app ?

f.Launch works fine for me. Which file are you trying to launch?

I am trying to launch an installer pkg file.

But since I posted, I did other experiments trying to launch a regular app, and I get the same result.

No error, but nothing happens.

I am working with a small test app that simply opens the MAS app. Under High Sierra, it runs flawlessly, under Catalina Beta 19A512f, it simply does nothing.

I just tried to launch the app from a shell with Open, and get the same result. It works as expected under High Sierra, and does nothing under Catalina.

But your post made me wonder if there would be a difference between launching apps, and documents.

To test that, I tried to open a text file. I get a dialog

“test.app” would like to access files in your download folder.
[Don’t Allow] [OK]

When I click OK, the text file is opened just fine.

So indeed, launch works for documents, although apparently Apple’s paranoia has increased, and the user has to confirm access to the folder.

I am left with the same predicament. I tried to dive into Monkeybread’s documentation with a search, but frankly, it exceeds my comprehension.

That’s odd. At the end of my own self-written installer I launch the main app. That works fine even on Catalina.

Some example code:

dim f as FolderItem = getOpenfolderitem("") if f = Nil then Return f.Launch

I selected a random app and it launched. What are you doing differently?

dim f as FolderItem = SpecialFolder.Applications.Child("App Store.app") if f <> nil and f.exists then system.DebugLog("Trying to launch " + f.ShellPath) f.launch end if

BTW I tried to run 2019R1.1 under Catalina. After dancing in the dock for quite a while, it shows no window and seems to go into hiding like a service. I see it in Activity monitor, though.

That’s a different problem. Specialfolder.Applications is nil. That doesn’t crash for you in the first line?

add

Dim i as integer = f.lastErrorCode if i <> 0 then Msgbox str( i )

after f.launch

If there’s an error, it should give you the code.

You can check OpenFile methods in NSWorkspaceMBS class.

Thank you Christian. I am going to try.

Beatrix, I checked, Specialfolder.Applications is not nil.

Sam, thank you. I did what you suggested, and it reports 101.

I tried to locate error codes in the LR, but nothing conclusive. At any rate I am going to try MBS and report.

Alright. I have to sadly report that NSWorkspaceMBS does not provide the solution.

Not only the code below works on High Sierra but does nothing under Catalina, but I could not find anything in Console to explain why.

At this point I have to conclude that for some reason, Apple must have tighten security in such a way that it is not possible anymore to launch an application from another.

The only solution I have is to test the system version, and if under Catalina, instruct the user to run the pkg himself

[code]dim f as FolderItem = SpecialFolder.Applications
if f = nil then msgbox (f.ShellPath +" is nil")
f = f.Child(“App Store.app”)
if f = nil then msgbox( f.ShellPath +" is nil")
if f <> nil and f.exists then
dim w as new NSWorkspaceMBS
dim file as FolderItem = SpecialFolder.Applications.Child(“App Store.app”)

dim error as NSErrorMBS
dim configuration as new Dictionary
dim options as Integer

// today we start 64 bit version
configuration.Value(w.NSWorkspaceLaunchConfigurationArchitecture) = w.NSBundleExecutableArchitectureX86_64

// and hide all others
options = w.NSWorkspaceLaunchDefault

dim r as NSRunningApplicationMBS = w.launchApplicationAtFile(file, options, configuration, error)
[/code]

https://documentation.xojo.com/api/files/folderitem.html.LastErrorCode

101 	FileNotFound 	The File was not found.

There’s still a lot broken in Catalina right now; I see others in the industry are getting concerned two months may not be enough time to fix all the problems.

I have it on good authority that the issue I reported will most probably no longer present in the next version of Xojo.

This thread may have alarmed unnecessarily. Sorry.

Just want to add for anyone else looking at this; all NSWorkspace API for launching apps has now been deprecated. It appears that we as developers are no longer allowed to launch other applications on a users system. I presume this is for security purposes . Same as the function for zipping/unzipping files.

However [[NSWorkspace sharedWorkspace] openURL:] is still there, so you can ask for a file to be opened, and the OS will open it in whatever application is see’s fit. Just no longer can you specify which application to open the file (which is dumb as I often do this, so that the file is going to open in the application that I expect to, rather than some scammy app that’s commandeered the filetype).

If anyone needs this prior to the launch of the aforementioned Xojo update. Please note that as the API returns a boolean, so does this function.

[code]Public Function launchItem(inFile as folderItem) as boolean
#if targetMacOS then
// — Patch to open a Xojo folderitem using [[NSWorkspace sharedWorkspace] openURL:]
// July 28th 2019 - Sam Rowlands

declare function NSClassFromString lib "Foundation" ( inNSClassName as CFStringRef ) as integer
declare Function NSURLfileURLWithPathIsDirectory lib "AppKit" selector "fileURLWithPath:isDirectory:" _
(NSURLClass as integer, path as CFStringRef, directory as boolean) as integer

declare function NSWorkspaceSharedWorkspace lib "AppKit" selector "sharedWorkspace" ( NSWorkspaceClass as integer ) as integer
declare Function NSWorkspaceOpenURL lib "AppKit" selector "openURL:" ( NSWorkspaceSharedInstance as integer, inNSURL as integer ) as boolean

return NSWorkspaceOpenURL( NSWorkspaceSharedWorkspace( NSClassFromString( "NSWorkspace" ) ), _
   NSURLfileURLWithPathIsDirectory( NSClassFromString( "NSURL" ), inFile.nativePath, inFile.directory ) )

#endif
End Function
[/code]

A scan of the Apple developer docs seems to indicate that you can still state a preferred app via LSOpenFromURLSpec.
https://developer.apple.com/documentation/coreservices/1441986-lsopenfromurlspec

@Michel Bujardet — Well functions using “Alias Records” (or FSRefs) do not seem to work on APFS volumes. I suspect that Xojo is late (as usual) on moving to more up-to-date functions

You an check CFBookmarkMBS module in MBS Xojo Plugins.

If Apple would just leave stuff alone for a while…

I think their motto bas become “Have we broken this lately?”

Not sure they have one motto only. So:
Breaking is fun
Break but don’t tell (developers)
Broken is beautiful