Forked from depressiveRobot/osx-intellij-set-path.sh
Last active
February 17, 2019 16:02
-
-
Save seasonyuu/7b75c2b6ad3cb6f78861963c716b1b5f to your computer and use it in GitHub Desktop.
Modifies the app package to start Android Studio inside a shell with a custom PATH environment variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ "$#" -lt 2 ]; then | |
echo "Too few arguments\n" | |
echo "Usage: $0 'PATH TO ANDROID STUDIO APP' 'PATH_VALUE'" >&2 | |
exit 1 | |
fi | |
if [ "$#" -gt 2 ]; then | |
echo "Too many arguments\n" | |
echo "Usage: $0 'PATH TO ANDROID STUDIO APP' 'PATH_VALUE'" >&2 | |
exit 1 | |
fi | |
if ! [ -e "$1" ]; then | |
echo "'$1' not found\n" >&2 | |
echo "Usage: $0 'PATH TO ANDROID STUDIO APP' 'PATH_VALUE'" >&2 | |
exit 1 | |
fi | |
# add shell script to app package | |
cat > "$1/Contents/MacOS/studio.sh" <<- EOF | |
#!/bin/sh | |
export PATH="$2" | |
logger "\`dirname \"\$0\"\`/studio" | |
exec "\`dirname \"\$0\"\`/studio" \$@ | |
EOF | |
# make shell script executable | |
chmod +x "$1/Contents/MacOS/studio.sh" | |
# run shell script when starting app | |
defaults write "$1/Contents/Info" CFBundleExecutable studio.sh | |
# writing the plist converts it to binary format, convert it back to xml | |
plutil -convert xml1 "$1/Contents/Info.plist" | |
# re-register to launch services database | |
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment