AutoHotkey Community

It is currently May 27th, 2012, 6:06 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Max/Min script Possible?
PostPosted: October 23rd, 2010, 12:45 am 
Offline

Joined: October 22nd, 2010, 8:16 pm
Posts: 2
Hi everyone,

I have been creating hotkeys to Activate or Minimize applications. The have been following this format:

Code:
LAlt & "character"::
SetTitleMatchMode, 2

ifWinActive, "Application Name"
WinMinimize

else
WinActivate, "Application Name"
return
;


I have been working on a script for the last week (yes, I'm not very good at this stuff). I am almost done, but I'm stuck...

I have two different instances of an application running (they are installed in different directories) whose WinTitles change and sometimes they even have the same title. Is there a way to choose an application by its installation path on the Hard Drive? If so, I'm stupid... how would that be done?

Thanks
Smash

PS - I also cannot figure out how/where to put the logic to run the application if WinNotExist > Run (file path).

i.e. - If Firefox is not currently running a process, it will open it)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 23rd, 2010, 1:45 am 
Offline

Joined: April 30th, 2006, 6:23 pm
Posts: 358
Location: Shigle Springs
Smashin wrote:
PS - I also cannot figure out how/where to put the logic to run the application if WinNotExist > Run (file path).

i.e. - If Firefox is not currently running a process, it will open it)


Code:
process, exist, blabla.exe
if ! errorlevel
run, blabla.exe

_________________
CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 23rd, 2010, 1:53 am 
Offline

Joined: April 30th, 2006, 6:23 pm
Posts: 358
Location: Shigle Springs
Smashin wrote:
I have two different instances of an application running (they are installed in different directories) whose WinTitles change and sometimes they even have the same title. Is there a way to choose an application by its installation path on the Hard Drive? If so, I'm stupid... how would that be done?



I do not think you can discover install paths of where a process is running from. That would be very cool if possible. I would love to see a virus running on a client and end the process and make a fake exe with read only persmissiions to kill the bastard.. (We clean viruses all day)
Na, not stupid, learning, don't be down on yourself.

For sorting through different windows,

Try...
Code:
DetectHiddenText, On

ifWinExist, File Download - Security Warning
{
text =
WinGetText, text, File Download - Security Warning
ifinstring, text, acctHmpg.js
ControlClick, Cancel, File Download - Security Warning
}


_________________
CPULOCK.com
virusSWAT.com
Computer Repair Computer Service.com
911PCFIX.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 23rd, 2010, 4:43 pm 
Offline

Joined: October 22nd, 2010, 8:16 pm
Posts: 2
Thank you for the responses!

I somewhat understand what is being spoken of in the responses above, but I am not clever enough to know how to put it together to make it work for my script.

Since the 3 applications I am trying to Restore (think i said "Maximize" in first post... my apologies) and Minimize on command have WinTitles that are changing (depending on which active window inside them is active) AND at times they even have the same WinTitle, I decided to look for their process names. They were all the same, "terminal.exe", so I renamed them as a sequences of 1, 2, and 3 in their installed directories. This way they can each be identified by their process name.

Code:
!Numpad1::
WinGet, myProcessName, ProcessName, A
If myProcessName = terminal1.exe
WinMinimize, A
return
;

!Numpad2::
WinGet, myProcessName, ProcessName, A
If myProcessName = terminal2.exe
WinMinimize, A
return
;

!Numpad3::
WinGet, myProcessName, ProcessName, A
If myProcessName = terminal3.exe
WinMinimize, A
return
;


I feel I am getting closer, but still not there yet. The limitations of the logic above are :

(1) The process has to be the active window for it to work. I have multiple monitors and want to minimize and restore on command no matter which window is active, even if it's not one of these processes.

(2) There is no Restore (WinActivate??) in the logic. I do not know how to build from this if it is even a good foundation for the logic.

(3) There is no Run command to run the process if it is NotExist. I have no idea how to properly code multiple If Else statements to give the script a "path" of logic to follow.

Point (3) is the least of my concerns as I can easily get programs running by clicking. But I want to be able to move through them in this way by their own dedicated key strokes.

Further assistance is much appreciated!
Smash


Report this post
Top
 Profile  
Reply with quote  
 Post subject: My solution
PostPosted: October 23rd, 2010, 8:00 pm 
Offline

Joined: May 18th, 2005, 6:46 pm
Posts: 16
My solution is to use the following function. You need to specify the title of the app (usually in forms of ahk_class) is the best option, and also the name / part of the name of the shortcut of the app in your start menu. You can supply multiple wildcards to make a better match with the :

i.e :
"Auto:Help" to open Autohotkey help file instead of anything else with the word "auto" in it.

Use like:

^!1::WinMinLaunch("ahk_class Vim", "Vim72.lnk")

What this will do when run Vim72.lnk if the window is not found, restore if minimized, and minimize if the active screen.

Hope this helps.

Code:
WinMinLaunch(WindowTitle, AppTitle)
{
   SetTitleMatchMode,2
   AutoTrim, Off
   DetectHiddenWindows, Off
   IfWinActive, %WindowTitle%
   {
      WinMinimize, %WindowTitle%
   }
   Else
   {
      IfWinExist, %WindowTitle%
      {
         WinGet, winid, ID, %WindowTitle%
         DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)
      }
      Else
      {
         if InStr(AppTitle, ":")
            NewApp := AppTitle
         else
            NewApp := FindAppPath(AppTitle)
         Sleep, 10
         Run % NewApp
      }
   }
}

; Find application path from start menus, use | to parse description for more detailed search
FindAppPath(AppTitle)
{
   scanPath = %A_StartMenuCommon%|%A_StartMenu%
   Count = 0
   Loop, parse, scanPath,|
   {
      Loop, %A_LoopField%\*, %ScanMode%, 1
      {
         FileGetAttrib, fileAttrib, %A_LoopFileFullPath%
         IfNotInString, fileAttrib, H ; EXCLUDE HIDDEN FILE
         {
            Count += 1
            Listing%Count% := A_LoopFileFullPath
         }
      }
   }
   Loop %Count%
   {
      element := Listing%A_Index%
      try = 0
      success = 0
      Loop, parse, AppTitle, |
      {
         try +=1
         IfInString, element, %A_LoopField%
            success +=1
      }
      If (try = success)
         Return %element%
   }
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, dra, HotkeyStick, migz99, Wicked, XstatyK and 58 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group