Created
September 23, 2020 16:08
-
-
Save rharter/c4b8c5139c273bceb45c3fb8747055b7 to your computer and use it in GitHub Desktop.
Using this script you can create a tiny macOS app that will always launch the latest version of any JetBrains Toolbox installed IDE. Simply pass the target IDE application as the first argument and the script will create a launcher that you can add to your dock that will always point to the latest installed version of the IDE.
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/bash | |
APP_DIR=$1 | |
APP_SCRIPT_NAME="$(ls "${APP_DIR}/Contents/MacOS/")" | |
APP_FILE_NAME="$(basename "${APP_DIR}")" | |
CHANNEL_DIR="$(dirname "$(dirname "$1")")" | |
CHANNEL_NAME="$(basename "$CHANNEL_DIR")" | |
TOOLBOX_APP_NAME="$(basename "$(dirname "$CHANNEL_DIR")")" | |
TOOLBOX_DIR=${APP_DIR%/apps/*} | |
LAUNCHERS_DIR="${TOOLBOX_DIR}/launchers" | |
if [ ! -d "${LAUNCHERS_DIR}" ];then | |
echo Creating launcher directory: ${LAUNCHERS_DIR} | |
mkdir -p "${LAUNCHERS_DIR}" | |
fi | |
LAUNCHER_PATH="${LAUNCHERS_DIR}/${APP_FILE_NAME}" | |
if [ -d "${LAUNCHER_PATH}" ];then | |
echo Launcher already exists at path ${LAUNCHER_PATH} | |
echo exiting. | |
exit 1 | |
fi | |
# Create the launcher directory structure | |
echo Creating launcher at path: ${LAUNCHER_PATH} | |
mkdir -p "$LAUNCHER_PATH/Contents/MacOS" | |
# Link the existing | |
ln -s -f "$APP_DIR/Contents/Info.plist" "$LAUNCHER_PATH/Contents/Info.plist" | |
ln -s -f "$APP_DIR/Contents/Resources" "$LAUNCHER_PATH/Contents/Resources" | |
LAUNCHER_SCRIPT_PATH="$LAUNCHER_PATH/Contents/MacOS/$APP_SCRIPT_NAME" | |
function write() { | |
echo "$1" >> "$LAUNCHER_SCRIPT_PATH" | |
} | |
write '#!/bin/sh' | |
write '' | |
write 'DIR="$(dirname "$0")"' | |
write 'BASE_DIR="$DIR/../../../../apps/'"$TOOLBOX_APP_NAME"'/'"$CHANNEL_NAME"'"' | |
write 'SUFFIX="Contents/MacOS/'"$APP_SCRIPT_NAME"'"' | |
write '' | |
write 'release_dirname=$(ls "$BASE_DIR" | sort -r | head -n 1)' | |
write 'release_dir="$BASE_DIR/$release_dirname"' | |
write '' | |
write 'app_dir="$release_dir/'"$APP_FILE_NAME"'"' | |
write 'app_path="$app_dir/$SUFFIX"' | |
write '' | |
write '# Make sure the info.plist and resources are current.' | |
write 'ln -s -f "$app_dir/Contents/Info.plist" "$DIR/../Info.plist"' | |
write 'ln -s -f "$app_dir/Contents/Resources" "$DIR/../Resources"' | |
write '' | |
write '"$app_path"' | |
echo Making launcher script executable... | |
chmod +x "$LAUNCHER_SCRIPT_PATH" | |
echo Successfully created launcher for $APP_FILE_NAME in channel $CHANNEL_NAME | |
open "$LAUNCHERS_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
EDIT: seems like PyCharm does not see environment variables, like
PATH
, when launched this wayDeleting JetBrains Toolbox and launching PyCharm directly still seems like the best solution