-
Notifications
You must be signed in to change notification settings - Fork 0
/
PNPMacParam.sh
executable file
·100 lines (83 loc) · 2.51 KB
/
PNPMacParam.sh
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# List of Display names
# You can add as many as you want (separated by a space)
# Ex: listDisplayNames=("Display Name" "Other Display Name")
listDisplayNames=()
# List of Wi-Fi names
# You can add as many as you want (separated by a space)
# Ex: listWifiNames=("Wifi Name" "Other Wifi Name")
listWifiNames=()
# List of Apps to open
# You can add as many as you want (separated by a space)
# Ex: listAppToOpen=("App Name" "Other App Name" "Other App Name")
listAppToOpen=()
# Max battery level when connected (suggest 77)
batteryValue=80
##########################################################################
#
### DON'T MODIFY THE CODE BELOW THIS LINE
#
##########################################################################
# Delay in seconds (default 60 seconds)
seconds4Delay=60
# main script
isRunning=false
# Caffeinate
isCaffeinate=false
# BCLM
isBclm=false
# Apps
areAppsOpen=false
# Check two times if the second monitor is connected before continue
firstTime=true
lastUpdateTime=""
# ID of the last active caffeinate process (0 at start of the script)
PMSETPID=0
# main directory
parentPath=/usr/local/bin/PlugNPlayMac
# App not founded in the Application folder
notFoundedApp=()
getUSR() {
# Take the full name of the user
local my_var
my_var=$(id -F)
echo "$my_var"
}
# Get the full name of the user
accountUser=$(getUSR)
getPW() {
# Take the password from Apple Keychain for operating the sudo operation
local my_var
my_var=$(security find-generic-password -w -s "PlugNPlayMac" -a "$accountUser" 2>/dev/null)
if [[ -z $my_var ]]; then
date_string=$(date +"%b %d %Y - %H:%M")
echo "$date_string: The password doesn't exist yet"
fi
echo "$my_var"
}
detect_cpu_architecture() {
architecture=$(uname -m)
local my_var
if [[ "$architecture" == *"arm64"* ]]; then
echo "$date_string: Apple Silicon CPU architecture detected"
my_var=true
elif [[ "$architecture" == *"x86_64"* ]]; then
echo "$date_string: Intel CPU architecture detected"
my_var=false
else
date_string=$(date +"%b %d %Y - %H:%M")
echo "$date_string: Problem during the detection of the CPU architecture"
exit 1
fi
echo "$my_var"
}
log_error() {
local msg_type="$1"
local isAppleSilicon="$2"
local msg_text="$3"
local date_string=$(date +"%b %d %Y - %H:%M")
if [ -n "$isAppleSilicon" ]; then
echo "$date_string: (A$msg_type): $msg_text"
else
echo "$date_string: (I$msg_type): $msg_text"
fi
}