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):
- URL launches .app which contains AppleScript
- AppleScript launches
a shell script which forks the
dotnet MyApp.dll $1command into a new process
MyApp.dlllaunches 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.