Managing the system via AHK | Create, open folders and move windows with one button
It's time to consider how to speed up work with the system via AHK. For myself, I have identified the following actions:
changing the position of an open window (I have 3 monitors, and every time I move a window to a convenient place with my hands – the pain is unbearable)
Automatic creation of multiple folders with a specific name
open specific folders in a specific directory with one button
copy file name
Let's get started!
Changing the position of an open window
Moving windows manually and setting the position each time is a choice for the weak. Now we will make it so that when you press a button, the active window immediately stands where it should. I decided to make three options for the window position: full screen, half on the left, half on the right (and so on for three monitors). Actually, we write such a function:
MoveWindow_Main_Left(width, height) {
WinMove, A, , 0, 0, width, height
ToolTip, %width%x%height%
Sleep, 500
ToolTip,
Return
}
And then call the function:
Numpad4::
MoveWindow_Main_Left(1280, 1400)
return
What's what? Function:
WinMove, A, , 0, 0, width, height
– here in place of the 4th and 5th arguments (in this example 0 and 0) we write the offset (position) of the window. The count is from the upper left corner of the main monitor. Here we have a function for the “half on the left”, so the offset by X and Y is zero
Calling the function:
MoveWindow_Main_Left(1280, 1400)
– here we write down the arguments, namely – the window size. Here, most likely, you will have to adjust it manually. My monitor is 2560 x 1440, so for the “half” we divide the width by 2, and leave the height as the original (although the experienced one set the height not to 1440, but to 1400)
Detailed explanation:
![](https://habrastorage.org/getpro/habr/upload_files/c9d/357/611/c9d357611ada2faed12580e878790b39.png)
And so we write for all monitors. You can see my example here. I will only add that if you have a monitor located to the left (or above) the main one, the window position will be negative (since we count from the upper left corner of the main monitor):
![](https://habrastorage.org/getpro/habr/upload_files/055/029/d79/055029d7915a4284d161a25c5f94291a.png)
Now with one button (I have 9 numpad buttons) you can move windows across all monitors – isn't it beautiful?
Automatic creation of folders
My project structure looks something like this:
[ИМЯ_ПРОЕКТА]
[IN]
[OUT]
[NUKE]
The IN folder stores all the sources, OUT stores all the renders, and NUKE stores all the project files by shots. Years go by, new projects start, old ones are delivered, but one thing remains constant – the project hierarchy. Which means it can be automated :). This time there won't be anything interesting, we just call the function to create folders sequentially:
f11::
CreateFolder("IN")
CreateFolder("NUKE")
CreateFolder("OUT")
CreateFolder(Folder_Name)
{
Send, ^+n
Send, %Folder_Name%
Send, {Enter}
Sleep, 200
}
return
![](https://habrastorage.org/getpro/habr/upload_files/96a/42b/52c/96a42b52c9cf73278c923dc4bf60633e.png)
The result is three folders.
Open specific folders in a specific directory with one button
Often, when working, you need to open a folder with sources to throw something new there and then drag it into the project. Or open a folder with a render to send it to someone to look at. But every time you open the explorer and go to the necessary directory manually can be tedious, boring, sad and slow. Let's fix it!
At the very beginning of the script, we declare a variable for the working directory as global:
global dir_path
![](https://habrastorage.org/getpro/habr/upload_files/c25/9c2/52d/c259c252db5f61058440914c2cf3b13b.png)
I have entered a code on a separate f12 button that asks for your working directory:
f12::
InputBox, dir_path, dir path, Enter dir path,,,,,,,, %dir_path%
return
InputBox
– window call
1 аргумент
– a variable into which the value will be written
2 аргумент
– name of the pop-up window
3 аргумент
– inscription inside the window
More detailed explanation:
![](https://habrastorage.org/getpro/habr/upload_files/b75/b97/8ba/b75b978ba7f4e1fc06eaad58da437f3f.png)
When executing the code, the following window appears with an input field:
![](https://habrastorage.org/getpro/habr/upload_files/eae/4eb/429/eae4eb429d8fc7bc04587ae0a2cdc94c.png)
Here we paste the path to the project folder directly from the explorer. Well, that's it, now you can make a script to open any folder in this directory:
f1::
global dir_path
open = \IN
dir_path_open = %dir_path%%open%
Run, %dir_path_open%
return
open = \IN
– here we write the folder that needs to be opened
global dir_path
– this is necessary so that the variable can be used inside the script
dir_path_open = %dir_path%%open%
– we combine the working directory and the folder that needs to be opened into one path
Run, %dir_path_open%
– open the final path
Since I have basically 3 folders, it all looks something like this:
![](https://habrastorage.org/getpro/habr/upload_files/7d3/eed/53d/7d3eed53d3764ec6c22cb4ae9c641254.png)
Copy file name
There's just one little thing left. Periodically (often, actually) I need to copy a file name. At first, I did it like this: right-click on the file – rename, ctrl+c. After a while, I started selecting the file, F2 (hotkey for renaming) and ctrl+c. Faster, but still inconvenient. As always, we'll do it by pressing a button:
f10::
Send, {f2}
Send, ^c
Send, {Enter}
return
Conclusion
I pasted over all the buttons on my keyboard to make it more clear and to not forget what is where.
![](https://habrastorage.org/getpro/habr/upload_files/1fb/f88/d81/1fbf88d813874bd583f6fc061d943785.png)
At the moment, these are all my “life hacks” through AHK. Perhaps, in some time there will be new ones – I will definitely bring them into a human form and share. So, I'm not saying goodbye!
P.s. my full script for AHK can be downloaded here
My telegram channel with useful tools for working in Nuke and more: