Calling an app from the terminal via script
I try to call an application from the console and pass it an argument. This is the script I am using:
#!/bin/sh
open -a "/Applications/MyApp.app/" $1
Somehow the OS is unhappy with this and complains:
FSPathMakeRef(/Applications/MyApp.app) failed with error -43.
What can I do?
That looks like /Applications/MyApp.app doesn't actually exist.
You can test for that in your script, perhaps like this:
#!/bin/sh
APP=/Applications/MyApp.app
if [ ! -d "$APP" ]; then
echo >&2 "$0: $APP not found."
exit 1
fi
exec open -a "$APP" "$@"
You can make sure the application exists before calling open
on it! Here's a quick bit of Bash to do this:
if [ -d "/Applications/MyApp.app" ]; then
open -a "/Applications/MyApp.app"
else
echo "Application /Applications/MyApp.app does not exist!"
fi