Non blocking do shell script?

Is there any way to do this?

Describe a little more; you initiate one shell process that takes a while so a second doesn’t proceed (or you don’t get your script to continue because it’s waiting for stout from the first). Have you tried simply writing the first somewhere else and then initiating the second with a separate do shell script? You could check the file size of the “somewhere else” by looking at the first word of du -d 0 periodically and waiting for it to stabilize. Are you piping the first to the second?

Whats happening is i got somescripts i use to launch x11 based programs and i run the script and it keeps running till i quite the program im running, and for some reason if i try to run another one of the scripts while the other is running it doesn’t work, then all of a sudden after i quite the first script(well not script but close the program that i started with do shell script) the second one that wasnt running starts running as if it was just waiting for the first to finish(i dont try to open it a second time).
Heres the basic source for the scripts:


tell application "Finder"
	open application file "X11.app" of folder "Utilities" of folder "Applications" of startup disk
end tell
do shell script "export DISPLAY=:0; program" with administrator privileges

I did try appending & on the the end of the command but that didn’t do it.

AppleScript is single-threaded; only one script at a time will run, so something is hanging the first script.

There’s an “open” instruction in Bash that is equivalent to double-clicking an icon in the Finder. Why not use it for the first bit? open /Applications/Preview.app will start Preview, I don’t have X11. The AppleScript is satisfied when X11 opens and the do shell returns a 0 for mission accomplished, and goes on to the next bit. Another approach is “ignoring application responses … end ignoring”

Ya its the do shell script is not ending i already figured that part out, lame … na i have to do the do shell script, open wont work i just tried really gay… ok thanks for the help either way.

AppleScript’s do shell script holds the process’ stdout and stderr hooks waiting for the output of the command. That’s why it appears to hang - it’s doing what it’s designed to do.

The solution is simple - you redirect stderr and stdout to some other location and send the shell process to the background:

do shell script "/bin/sleep 60 > /dev/null 2>&1 &"

the > /dev/null redirects the process’ stdout to /dev/null (you can use some other file path if you want to capture its output). 2>&1 redirects stderr to the same place as stderr (in this case, /dev/null) and the trailing & sends the process to the background.

You’ll find that this effectively returns control back to your script while the shell process runs in the background.

I knew it was doing what it was designed to but what it was designed to do was pissing me off :frowning: Thank you that worked perfectly :smiley: i owe you a beer.