Backgrounding a Process

Most of the processes I kick off with ASS are relatively finite, so It’s really no big deal to wait until they’re done. However, I’ve now come across a process that would tie up my app indefinately. Of course, I can launch it via the Terminal application, thus freeing my ASS app, but I’d like to not have to use the Terminal.app to do so. Anyone know of a way to force a process to the background freeing the ASS app to do other tasks?

See this thread:

http://bbs.applescript.net/viewtopic.php?pid=30674#p30674

Jon

Hi Dean,

You can try using ‘ignoring’. Something like this:

ignoring application responses
tell app “SomeApp”
– do whatever
end tell
end ignoring

gl,

Thanks,

the information in the technote was helpful, and it allowed me to start the process, but there’s no way to terminate the process without heading towards the command line. This is a very different type of process that a normal shell command, and it ties up everything, the menus, buttons, etc. I wish it were easier, but I think I’m going to have to stick with the Terminal as a solution, because essentially that hands off the process to the Terminal and releases the ASS app. Here’s the code I’m using that I’ve modeled per the tech note’s suggestion, but isn’t working:

do shell script "long command with options &  > /dev/null &" user name adminName password adminPass with administrator privileges

This doesn’t work? Make two buttons named “start” and “end”, attach them to your script, and try this:

property the_pid : ""

on clicked the_object
	set object_name to the_object's name as Unicode text
	if object_name = "start" then
		set the_pid to (do shell script "long command with options  > /dev/null >&1 & echo $!" user name adminName password adminPass with administrator privileges)
	else if object_name = "end" then
		if the_pid is not "" then do shell script ("kill -9 " & the_pid) user name adminName password adminPass with administrator privileges
		set the_pid to ""
	end if
end clicked

Jon

This works quite well, thanks!

Now, the only problem is figuring out how to monitor the status of the background task. So far, It looks like it’ll have to be an idle handler (blech). I have tried to start both the process to monitor the background task and the background task at the same time, but no go. Later this week, I’ll try it with the monitor launching first.