UI Command queuing?

Is there a way to have a button press (I have a long series of if-then statements for the onObject button) queue until a currently running script has finished instead of interrupting it? Forgive me if this is a basic question. Thanks. :slight_smile:

-Evan

The best way is to have a property variable hold a key that determines whether some code can run or not. When the button is pressed to start an action, it also sets a variable which limits functionality on subsequent presses. You can also use this in conjunction with setting the enabled property of any controls which might trigger the action again. For example…

property currentlyDoingSomething : false

on clicked theObject
	if name of theObject is "startSomething" then
		if (not currentlyDoingSomething) then --> Only execute if were not already doing it
			toggleDoingSomething(true)
			--> Do some stuff
		else
			display dialog "You're already doing something!"
		end if
	else if name of theObject is "stopSomething" then
		toggleDoingSomething(false)
		--> Process your stuff
	end if
end clicked

to toggleDoingSomething(isDoing)
	set currentlyDoingSomething to isDoing
	set enabled of button "startSomething" of window "someWindow" to (not isDoing)
end toggleDoingSomething

I realize that this only addresses the question of keeping something from running if it’s already running. It does not add it to a queue and run it after other running processes are all done. If you really NEED to have a queue, rather than telling the user to just be patient and press the button later, then you have to get creative. What you could do, is keep track of a list of references to certain actions that you may want to do in a list variable. At the end of doing whetever you do, evaluate the list and see if it contains any references to any actions. If it does, then run them. This get complicated for many reasons. The script might need user interaction to do your whatever, it may get complicated to create the queue, the user may hit the start button a bunch of times and the app may hang, I could go on and on. Generally, in ASStudio apps it’s probably best to do something… wait for a result… then allow the user to do something else. Creating a queue is complicated, and because asstudio apps run by default on a single thread, you don’t really have the luxury of just doing something in the background while the user piles up a queue of things to do. It’s not that it can’t be done, it is just complicated… the level of complexity being dictated by how complex the tasks you’re queuing(sp?) are.

j

I had already done what you suggested as far as disabling the command if it is running, so thanks for that great advice. :slight_smile: You are right though, it only solves part of my problem. The user in this case will likely be VERY impatient, so I should figure out how to queue the commands. What about incrementing a variable with each button push and then checking the value of that variable at the end of the command and running the command that many times, decrementing it with each pass? Does that make sense? Is there a better way that someone has used? Thanks again for all the help. :slight_smile:

-Evan