#!/bin/bash # Check if an executable is provided as an argument if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi # Find the executable path using 'which' EXEC_PATH=$(which "$1") # Check if the executable exists if [ -z "$EXEC_PATH" ]; then echo "Error: Executable '$1' not found." exit 1 fi # Get the executable name EXEC_NAME=$(basename "$EXEC_PATH") # Create the launchd plist file content PLIST_FILE_CONTENT=" Label $EXEC_NAME ProgramArguments $EXEC_PATH KeepAlive RunAtLoad " # Create the launchd plist file PLIST_FILE="$HOME/Library/LaunchAgents/$EXEC_NAME.plist" echo "$PLIST_FILE_CONTENT" > "$PLIST_FILE" # Load the launchd service launchctl load "$PLIST_FILE" echo "Service '$EXEC_NAME' has been created and loaded."