Repository navigation
Expand file tree
/
Copy pathstop_mac.command
More file actions
executable file
·82 lines (70 loc) · 1.95 KB
/
Copy pathstop_mac.command
File metadata and controls
executable file
·82 lines (70 loc) · 1.95 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
#!/bin/zsh
set -u
cd "$(dirname "$0")"
PORT=8765
URL="http://127.0.0.1:${PORT}"
echo "WD CrystalChain"
echo "Stopping local server on ${URL}"
echo
PIDS=$(lsof -nP -tiTCP:${PORT} -sTCP:LISTEN 2>/dev/null || true)
if [ -z "${PIDS}" ]; then
echo "No CrystalChain server was found on port ${PORT}."
else
for PID in ${(f)PIDS}; do
if [ -n "${PID}" ]; then
echo "Stopping process ${PID}..."
kill "${PID}" 2>/dev/null || true
fi
done
sleep 1
STILL_RUNNING=$(lsof -nP -tiTCP:${PORT} -sTCP:LISTEN 2>/dev/null || true)
if [ -n "${STILL_RUNNING}" ]; then
for PID in ${(f)STILL_RUNNING}; do
if [ -n "${PID}" ]; then
echo "Force stopping process ${PID}..."
kill -9 "${PID}" 2>/dev/null || true
fi
done
fi
echo "Server stopped."
fi
osascript >/dev/null 2>&1 <<'APPLESCRIPT' || true
set targetText to "127.0.0.1:8765"
tell application "System Events"
set chromeRunning to exists process "Google Chrome"
set safariRunning to exists process "Safari"
end tell
if chromeRunning then
tell application "Google Chrome"
repeat with chromeWindow in windows
set tabsToClose to {}
repeat with chromeTab in tabs of chromeWindow
if (URL of chromeTab) contains targetText then
set end of tabsToClose to chromeTab
end if
end repeat
repeat with chromeTab in tabsToClose
close chromeTab
end repeat
end repeat
end tell
end if
if safariRunning then
tell application "Safari"
repeat with safariWindow in windows
set tabsToClose to {}
repeat with safariTab in tabs of safariWindow
if (URL of safariTab) contains targetText then
set end of tabsToClose to safariTab
end if
end repeat
repeat with safariTab in tabsToClose
close safariTab
end repeat
end repeat
end tell
end if
APPLESCRIPT
echo "Local browser tabs were closed if macOS allowed it."
echo
read -k 1 "?Press any key to close..."