-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserv
executable file
·46 lines (38 loc) · 1.06 KB
/
serv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# Check if an executable is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <executable>"
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="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Label</key>
<string>$EXEC_NAME</string>
<key>ProgramArguments</key>
<array>
<string>$EXEC_PATH</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>"
# 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."