From 4d507e49348719cb050a4b06f76882ad3169871e Mon Sep 17 00:00:00 2001 From: Dmitry Surin Date: Wed, 28 Aug 2024 21:17:21 +0400 Subject: [PATCH] Ahk updates. Fixed bugs --- win/ahk/actions.json | 1 + win/ahk/alfred.ahk | 17 ++++++++++++----- win/ahk/remap/per-app/browser.ahk | 21 +++++++++++---------- win/ahk/remap/per-app/devtools.ahk | 4 ++-- win/ahk/utils/tray.ahk | 13 +++++++++++-- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/win/ahk/actions.json b/win/ahk/actions.json index d5ddb58..308f3df 100644 --- a/win/ahk/actions.json +++ b/win/ahk/actions.json @@ -191,6 +191,7 @@ }, "turm": { "desktop": "Dev", + "title": "ubuntu", "run": "C:\\Program Files\\Alacritty\\alacritty.exe", "runArgs": "--config-file C:\\Users\\dmitr\\.dotfiles\\all\\alacritty\\alacritty-work-profile.yml --title ubuntu --command wsl -d Ubuntu-22.04 --cd ~", "initFunction": "makeAnyWindowCenteredThenMaximized", diff --git a/win/ahk/alfred.ahk b/win/ahk/alfred.ahk index fa191b6..ea98b52 100644 --- a/win/ahk/alfred.ahk +++ b/win/ahk/alfred.ahk @@ -54,17 +54,24 @@ executeInput(apps, userInput) { } ; If nothing to activate else { - if (app.run && IsAppInTray(app.run)) { + ; Check in tray + if (app.title) { + if (IsAppInTrayByTitle(app.title)) { + RemoveAppFromTrayByTitle(app.title) + return + } + } else + if (app.run && IsAppInTrayByPath(app.run)) { RemoveAppFromTrayByPath(app.run) return } + ; Try to run runCmd := app.run - if (app.runArgs != "") { + if (app.runArgs) { runCmd := runCmd . " " . app.runArgs } - ; Try to run Run % runCmd WinWait % app.selector,, 10 if ErrorLevel { @@ -78,14 +85,14 @@ executeInput(apps, userInput) { } ; Call init function - if (app.initFunction != "") { + if (app.initFunction) { retval := Func(app.initFunction).Call() } } } ; there is no selector for the app else { - if (app.run && IsAppInTray(app.run)) { + if (app.run && IsAppInTrayByPath(app.run)) { RemoveAppFromTrayByPath(app.run) return } diff --git a/win/ahk/remap/per-app/browser.ahk b/win/ahk/remap/per-app/browser.ahk index 86cea4d..492c9ad 100644 --- a/win/ahk/remap/per-app/browser.ahk +++ b/win/ahk/remap/per-app/browser.ahk @@ -15,25 +15,26 @@ ; Workspace switcher popup #if ScopeIs("ahk_exe msedge.exe") - ~s:: - if (GetKeyState("Space", "P")) { - createPopUp("select workspace", "C:\Users\dmitr\.dotfiles\win\pwsh\bin\Switch-BrowserWorkspace.ps1", false) - } - return #s:: createPopUp("select workspace", "C:\Users\dmitr\.dotfiles\win\pwsh\bin\Switch-BrowserWorkspace.ps1", false) return #if +#if ScopeIs("ahk_exe msedge.exe") && HYPER_PRESSED + s:: + createPopUp("select workspace", "C:\Users\dmitr\.dotfiles\win\pwsh\bin\Switch-BrowserWorkspace.ps1", false) + return +#if + #if ScopeIs("select workspace ahk_class Window Class ahk_exe alacritty.exe") - ~s:: - if (GetKeyState("Space", "P")) { - HideAppToTray() - } - return #s:: ~*Enter:: HideAppToTray() return #if +#if ScopeIs("select workspace ahk_class Window Class ahk_exe alacritty.exe") && HYPER_PRESSED + s:: + HideAppToTray() + return +#if diff --git a/win/ahk/remap/per-app/devtools.ahk b/win/ahk/remap/per-app/devtools.ahk index 5d87ee7..81dd2ea 100644 --- a/win/ahk/remap/per-app/devtools.ahk +++ b/win/ahk/remap/per-app/devtools.ahk @@ -1,10 +1,10 @@ -#if ScopeIs("^Dev") && GetKeyState("Space", "P") +#if ScopeIs("^Dev ahk_exe msedge.exe") && HYPER_PRESSED a::Send ^+p f::Send ^p #if on := false -#if ScopeIs("^Dev") +#if ScopeIs("^Dev ahk_exe msedge.exe") ; Debug `;:: ; Step global on diff --git a/win/ahk/utils/tray.ahk b/win/ahk/utils/tray.ahk index fc539fc..ac24a59 100644 --- a/win/ahk/utils/tray.ahk +++ b/win/ahk/utils/tray.ahk @@ -12,10 +12,19 @@ AddAppToTray(winTitle, winID, pathToExe) { } ; Function to check if a window is already in the tray menu -IsAppInTray(pathToExe) { +IsAppInTrayByPath(path) { global appsInTray for _, win in appsInTray { - if (win.pathToExe = pathToExe) { + if (win.pathToExe = path) { + return true + } + } + return false +} +IsAppInTrayByTitle(title) { + global appsInTray + for _, win in appsInTray { + if (win.winTitle = title) { return true } }