StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 General Action Scripts
 Opening/focusing a program or window
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

JohntheApostle

4 Posts

Posted - 03/16/2014 :  16:37:15  Show Profile  Reply with Quote
I'd like to have a stroke that will open a program, but if the program is already open, then it will bring it to the front/focus. I feel like this probably exists already, but I couldn't find it anywhere.

Rob

USA
2516 Posts

Posted - 03/16/2014 :  17:06:31  Show Profile  Visit Rob's Homepage  Reply with Quote
You would be correct! These threads have all the pieces you're looking for.

http://www.strokesplus.com/forum/topic/852/open-or-close-program-same-gesture
http://www.strokesplus.com/forum/topic/828/how-to-active-and-restore-window
Go to Top of Page

JohntheApostle

4 Posts

Posted - 03/17/2014 :  00:44:32  Show Profile  Reply with Quote
Hey, thanks Rob! I'm sort of a newb with programming, so I tried to piece together the pieces you gave me, but it doesn't seem to be working. Here's what I got

local swnd = acFindWindow("MozillaWindowClass",nil) --this line would match on exact class name
--local swnd = acFindWindowByTitleRegex(".* - firefox") --finds by title wildcard
if swnd > 0 then
acRestoreWindow(MozillaWindowClass)
acActivateWindow(MozillaWindowClass)
else
acRunProgram("C:\\program files (x86)\\mozilla firefox\\firefox.exe","",0, 1)
end
Go to Top of Page

JohntheApostle

4 Posts

Posted - 03/17/2014 :  00:48:26  Show Profile  Reply with Quote
I just noticed I should probably replace

acRestoreWindow(MozillaWindowClass)
acActivateWindow(MozillaWindowClass)

with

acRestoreWindow(swnd)
acActivateWindow(swnd)

But it didn't help...
Go to Top of Page

Rob

USA
2516 Posts

Posted - 03/17/2014 :  01:04:21  Show Profile  Visit Rob's Homepage  Reply with Quote
Interesting, I copied exactly what you have (using the swnd parameter, of course) and it works perfectly!
local swnd = acFindWindow("MozillaWindowClass",nil) --this line would match on exact class name
--local swnd = acFindWindowByTitleRegex(".* - firefox") --finds by title wildcard
if swnd > 0 then
	acRestoreWindow(swnd)
	acActivateWindow(swnd)
else
	acRunProgram("C:\\program files (x86)\\mozilla firefox\\firefox.exe","",0, 1)
end
So, let's see what could be causing this...

Does it do either of these events? Meaning, does it open FF or activate it?

If not, it seems like we're missing something.

Put this in place of your script just to confirm it's running:
local swnd = acFindWindow("MozillaWindowClass",nil)
acMessageBox("swnd handle: "..swnd)
acMessageBox("swnd EXE: "..acGetExecutableName(swnd))
No matter what, you should see two message boxes when you execute the gesture; whether swnd is reflecting the correct handle and EXE is another matter, but if you see the message boxes, then we know it's running.

Go to Top of Page

JohntheApostle

4 Posts

Posted - 03/17/2014 :  04:21:02  Show Profile  Reply with Quote
Yeah, it opens FF when it's closed, but it doesn't do anything when it's open. I am using bblean as my windows shell, but that hasn't caused any problems in the past. I tried the script you gave me and both boxes came up. The handle was 1639972 and the exe was firefox.
Go to Top of Page

Rob

USA
2516 Posts

Posted - 03/19/2014 :  01:54:50  Show Profile  Visit Rob's Homepage  Reply with Quote
I wish I had some advice. If you switch back to Explorer as the shell, does it work? If so, there's something missing from bblean to handle the API call. Maybe bblean has it's own API call to manage the foreground window that can be bound to via Alien/Lua..
Go to Top of Page

control_freak

51 Posts

Posted - 04/21/2016 :  16:42:54  Show Profile  Reply with Quote
hey rob if i put this it opens a new chrome window and doesn't put focus on existing chrome.
and how do i get the class name of any application in case i try it with other applications?

local swnd = acFindWindow("Google chrome",nil) --this line would match on exact class name
--local swnd = acFindWindowByTitleRegex(".* - chrome") --finds by title wildcard
if swnd > 0 then
acRestoreWindow(swnd)
acActivateWindow(swnd)
else
acRunProgram("C:\\program files (x86)\\Google\\chrome\\application\\chrome.exe","",0, 1)
end

Go to Top of Page

chandisciple

75 Posts

Posted - 04/21/2016 :  20:04:03  Show Profile  Reply with Quote
Control freak , try changing this line,

swnd = acFindWindowByTitleRegex(".* - chrome")

to this,

swnd = acFindWindowByTitleRegex(".* - Google Chrome")


I guess rob would suggest the tool he likes to find the class,
WinSpy++ 1.7. Rob apologies if you have a different answer.

Edited by - chandisciple on 04/21/2016 20:06:34
Go to Top of Page

control_freak

51 Posts

Posted - 04/21/2016 :  21:05:48  Show Profile  Reply with Quote
hey chandisciple thank you :P winspy++ worked. rob has just told me about this software this morning lol. heres what made it work

local swnd = acFindWindow("Chrome_WidgetWin_1",nil) --this line would match on exact class name
--local swnd = acFindWindowByTitleRegex(".* -Google chrome") --finds by title wildcard
if swnd > 0 then
acRestoreWindow(swnd)
acActivateWindow(swnd)
else
acRunProgram("C:\\program files (x86)\\Google\\chrome\\application\\chrome.exe","",0, 1)
end
Go to Top of Page

control_freak

51 Posts

Posted - 04/22/2016 :  18:46:29  Show Profile  Reply with Quote
hey i have another problem. if my chrome is minimized to the tray acMaximizeWindow doesnt work. i put my code like this

local swnd = acFindWindow("Chrome_WidgetWin_1",nil) --this line would match on exact class name
--local swnd = acFindWindowByTitleRegex(".* -Google chrome") --finds by title wildcard
if swnd > 0 then
acMaximizeWindow(swnd)
acRestoreWindow(swnd)
acActivateWindow(swnd)

else
acRunProgram("C:\\program files (x86)\\Google\\chrome\\application\\chrome.exe","",0, 1)
end
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000