Terminal - do shell pause/continue

Hey all,

I’m running a series of commands in the terminal. I don’t want the next command to execute until the first command is completed.

Does anyone know how to accomplish that?

any help would be greatly appreciated,

thanks

Could you post the commands or even better your code.

normally to execute shell commands you should use do shell script and not scripting the terminal.

You can just put “&&” or “;” between the commands.


do shell script "killall Finder && killall Dock"


Here is my overly complicated way of entering commands into Terminal.

property McTmpPath : missing value

tell application "Terminal"
	if (count of windows) is 0 then
		do script
	end if
	activate
end tell
delay 4
set theCommands to {¬
	"cd ~", ¬
	"mkdir MCTMP", ¬
	"cd MCTMP", ¬
	"jar xf ~/Library/Application\\ Support/minecraft/bin/minecraft.jar", ¬
	"PAUSE", ¬
	"rm META-INF/MOJANG_C.*", ¬
	"jar uf ~/Library/Application\\ Support/minecraft/bin/minecraft.jar ./", ¬
	"cd ..", ¬
	"rm -rf MCTMP"}

repeat with i in theCommands
	set TheCommand to i as text
	if TheCommand is "PAUSE" then
		tell application "Finder"
			set McTmpPath to ((path to home folder as text) & "MCTMP" as alias)
			open McTmpPath
		end tell
		tell me to activate
		display dialog "Copy MOD class files into the MCTMP directory.
Then click 'Continue' to finish MOD installation." buttons {"Continue"}
		tell application "Terminal" to activate
	else
		set the clipboard to (TheCommand as text)
		tell application "Terminal"
			tell application "System Events"
				tell process "Terminal"
					click menu item "Paste" of menu "Edit" of menu bar item "Edit" of menu bar 1
				end tell
				keystroke return
			end tell
		end tell
		delay 1
		
		
	end if
end repeat

set app_name to "Terminal"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
if the_pid is not "" then do shell script ("kill -9 " & the_pid)

Lets break this down.

Is there an open Terminal Window? If not make one, otherwise activate Terminal

tell application "Terminal"
	if (count of windows) is 0 then
		do script
	end if
	activate
end tell

The commands I want to preform


set theCommands to {¬
	"cd ~", ¬
	"mkdir MCTMP", ¬
	"cd MCTMP", ¬
	"jar xf ~/Library/Application\\ Support/minecraft/bin/minecraft.jar", ¬
	"PAUSE", ¬
	"rm META-INF/MOJANG_C.*", ¬
	"jar uf ~/Library/Application\\ Support/minecraft/bin/minecraft.jar ./", ¬
	"cd ..", ¬
	"rm -rf MCTMP"}

Processing the commands. If Command is PAUSE do this else do the terminal command. You could change all of that to just a delay. I paste the commands in because the script tends to run a little faster than Terminal accepts the input and instead of sending mkdir MCTMP it would garbel the first few letters and try to send kdmir MCTMP.

repeat with i in theCommands
	set TheCommand to i as text
	if TheCommand is "PAUSE" then
		tell application "Finder"
			set McTmpPath to ((path to home folder as text) & "MCTMP" as alias)
			open McTmpPath
		end tell
		tell me to activate
		display dialog "Copy MOD class files into the MCTMP directory.
Then click 'Continue' to finish MOD installation." buttons {"Continue"}
		tell application "Terminal" to activate
	else
		set the clipboard to (TheCommand as text)
		tell application "Terminal"
			tell application "System Events"
				tell process "Terminal"
					click menu item "Paste" of menu "Edit" of menu bar item "Edit" of menu bar 1
				end tell
				keystroke return
			end tell
		end tell
		delay 1
		
		
	end if
end repeat

Well, everything is done, lets Kill Terminal.

set app_name to "Terminal"
set the_pid to (do shell script "ps ax | grep " & (quoted form of app_name) & " | grep -v grep | awk '{print $1}'")
if the_pid is not "" then do shell script ("kill -9 " & the_pid)

I use the above script for opening the Jar file to install mods into Minecraft.

thanks for the example greatly appreciated.

“&&”

works.

—correction it didn’t work but looks like its smart enough to wait…


tell application "Finder"
	do shell script "cd ~/Desktop/"
	do shell script "sudo -k" --cancels the sudo authentication
	do shell script "sudo spindump" password "--------" with administrator privileges
	do shell script "top -l2 > ~/Desktop/topOutput.txt"
	do shell script "sudo -k" --cancels the sudo authentication
	do shell script "sudo cp /tmp/spindump.txt ~/Desktop/" password "-------" with administrator privileges
end tell