Reputation: 150
I am running an experiment in a remote host and to to that i have a shell script that does some tasks, calls osascript that launches several terminal windows that perform some of the tasks, some inside an ssh session, then closes.
Now in order to do that i have to keep the terminal window in in context so when it is time to close i can keystroke the terminate and then accept the drop down menu asking if i want to quit (because ssh open). If i have for example safari open and am browsing this closes the browser.
My question is if there is a better way to do this because i have to keep always this terminal window, with its 6 tabs, open and this does not give me liberty to do other tasks meanwhile
Bellow is my snippet
osascript -e 'tell app "Terminal"
do script ""
delay 0.2
do script "
/*do stuf inside ssh*/
" in tab 1 of front window
delay 0.2
my makeTab()
do script "
/*do stuf here*/
" in tab 2 of front window
delay 0.2
my makeTab()
do script "
/*do stuf here*/
" in tab 3 of front window
delay 0.2
my makeTab()
do script "
/*do stuf inside ssh*/
" in tab 4 of front window
my makeTab()
do script "
/*do stuf here with tshark */
tshark -i en0 -f \"udp dst port 5683 or udp src port 5683\" -w sink.pcap
" in tab 5 of front window
my makeTab()
do script "
/*do stuf here*/
" in tab 6 of front window
delay '$CLOSE_WINDOW_DELAY'
my ending()
end tell
on makeTab()
tell application "System Events" to keystroke "t" using {command down}
delay 0.5
end makeTab
on ending()
tell application "System Events" to keystroke "w" using {command down, shift down}
delay 0.9
tell application "System Events" to keystroke return /*for the question due to ssh session*/
end ending
'
Thank you in advance
Upvotes: 1
Views: 1125
Reputation: 3535
If you do NOT need to receive and Process answers of your script, this is way faster - taking advantage of background threading:
set myScript to "some shell command here"
do shell script myScript &" > /dev/null 2>&1 &"
The '> /dev/null' suppresses stdout; '2>&1' suppresses stderr (specifically, sends stderr to the same place as stdout), and the trailing '&' puts the command in the background.
Using this suffix will return control to your AppleScript immediately, leaving the shell process running in the background. So you can launch different commands simultaneously.
If you want to receive answers:
set theAnswer to do shell script myScript
In this case the process will wait for the answer.
Upvotes: 1