#!/bin/bash
# Application name as parameter
APP_NAME="$1"
# System app directory
SYSTEM_APP_DIR="/Applications"
# Current User
CURRENT_USER=
stat -f%Su /dev/console
# Home folder of current user
HOME_FOLDER=$(dscl . -read /Users/"$CURRENT_USER" NFSHomeDirectory | cut -d: -f2 | xargs)
# Current user application directory
USER_APP_DIR="$HOME_FOLDER/Applications"
# Create if user has no Application folder
if [ ! -d "$USER_APP_DIR" ]; then
/bin/mkdir "$USER_APP_DIR"
/bin/chmod 755 "$USER_APP_DIR"
/usr/sbin/chown "$CURRENT_USER" "$USER_APP_DIR"
else
if [ -d "$USER_APP_DIR/$APP_NAME" ]; then
echo "App already exists in user's Applications folder"
exit 0
fi
fi
# Copy from system folder to user folder
/bin/cp -R "$SYSTEM_APP_DIR/$APP_NAME" "$USER_APP_DIR"
# Move from system folder to user folder
# /bin/mv "$SYSTEM_APP_DIR/$APP_NAME" "$USER_APP_DIR/$APP_NAME"
exit 0