[Mac] Launcher script doesn't pass arguments to SMAPI properly
danvolchek opened this issue ยท 2 comments
Describe the bug
The launcher script doesn't pass arguments to SMAPI properly, so using --mods-path
or --no-terminal
doesn't work.
To Reproduce
If you run:
"/path/to/StardewValley" --mods-path "ModsMP"
you'll get an error:
unrecognized option `--mods-path'
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s <partial SDK name>][-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]
...
This has been seen on macOS Catalina (by Discord user Strobe-#7996
) and macOS Sierra (by Discord user GenStella#3149
).
Fixing the bug
I tried some different ways to fix this, but I couldn't find a fully working solution. Here's what I tried.
Using open
's --args
option
If the open command is changed from
open -a Terminal ./StardewModdingAPI.bin.osx "$@"
to
open -a Terminal ./StardewModdingAPI.bin.osx --args "$@"
The error goes away. However, SMAPI still launches without any --mods-path
argument, so my guess is that Terminal
isn't passing the arguments it received from open
to SMAPI.
Not relying on open
's --args
option
Instead of relying on open
to pass arguments to Terminal
and Terminal
to pass arguments to SMAPI, I tried creating a script that already has the arguments in it:
launch_file=$(mktemp)
cat << EOF > launch_file
./StardewModdingAPI.bin.osx "$@"
rm $launch_file
EOF
chmod +x $launch_file
open -a Terminal $launch_file
This worked fine for me (macOS Mojave) when launching another script file, but I wasn't able to test with SMAPI. Strobe tried with SMAPI and SMAPI didn't run for them - I'm not sure if the OS difference, actually using SMAPI is the problem, or something else is the problem.
Using osascript
instead of open
The osascript
command is able to open new windows and run commands in them much like open
. I tried using this instead of the open command:
osascript -e ' tell app "Terminal"
do script "./StardewModdingAPI.bin.osx '"$@"';exit"
end tell'
This passes the arguments properly but:
- If not run through
Terminal
, Mac shows a permissions dialog box to allow running Applescript and access toTerminal
(the first time only). - If
Terminal
isn't already running, then the SMAPI window doesn't show up until you click on theTerminal
icon in the dock.
As a workaround, we could add environment variable support for the arguments. Then you could do something like this on Linux/Mac:
SMAPI_MODS_PATH="Mods (multiplayer)" /path/to/StardewValley