1

I have a .NET Core app that needs to be opened from a custom URL. It would be passed something like myapp:<base64 params> and this would need to open the app.

Currently, I have a setup somewhat like this (I'm mostly a Windows developer and haven't really touched Mac at all, Linux I'm more familiar with but still not comfortable working in):

  1. URL launches .app which contains AppleScript
  2. AppleScript launches a shell script which forks the dotnet MyApp.dll $1 command into a new process
  3. MyApp.dll launches with the parameter supplied

The issue with this seems to be the AppleScript launcher, as when launching the shell script manually with params the app opens and functions normally. But when launching the URL from a browser (Chrome) the icon appears and quickly disappears in the dock, and the program does not execute. I have no idea how to debug something like this since I've never properly worked with a Mac and I don't know if there's an event viewer or something of the like (usually checking the event viewer would be my step 1 on Windows).

The scripts I'm using:

AppleScript (which then gets made into a .app using the built-in exporter):

on open location this_URL
    do shell script "/Library/MyApp/Launcher " & this_URL
end open location

I edited the Info.plist for the generated .app to add the Custom URL handler:

...
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>com.myapp.urlhandler</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>myapp</string>
        </array>
    </dict>
</array>
...

The shell script (without sh extension) that is used to launch the dll:

#!/usr/bin/env bash
( ( ( dotnet /Library/MyApp/AppFiles/MyApp.dll $1 ) & ) & )

Side Note: The shell script forks once more than should be necessary, but without the extra fork it breaks .NET for some reason. Also adding the & after the $1 seems to cause issues with .NET's argument handling.

I have checked that all the files are in the right places, and when cutting out the AppleScript it runs normally, but I'm not sure how to debug the AppleScript issues. I did have it working before where the AppleScript would directly launch the dll, but that caused a console window which would kill the app when closed, and trying to fork in there didn't seem to work.

Is there a better way of doing this or a workaround that I can use to launch the app from a custom URL without the shell and/or AppleScript bits?

UPDATE: Solved as per my answer below. SE won't let me accept it until 2 days time.

1

So as it would turn out, Apple doesn't like you having multiple copies of an app as backups.

Usually when I'm doing this kind of executable/package work, I keep backups, such as BAK1_Package.exe, BAK2_Package.exe, etc.

It seems that if you have more than one .app that's registered to a URL handler anywhere on your system then Mac uses one of those, and not specifically the one that's in the Applications folder. So when I tried to launch the URL, instead of launching the most recent .app that was placed inside the Applications folder, it was launching the first one that was in the _BACKUP folder on my desktop.

For anyone else who runs into a similar issue like this: make sure you only have one .app registered to that URL handler.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .