Repository navigation
Expand file tree
/
Copy pathquickposition.sh
More file actions
executable file
·110 lines (86 loc) · 3.64 KB
/
Copy pathquickposition.sh
File metadata and controls
executable file
·110 lines (86 loc) · 3.64 KB
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
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
# Author: Vincent Nahn
###############################################################################
# ________ ___ ___ ___ ________ ___ __ #
# |\ __ \|\ \|\ \|\ \|\ ____\|\ \|\ \ #
# \ \ \|\ \ \ \\\ \ \ \ \ \___|\ \ \/ /|_ #
# \ \ \\\ \ \ \\\ \ \ \ \ \ \ \ ___ \ #
# \ \ \\\ \ \ \\\ \ \ \ \ \____\ \ \\ \ \ #
# \ \_____ \ \_______\ \__\ \_______\ \__\\ \__\ #
# \|___| \__\|_______|\|__|\|_______|\|__| \|__| #
# \|__| #
# #
# ________ ________ ________ ___ _________ ___ ________ ________ #
# |\ __ \|\ __ \|\ ____\|\ \|\___ ___\\ \|\ __ \|\ ___ \ #
# \ \ \|\ \ \ \|\ \ \ \___|\ \ \|___ \ \_\ \ \ \ \|\ \ \ \\ \ \ #
# \ \ ____\ \ \\\ \ \_____ \ \ \ \ \ \ \ \ \ \ \\\ \ \ \\ \ \ #
# \ \ \___|\ \ \\\ \|____|\ \ \ \ \ \ \ \ \ \ \ \\\ \ \ \\ \ \ #
# \ \__\ \ \_______\____\_\ \ \__\ \ \__\ \ \__\ \_______\ \__\\ \__\#
# \|__| \|_______|\_________\|__| \|__| \|__|\|_______|\|__| \|__|#
# \|_________| #
###############################################################################
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Do not change these names as they are used within the Info.plist files
LEFT="iPad Left.app"
RIGHT="iPad Right.app"
function openDisplaySettings() {
open /System/Library/PreferencePanes/Displays.prefPane
}
# Param1: deviceName
function template() {
echo "#!/bin/bash
function run() {
$(displayplacer list | tail -n 1 | sed 's/^displayplacer /\/opt\/homebrew\/bin\/displayplacer /')
}
function existsMonitor() {
[ \$(/opt/homebrew/bin/displayplacer list | grep \"Persistent screen id\" | wc -l) -ge 2 ]
}
if \$(existsMonitor)
then
run
else
open /Applications/sidecar.app
while ! \$(existsMonitor); do
sleep .5
done
run
fi
"
}
# Confirm
function confirm() {
read -p "$1" -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
}
# Welcome Screen
echo "Welcome to QuickPosition."
echo "What is the name of your iPad?"
read -p "$1" -n 25 -r
DEVICE_NAME=$REPLY
cat ./sidecar.applescript | sed "s/iPadName/$DEVICE_NAME/g" | osacompile -o sidecar.app
rm -rf /Applications/sidecar.app
cp -R ./sidecar.app /Applications/
confirm "The display settings are going to open. First, position your iPad to the left side of your MacBook (Press y to continue) "
# Left side
openDisplaySettings
confirm "Did you position your iPad to the LEFT? (Press y to continue) "
template $DEVICE_NAME > "${SCRIPT_DIR}/${LEFT}/Contents/MacOS/iPadLeft"
# Right side
openDisplaySettings
confirm "Did you position your iPad to the RIGHT? (Press y to continue) "
template $DEVICE_NAME > "${SCRIPT_DIR}/${RIGHT}/Contents/MacOS/iPadRight"
# Set the execute permissions
chmod +X "${SCRIPT_DIR}/${LEFT}/Contents/MacOS/iPadLeft"
chmod +X "${SCRIPT_DIR}/${RIGHT}/Contents/MacOS/iPadRight"
# Copy the two folders into /Applications
rm -rf "/Applications/${LEFT}"
rm -rf "/Applications/${RIGHT}"
cp -R "$LEFT" "/Applications"
cp -R "$RIGHT" "/Applications"
# Exits
echo "Thank you for using Quick Position!"
echo "You can now remove the cloned directory."