Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An automation setup example #7

Open
schmidt9 opened this issue Jul 27, 2022 · 1 comment
Open

An automation setup example #7

schmidt9 opened this issue Jul 27, 2022 · 1 comment

Comments

@schmidt9
Copy link

Just sharing example script to automate shutdown setup without original files modification (working with copies), might be appended to readme and be helpful

#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
EXECUTABLE_COMMAND="killall Simulator"

#setup paths

REPO_DIR_NAME="macosx-script-boot-shutdown"
REPO_PLIST_NAME="boot-shutdown-script.plist"
REPO_SCRIPT_NAME="boot-shutdown.sh"

REPO_WORKING_DIRECTORY="$SCRIPT_DIR/$REPO_DIR_NAME"
REPO_LOG_PATH=$SCRIPT_DIR

REPO_CUSTOM_PLIST_PATH="$SCRIPT_DIR/$REPO_PLIST_NAME"
REPO_CUSTOM_SCRIPT_PATH="$SCRIPT_DIR/$REPO_SCRIPT_NAME"

#create plist & script copy

cp "$REPO_WORKING_DIRECTORY/$REPO_PLIST_NAME" $REPO_CUSTOM_PLIST_PATH
cp "$REPO_WORKING_DIRECTORY/$REPO_SCRIPT_NAME" $REPO_CUSTOM_SCRIPT_PATH

#replace vars in custom plist

sed -i '' "s#SCRIPT_PATH#$REPO_WORKING_DIRECTORY#g" "$REPO_CUSTOM_PLIST_PATH"
sed -i '' "s#LOG_PATH#$REPO_LOG_PATH#g" "$REPO_CUSTOM_PLIST_PATH"
sed -i '' "s#.*AT SHUTDOWN.*#$EXECUTABLE_COMMAND#g" "$REPO_CUSTOM_SCRIPT_PATH"

#setup launch daemon

sudo cp $REPO_PLIST_NAME  /Library/LaunchDaemons/
sudo launchctl load -w "/Library/LaunchDaemons/$REPO_PLIST_NAME"
@freedev
Copy link
Owner

freedev commented Jan 17, 2024

Hi @schmidt9, thanks for sharing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants