Adding initial state of my script
- Auto-download Youtube links using WSL2 and youtube-dl - Toggle terminal with capslock+t. Resizes to cover VS Code - Auto place windows based on connected monitors
This commit is contained in:
parent
2b637e3c23
commit
d7bf2bb1b6
108
main.ahk
Normal file
108
main.ahk
Normal file
@ -0,0 +1,108 @@
|
||||
DownloadYoutubeVideo(dataType)
|
||||
{
|
||||
; Note: This callback is usually fired twice when copying for some reason
|
||||
; so we use "RunWait" below to make sure we only launch youtube-dl once.
|
||||
|
||||
if (dataType != 1) {
|
||||
return
|
||||
}
|
||||
|
||||
; If there is an ampersand, remove it and anything following.
|
||||
link := StrSplit(A_Clipboard, "&")[1] ; Arrays are 1 offset
|
||||
|
||||
if (InStr(A_Clipboard, "youtube.com/watch")) {
|
||||
Runwait "wsl.exe --shell-type standard /home/tgrosinger/bin/youtube-dl " . link
|
||||
}
|
||||
}
|
||||
OnClipboardChange DownloadYoutubeVideo
|
||||
|
||||
|
||||
; Open a terminal over the currently focused VS Code window.
|
||||
; If there is an open Windows Terminal, use that, otherwise create a new one.
|
||||
; Pressing the hotkey again goes back to the previously focused window.
|
||||
|
||||
prevWindow := 0
|
||||
CapsLock & t:: ; Capslock+t to open a terminal
|
||||
{
|
||||
global prevWindow
|
||||
|
||||
termID := WinExist("ahk_exe WindowsTerminal.exe")
|
||||
|
||||
if (termID and termID == WinGetID("A") and prevWindow) {
|
||||
WinActivate(prevWindow)
|
||||
return
|
||||
}
|
||||
|
||||
prevWindow := WinGetID("A")
|
||||
|
||||
if ( not termID) {
|
||||
Run "wt.exe"
|
||||
termID := WinWait("ahk_exe WindowsTerminal.exe")
|
||||
}
|
||||
WinActivate
|
||||
|
||||
if (WinExist("ahk_exe Code.exe")) {
|
||||
WinGetPos ¤t_x, ¤t_y, &width, &height
|
||||
WinMove(current_x, current_y, width, height, "ahk_exe WindowsTerminal.exe")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
; Arrange windows into my preferred location, based on what monitors are connected.
|
||||
monitorConfigurations := Map(
|
||||
; Desk means the monitor at my desk is plugged in.
|
||||
"desk", Map(
|
||||
"Workrave", [3748, 2056, 94, 56],
|
||||
"Discord", [-7, 0, 900, 750],
|
||||
"Signal", [-7, 742, 900, 750],
|
||||
"Visual Studio Code", [886, 0, 2954, 2110],
|
||||
"Mozilla Firefox", [881, 0, 2963, 2117],
|
||||
"TickTick", [712, 2892, 942, 821],
|
||||
"Atrium", [1654, 2160, 1620, 1552]
|
||||
),
|
||||
; Standalone means there are no other monitors plugged in.
|
||||
"standalone", Map(
|
||||
"Workrave", [2468, 1498, 94, 56],
|
||||
"Discord", [-7, 0, 900, 750],
|
||||
"Signal", [-7, 742, 900, 750],
|
||||
"Visual Studio Code", [472, 0, 2085, 1550],
|
||||
"Mozilla Firefox", [467, 0, 2099, 1557],
|
||||
"TickTick", [0, 731, 942, 821],
|
||||
"Atrium", [983, 0, 1577, 1552]
|
||||
)
|
||||
)
|
||||
IdentifyMonitorConfiguration() {
|
||||
count := MonitorGetCount()
|
||||
if (count == 1) {
|
||||
return "standalone"
|
||||
}
|
||||
|
||||
primary := MonitorGetPrimary()
|
||||
MonitorGet primary, &Left, &Top, &Right, &Bottom
|
||||
|
||||
if (Right == "3840" and Bottom == "2160") {
|
||||
return "desk"
|
||||
}
|
||||
|
||||
return "unknown"
|
||||
}
|
||||
ArrangeWindowsInMonitor(monitorIndex, windowConfigs) {
|
||||
for win, params in windowConfigs {
|
||||
if (WinExist(win)) {
|
||||
WinMove(params[1], params[2], params[3], params[4])
|
||||
}
|
||||
}
|
||||
}
|
||||
ArrangeWindows(wParam, lParam, msg, hwnd)
|
||||
{
|
||||
monitorConfigName := IdentifyMonitorConfiguration()
|
||||
if ( not monitorConfigurations.Has(monitorConfigName)) {
|
||||
return
|
||||
}
|
||||
|
||||
monitorConfig := monitorConfigurations[monitorConfigName]
|
||||
ArrangeWindowsInMonitor(A_Index, monitorConfig)
|
||||
}
|
||||
OnMessage(0x007E, ArrangeWindows)
|
||||
|
||||
ArrangeWindows(0, 0, 0, 0)
|
Loading…
Reference in New Issue
Block a user