Page 1 of 4
window management
Posted: Wed Mar 20, 2013 11:53 pm
by adventuresofgreg
Hello. I am looking for a way to manage a number in instances of a LiveCode standalone running in windows. Ideally, I want to make a standalone with a scrolling list of all LC apps currently running, and clicking on a line will bring that running SA app to the front. I assume this would have to be done using a shell and a windows command line. But, as far as I can tell, there is no command for making a window 'active'.
If I was running these SA instances on a Mac, I could simply "launch" the SA, and if it is already running, it would become active. But this doesnt work on WIndows because re-launching an app, launches a new instance of the app.
Thanks
Greg
Re: window management
Posted: Wed Mar 20, 2013 11:58 pm
by Simon
Check out topStack in the dictionary
Simon
EDIT: or
go stack "myStack"
Re: window management
Posted: Thu Mar 21, 2013 12:25 am
by adventuresofgreg
Thanks Simon, but from what I can tell, topstack returns the name of a stack in front, but doesn't set a standalone app (stack) to the front. Also, it appears that mainstacks function will return a list of all stacks running, but I doubt it would return a list of all instances of a standalone running, as WIndows see's each instance of a standalone as it's own unique exe.
Re: window management
Posted: Thu Mar 21, 2013 12:34 am
by bn
Hi Greg,
have a look at "relaunch" in the dictionary. That message should take care of multiple instances on Windows. I don't have a Windows computer to test it.
Kind regards
Bernd
Re: window management
Posted: Thu Mar 21, 2013 12:54 am
by adventuresofgreg
Thanks Bernd. I just tried relaunch, and it will stop the standalone from launching multiple instances of itself (like OSX), however, upon a relaunch attempt, the result is NOT to bring the already launched standalone to the front (as it would - from what I recall - in OSX).
I remember a way back in the HyperCard days, I had written a 'launcher' stack that would build a list of my apps, and launch the one I selected. You could also use it to switch between currently running apps as well, because in OSX, once an app is running, it won't run another instance of it, and instead, will make the already running app to the front. (I think...)
This is basically what I need to do - but in Windows - with multiple instances of the same LC stack (as standalones)
Thanks
Re: window management
Posted: Thu Mar 21, 2013 1:29 am
by Simon
How about using vbs?
Code: Select all
put "set WshShell = WScript.CreateObject("WScript.Shell")" & cr & "WSHShell.AppActivate "LiveCode 5.5.3" into tVbs
do tVbs as VBscript
Replace that LiveCode stuff with your app name.
Probably should check the platform first.
Simon
EDIT I messed up... let me figure this out
Re: window management
Posted: Thu Mar 21, 2013 2:33 am
by bn
Hi Simon,
maybe there is a VB command to bring an application to the front. That could be triggered by the relaunch message Gregg's app gets on launch.
As far as I see that is the only problem that remains. But I just have no idea how this would work on Windows.
Kind regards
Bernd
Re: window management
Posted: Thu Mar 21, 2013 2:38 am
by Simon
Ok I got it:
Code: Select all
on mouseUp
put "set WshShell = WScript.CreateObject(""e&"WScript.Shell""e&")" & cr & \
"WSHShell.AppActivate ""e&"notepad""e&"" into url "file:focus.vbs"
launch document "focus.vbs"
wait 1 second with messages
delete file "focus.vbs"
end mouseUp
replace "notepad" up there with your app
Note: you can use just "note" in the example above and it will find "notepad" it looks for the closest match. Might be of some help.
I was only able to get it to work if it was written to a file, not ideal
Simon
Re: window management
Posted: Thu Mar 21, 2013 3:44 am
by Simon
Sorry I keep updating:
Code: Select all
on mouseUp
set hideConsoleWindows to true
get shell("tasklist")
put it into tTask
put "notepad" into tProg
if tProg is in tTask then
put "set WshShell = WScript.CreateObject(""e&"WScript.Shell""e&")" & cr & \
"WSHShell.AppActivate ""e& tProg "e&"" into url "file:focus.vbs"
launch document "focus.vbs"
wait 1 second with messages
delete file "focus.vbs"
else
answer "app not running"
end if
end mouseUp
I've added the shell to make sure your app is running first otherwise it might just focus the nearest named app.
You probably want to put that shell stuff into the openCard or somewhere so you only have to run it once... or maybe not? (you might start and stop apps randomly).
The name of your standalones should be unique (I found that adding .exe to the end didn't focus on the app).
Simon
Re: window management
Posted: Thu Mar 21, 2013 4:04 pm
by adventuresofgreg
Thanks Simon - you are brilliant! It works. Only issue now, is I have to figure out a way to change the name of each standalone instance because if there are duplicate names running at the same time, the script won't work. Is it even possible for a standalone to change it's name?
thinking... Each instance of the standalone opens it's own data file. I could manually change the NAME of the standalone to reflect the data file that it is supposed to open. Then, rather than manually loading in the data file after I launch each instance of the SA, the SA could just automatically open it's own data file depending on it's name. That way, I would have uniquely named SA's to window manage... And easy start up procedure by simply launching all the SA's.
Re: window management
Posted: Thu Mar 21, 2013 9:10 pm
by Simon
I'm glad it's working for you
As I think about it, since your standalones were made with LC... Shouldn't they be substacks of your "control panel"?
Think about how much more you could do with them:
go stack "myStack" would work, you could open all of them at once or any of them. Bring any of them into focus.
All the substacks could communicate with each other.
Control their size and position via your control panel.
But most of all, be wickedly cool.
It's easy to at least try out, just set the main stack to your control panel.
Simon
Re: window management
Posted: Thu Mar 21, 2013 9:18 pm
by sturgis
My suspicion is that separate instances are needed so that a pseudo type of multiprocessing can be done. (otherwise yeah i'm with you, just "go stack.." ) For some applications though popping up several instances can drastically decrease the time it takes to accomplish a task since each process can grab a separate core. (I've messed with this method as well as laying jobs off on several web servers running lc server on my network.. Pretty cool stuff!) Think one of the marks (I get confused) also put together a progress bar stack that is its own engine instance so that its easier to have a smoothly updating bar. I forget the details but seem to recall that it was pretty slick.
Of course, now i'm curious to know whats being done that might require the multiple instances!
EDIT: Also just remembered, if running on a mac I think you can still "send to program.." and call handlers directly to other instances.
Re: window management
Posted: Thu Apr 11, 2013 5:42 pm
by adventuresofgreg
Simon: I finally got back to the "Switcher", and it would work PERFECTLY, except for one problem:
When I change the name of a SA (standalone) in windows, the name of the Process (as shown in Task Manager) now shows the new name, however, the name of the "APPLICATION" running (as shown in Task Manager) still shows the native application name (in Properties, this is the "Product name"). When refreshing the list showing currently running apps in Switcher, it will grab the new name, which is good, however, it can't find it because Windows thinks the name is the Product name.
Any ideas?
Thanks!
Greg
Re: window management
Posted: Thu Apr 11, 2013 10:08 pm
by Simon
Hi Greg,
Are you renaming the apps while they are running?
Actually I'm quite confused as to what is you are doing, my testing was just to open up Word, Excel, Notepad and LC and then bring any of them into focus. That was what the vb script was doing for me.
What are you doing differently?
Simon
Re: window management
Posted: Thu Apr 11, 2013 10:32 pm
by adventuresofgreg
Hi Simon:
I'm sorry, my explanation was probably confusing. The reason it works with Notepad, Excel, and other applications are because they all have UNIQUE names. It doesn't work with duplicate copies of LC standalones, because, even though they have all been re-named with unique names, their 'actual', internal names are all the same (which is the same name that the stack was given before the SA was generated.) Just renaming the copies of the SA's by changing the file name in Windows, does not actually change it's name as it is referenced via Windows system and your tools.
Did that explain it better?
Greg