Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

applescript - Process not running in background

I am trying to make an apple script that launches Alacritty and tmux. I have all the parts except the script runs while I'm running Alacritty and I would like it to exit soon after running (in both cases, where a tmux session exists and when it doesn't).

set t to (time of (current date))

do shell script "nohup /Applications/Alacritty.app/Contents/MacOS/alacritty -e /usr/local/bin/tmux attach || tmux new -s general > /dev/null 2>&1 &"

if (time of (current date)) < t + 1 then
do shell script "nohup /Applications/Alacritty.app/Contents/MacOS/alacritty -e /usr/local/bin/tmux new -s general > /dev/null 2>&1 &"
end if

This works as I'd hoped when there isn't a tmux session, but it runs until I quit Alacritty.

I think the solution will be related to job control in AppleScript, but I can't figure it out. I essentially need a way to wait for a second or two and then test if it is running or something.

question from:https://stackoverflow.com/questions/65559759/process-not-running-in-background

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Okay I figured out another way:

do shell script "nohup /Applications/Alacritty.app/Contents/MacOS/alacritty -e /usr/local/bin/tmux new -A -s general > /dev/null 2>&1 &"

This combines both.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...