Monday, May 28, 2018

automation - AutoHotKey: How to make my script run only within a specific program?


I have made an AHK script that adds metadata to video clips within Avid Media Composer (video editing software). It does this by entering all the necessary sub-menu's and sends mouse clicks to locations on the screen that make a laborious task easy when needing to do it over and over all day.


However, i want the script to only run within Avid Media Composer and nothing else. There are other storage systems connected to the machine and i wouldn't want the script going into other files/folders accidentally doing who knows what to important data.


I tried using #IfWinActive but i'm not very experienced and not sure why i cant get it to work.


Here's what i need to do:


If 'Avid Media Composer' is the active window, run 'My Code'.
If anything other than Avid Media Composer is the active window, Msgbox 'Avid Media Composer must be the active window to run this task'.


-


Window Title, Class and Process


Avid Media Composer Mojo DX
ahk_class Qt5QWindowIcon
ahk_exe AvidMediaComposer.exe

-


My Code:


F3::
{
BlockInput, MouseMove
Hotkey, LButton, DummyLabel, On
Hotkey, RButton, DummyLabel, On
Hotkey, MButton, DummyLabel, On
Sleep, 20
Send, {LAlt}
Sleep, 20
Send, {Right}
Sleep, 200
Send, {Right}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Right}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 107, 30
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Down}
Sleep, 20
Send, {Enter}
Sleep, 100
MouseClick, Left, 346, 38
Sleep, 200
Send, ^v
Sleep, 200
Send, {Enter}
Sleep, 200
Send, {Enter}
Sleep, 200
MouseClick, Left, 91, 102
Sleep, 100
MouseClick, Left, 92, 100
Sleep, 100
MouseClick, Left, 143, 154
Sleep, 100
Send, {Down}
BlockInput, MouseMoveoff
Hotkey, LButton, DummyLabel, Off
Hotkey, RButton, DummyLabel, Off
Hotkey, MButton, DummyLabel, Off
}
return
DummyLabel:
return

What is the correct code for this series of commands to run only within Avid Media Composer itself and nothing else?


Many thanks for any help in advance.


Answer



You should have a look at the following references :


According to your info the following three are all possible :


SetTitleMatchMode, 2
#IfWinActive Avid Media Composer
#IfWinActive ahk_class Qt5QWindowIcon
#IfWinActive ahk_exe AvidMediaComposer

Example :


SetTitleMatchMode, 2
#IfWinActive Notepad
F3:: MsgBox, IN
return
#IfWinNotActive Notepad
F3:: MsgBox, OUT
return

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...