computergroove Posted November 18, 2010 Share Posted November 18, 2010 What I need this to do is check to see if notepad is running and if it is then make it the active window. If notepad isn't running then it needs to start and become the active window. While 1 Sleep(11) WEnd Func Change() If WinExists('notepad.exe') Then; check to see if the MAC program is already running WinActivate('notepad.exe'); makes MAC program active Else Run('notepad.exe') ; Starts MAC program EndIf EndFunc Right now it just keeps opening new instances of notepad. What is wrong? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
BrewManNH Posted November 18, 2010 Share Posted November 18, 2010 Try this in place of your line above: If WinExists("[CLASS:Notepad]") Then If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
somdcomputerguy Posted November 18, 2010 Share Posted November 18, 2010 WinExists takes a title as a parameter, unlike ProcessExists which accepts a filename of the process running. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
computergroove Posted November 18, 2010 Author Share Posted November 18, 2010 Try this in place of your line above: If WinExists("[CLASS:Notepad]") Then This fixed the multiple notepad instances but When I hit the button and notepad is open it doesn't activate the window. The title bar stays gray. How can I get the program to do this? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
BrewManNH Posted November 18, 2010 Share Posted November 18, 2010 Here's the whole change you need, sorry should have put this out earlier. Func Change() If WinExists("[CLASS:Notepad]") Then; check to see if the MAC program is already running WinActivate("[CLASS:Notepad]"); makes MAC program active Else Run('notepad.exe') ; Starts MAC program EndIf EndFunc As somdcomputerguy said above, WinExists takes a title, and so does WinActivate, you can't give them the program name as an argument. See the Help file on how to use these functions. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
somdcomputerguy Posted November 18, 2010 Share Posted November 18, 2010 I didn't read enough of your original code. So, even though I don't need to say it now, I will anyway; WinActivate takes a title as a parameter also. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
computergroove Posted November 18, 2010 Author Share Posted November 18, 2010 Func Change() If WinExists("[CLASS:Notepad]") Then; check to see if the MAC program is already running WinActivate("[CLASS:Notepad]"); makes MAC program active Else Run('notepad.exe') ; Starts MAC program EndIf EndFunc And this fixed the problem with notepad not being the active window. Thank you very much. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now