-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToggleBitcoinEmail.applescript
More file actions
49 lines (39 loc) · 1.7 KB
/
ToggleBitcoinEmail.applescript
File metadata and controls
49 lines (39 loc) · 1.7 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
#!/usr/bin/osascript
-- Toggle Bitcoin Email Server on port 1040
-- If running: stops the server
-- If not running: starts the server and opens browser
on run
try
-- Check if server is running on port 1040
set serverRunning to false
try
set pid to do shell script "lsof -ti:1040"
if pid is not "" then
set serverRunning to true
end if
end try
if serverRunning then
-- Server is running, so stop it
do shell script "kill -9 " & pid
display notification "Bitcoin Email server on port 1040 has been stopped" with title "Bitcoin Email" subtitle "Server Stopped" sound name "Pop"
else
-- Server is not running, so start it
display notification "Starting Bitcoin Email server on port 1040..." with title "Bitcoin Email" subtitle "Starting Server" sound name "Pop"
-- Navigate to the project directory and start the server
do shell script "cd '/Volumes/Extreme SSD/Projects/bitcoin-email' && nohup npm run dev -- -p 1040 > /dev/null 2>&1 &"
-- Wait for server to start
delay 4
-- Check if server started successfully
set checkServer to do shell script "lsof -ti:1040 || echo 'failed'"
if checkServer is not "failed" then
-- Open the browser
do shell script "open http://localhost:1040"
display notification "Bitcoin Email server is running on port 1040" with title "Bitcoin Email" subtitle "Server Started" sound name "Glass"
else
display notification "Failed to start server. Check terminal for errors." with title "Bitcoin Email" subtitle "Start Failed" sound name "Basso"
end if
end if
on error errMsg
display notification "Error: " & errMsg with title "Bitcoin Email" subtitle "Error" sound name "Basso"
end try
end run