I'm trying to write an script in order to perform actions when Microsoft Edge windows being active. I tried these scripts:
#IfWinActive Microsoft edge
~$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
send,^l
sleep,100
send,{Delete}
}
return
But it doesn't recognize the windows. I tried different names such #IfWinActive, ahk_class Microsoft Edge and #IfWinActive Microsoft Edge.exe too. but neither of them worked.
Using Window Spy on a new Edge tab shows me this:
Of the three main options that you would use for an #IfWinActive statement (WinTitle, ahk_class, or ahk_exe), the ahk_exe would likely be the best option for creating a script that will always work in MS Edge, and only in MS Edge based on what the Windows Spy displays.
Based on this, I created this generic script to check if a hotkey was triggered in Edge
#IfWinActive, ahk_exe msedge.exe
^q::MsgBox Hotkey Triggered in Edge (msedge.exe)
#If
^q::MsgBox Hotkey Triggered in a different program
Incorporating your original script into this gives:
#IfWinActive, ahk_exe msedge.exe
~$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
send,^l
sleep,100
send,{Delete}
}
return
For more info about #IfWinActive, see the docs.
Also relevant: Post on AHK forums on how to use the #IfWinActive with program names, ahk_exe, and ahk_class.
Related
I would like to make a ahk script to start apps if they are not currently started and maximize them if they are. Is it possible using AHK ?
CapsLock & w::
Run firefox.exe
Return
Something like this but make it so that if I press CapsLock & w and then minimize firefox, pressing CapsLock & w would bring it back maximized / in focus. Any ideas? Thanks!
Sure, this is very easy and doable with AHK.
Here's a very easy and straight forward example
CapsLock & w::
if (WinExist("ahk_exe notepad.exe"))
{
WinActivate, ahk_exe notepad.exe
WinMaximize, ahk_exe notepad.exe
}
else
Run, notepad.exe
return
ahk_exe (docs) is used to refer to windows by their process. It's very convenient.
The code that you are looking for is somewhat similar to the example they give in the docs for WinActivate
So modifying that example for your purpose, and adding conditionals would give you:
CapsLock & w::
if WinExist("ahk_exe firefox.exe")
if WinActive("ahk_exe firefox.exe")
WinMinimize
else
WinActivate
else
Run firefox.exe
Return
Take note that this script will currently only minimize a Firefox window if it is the currently active window. If you need it to minimize a Firefox in the background, the script would potentially be a bit more complex since you could possibly have multiple Firefox windows open, and you would need to provide conditions and logic to handle cases like those. However, if you need this functionality, describe what behavior you would like to occur if this condition occurs, and I can work on it.
I'm stumped on how to best re-write my hotkey. What I want to do is simple. I have a script that switches to File Explorer IF it's currently open Else it will open a new file explorer window.
Here's the catch - It's hard to "identify" if the Explorer window is open. I used to just do this by using WinActivate, 00123456 because that's the name of the folder (eight-digit random number). But the problem with that is that these are support ticket numbers. And that number will also be within the title of my current Chrome session and sometimes other windows too (Firefox, Snagit, notepad, etc). So it will inadvertently switch to those other programs. So that led me to exclude in this way:
Ticket_Out := clipboard
xclude:= Ticket_Out . " | Salesforce - Google Chrome"
WinActivate, % Ticket_Out, , % xclude
That's handy except for it only excludes 1 window at a time. How could I implement something that excludes a second application? OR --- another thought, how could I just say: look for Explorer.exe with window title "00123456" ?
You can use ahk_exe to filter by the process name too:
WinActivate, ahk_exe explorer.exe %Ticket_Out%
Another way would be to look for the window class - since depending on the Windows version Explorer can use either CabinetWClass or ExploreWClass, you can use a group, as shown in the docs:
; Define the group: Windows Explorer windows
GroupAdd, Explorer, ahk_class ExploreWClass ; Unused on Vista and later
GroupAdd, Explorer, ahk_class CabinetWClass
; Activate any window matching the above criteria and the title
WinActivate, ahk_group Explorer %Ticket_Out%
Note on CherryDT's answer the two WinActivate examples are missing a comma between the WinTitle, and WinText parameters...
Should be....
WinActivate, ahk_exe explorer.exe, %Ticket_Out%
Second example (when using GroupAdd)
WinActivate, ahk_group Explorer, %Ticket_Out%
Caught me out for awhile.
(I would comment on the answer, but as a new user don't have 50 reputation)
I'm trying to build a script that allows me to open and use OneNote (The store app not OneNote 2016) with a hotkey, but I would like to use the same hotkey to switch the the app from another window. I have accomplished this with many other programs, but never with windows store app. Here is the code I'm trying to use.
#If WinExist("OneNote ahk_class ApplicationFrameWindow", "OneNote")
{
WinActivate,
}
Else
Run, C:\Users\ChrisCochrun\Documents\OneNote
#If
Unfortunately it's not detecting that the window exists and it'll only just launch a new instance of onenote. I've looked for answers, but I'm having trouble making it so that AHK actually sees the window already running and jumping to it.
Thanks very much for any help at all!
If the window's title doesn't start with "OneNote", you need to use
SetTitleMatchMode 2.
The #If-directive is only used for creating context-sensitive hotkeys and hotstrings.
F1:: ; or a hotkey of your choise
SetTitleMatchMode 2
If WinExist("OneNote ahk_class ApplicationFrameWindow", "OneNote")
WinActivate
Else
Run, C:\Users\ChrisCochrun\Documents\OneNote
return
rshfit::
SetTitleMatchMode 2
If WinExist("OneNote for Windows 10")
WinActivate return
;If I use rshift to activate Onenote for Windows 10
I have this autohotkey script that opens chrome if its not already on windows, and if it is, cycles through tabs within it. It also puts that chrome window on top of any other windows (e.g. excel docs, word docs, etc)
IfWinNotExist, ahk_class Chrome_WidgetWin_1
Run, chrome.exe
if WinActive("ahk_class Chrome_WidgetWin_1")
Send ^{tab}
else
WinActivate ahk_class Chrome_WidgetWin_1
Return
I can't seem to figure out how to get this to work for google chromium though. Both exe names are "chrome.exe", so I'm not sure what the run commands is if there's an overlap.
Also, I ran winSpy but still am not 100% sure what ahk_class name is. Below is the information from winSpy
I ended up settling for a different solution
After 2 days of tweaking and testing some workflows, this is what I settled with. I ran a combination of both phrase-express (any macro program works here) and autohotkey here, so I can have an extremely flexible layout
F1 → Binded to WIN+1 key
F2 → Binded to WIN+2 key
F3 → Binded to Win+4 key
F4 → Binded to Win+4 key
For F5 to F7 keys, I used autohotkey
F5::
IfWinNotExist, ahk_class Chrome_WidgetWin_1
Run, chrome.exe
GroupAdd, kjexplorers5, ahk_class Chrome_WidgetWin_1 ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe chrome.exe")
GroupActivate, kjexplorers5, r
else
WinActivate ahk_class Chrome_WidgetWin_1 ;you have to use WinActivatebottom if you didn't create a window group.
Return
F6::
IfWinNotExist, ahk_class ConsoleWindowClass
Run, cmd.exe
GroupAdd, kjexplorers6, ahk_class ConsoleWindowClass ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe cmd.exe")
GroupActivate, kjexplorers6, r
else
WinActivate ahk_class ConsoleWindowClass ;you have to use WinActivatebottom if you didn't create a window group.
Return
F7::
IfWinNotExist, ahk_class QWidget
Run, anki.exe
GroupAdd, kjexplorers7, ahk_class QWidget ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe anki.exe")
GroupActivate, kjexplorers7, r
else
WinActivate ahk_class QWidget ;you have to use WinActivatebottom if you didn't create a window group.
Return
F5 to F7 uses the same variant autohotkey, I just changed up the groupnames, the .exe files , and the ahk_class names.
This is how I organize the structure of my windows taskbar
So I press
F5 (3 times), and it pushes each chrome window I have up to the top of each of my 3 monitors.
F6 and I can quickly pop out whatever command prompts I have open, one command prompt for gulp commands, and one for git, independent of any IDE.
F7 twice to quickly add some new flashcards
I can restructure F1 F2 F3 F4 to whatever app I'm currently using. Anything that goes here I only keep one window per app at a time. Like I only run one firefox window (to watch tutorial youtube videos), only one running application of PHPstorm, etc.
Demonstration of F6 key in action (command prompt)
In AutoHotKey, ahk_class NAME has been a good identifier for programs. Typically, I now use it in the following two ways:
Simply calling the most recently called active instance:
; Pressing Win+Shift+X will bring up (or switch to) the Windows Journal
Application
#+x::
IfWinExist ahk_class JournalApp
WinActivate ahk_class JournalApp
else
Run C:\Program Files\Windows Journal\Journal.exe
return
Grouping windows with the same ahk_class and looping through them:
GroupAdd, FIRE, ahk_class MozillaWindowClass
; Pressing Win+3 will go through all open Firefox windows one by one.
#3::
IfWinExist ahk_class MozillaWindowClass
GroupActivate, FIRE, r
else
Run firefox
return
However, there are certain programs that do not have a stable ahk_class name. For example, the ArcMap.exe should
display the following information in the "Windows Spy" window of AHK:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Untitled - ArcMap
ahk_class Afx:012F0000:b:00010003:00000006:001C0BB0
Any idea how could I refer to this application that has dynamic ahk_class?
I am aware that there is also something called ahk_exe. However, I did not find it compatible with the method GroupAdd,
GroupActivate or IfWinExist.
You definitely are on the right track trying to incorporate ahk_exe. GroupAdd (and every other command receiving a WinTitle parameter at that) is compatible with ahk_exe in AHK_L; this sample code works perfectly on my machine:
GroupAdd, notepad, ahk_exe notepad.exe
Run, notepad.exe
WinWaitActive, ahk_group notepad
Sleep, 1000
WinClose, ahk_group notepad
I suspect you're not using the most recent version of AHK. Get it here and have another try.