Erel, thanks for trying. I found a work-around. It is more complex. I was hoping you would be successful before I fully implement this approach.
Step 1. Set up a helper application (e.g. xxxOpener) using Mac “Automator.app” that will run the bash script
open -a xxx –args pathoffile
where xxx is your application and pathoffile is the path of your double-clicked file. The path will be passed into B4J variable ‘main.appnames’
Step 2. Set file association to your application using a bash program called “duti”. It requires your application's "id" that can be found using command ‘mdls’.
Appid = $(mdls -name kMDItemCFBundleIdentifier -r pathtofile/xxx.app)
./duti -s $appid .pbn all #.pbn is an example extension
Step 3. Automate this process by incorporating duti commands into a script file and zipping it with duti.exe. Save it to File.DirAssets. When running your B4j program for the first time, unzip these files and run the script file to set associations using "shell" command in B4j.
Step 4. After MacSigner, run Packages (use "Raw Package" template) and put both your application (xxx) and the your helper application (xxxOpener) in the Application folder (using PayLoad Tab). This will create a single installation file (.pkg) for both your applications.
Here are some details for step 1:
1. Open
Automator (in Applications folder) and select
New Document >
Application.
2. Search for the
"Run Shell Script" action and drag it into the workflow area.
3. Set the following options:
- Shell: /bin/bash (or /bin/zsh)
- Pass input: "to as arguments".
- Insert following code.
for f in "$@"
do
# $f contains the full POSIX file path
open -a yourapplicationhere –args “$f”
done
Here are some details for Step 2
- Duti will allow you to set associations on a Mac using terminal. On Mac, load duti using Homebrew. After installing Homebrew, type "brew install duti" in terminal
- Find location of installed bin file. Alias is typically at /usr/local/bin/duti. From Alias, find true location of .exe.
- Note - To see hidden files on a Mac, pressing Command + Shift + “.”
- Actual path will be something like: /usr/local/Cellar/duti/1.5.4_1/bin/duti
- Move duti file to unrestricted location like “/documents”.
- If you want to test duti in terminal, here are some test commands:
mdls -name kMDItemCFBundleIdentifier -r pathofapplication/xxs.app #to get appid; e.g. “fdp.xxx.macrelease”
./duti -s fdp.xxx.macrelease .pbn all #to set associations
./duti -x pbn #to check if association is set
- To Remove association, go to pbn file. Right click>Get Info>Open with>(Change it to something else)>Change All
- Notes - ./ required when running unix executable files in terminal.
Here is my sample script. Saved as “myscript.sh.”
#!/bin/bash
appname=/Applications/$1.app #$1 is first argument with calling script
if [ -d $appname ]; then #check if appname exists in computer wide application folder
name=$(mdls -name kMDItemCFBundleIdentifier -r $appname) #to get app identifier name
else
appname1=~/Applications/$1.app #~indicates local
name=$(mdls -name kMDItemCFBundleIdentifier -r $appname1) #check local application folder
fi
chmod +x "duti" #for permissions
./duti -s $name .pbn all #to set associations
./duti -x pbn #to check if association is set
Here is some details on Step 3.
After unzipping in B4j, run the script as:
Dim shlDD As Shell
shlDD.Initialize("shlDD", "bash", Array As String("myscript.sh", "xxxOpener"))
shlDD.WorkingDirectory = DutiFullPath
shlDD.RunWithOutputEvents(10000) 'set a timeout