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

Categories

0 votes
580 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...