Using AutoHotkey to Emulate macOS Cmd + ` Window Switching on Windows OS

As a long-time Windows user, I experienced the convenience of Cmd+ after getting a MacBook Air M1. Especially when switching between different windows within the same application, this shortcut is incredibly smooth. For Windows users, this feature isn't as straightforward—typically, you need to use Alt+Tab to switch between all applications, without limiting it to just a single app. This guide will show you how to achieve a similar operation using AutoHotkey 1.0, allowing you to quickly switch between windows within the same program.

Download and Install AutoHotkey 1.0

  1. Visit the AutoHotkey Website: Open your browser and go to the AutoHotkey official website.
  2. Download AutoHotkey v1.0: The website provides download links for both v1.0 and v2.0. For this guide, we need v1.0, so download v1.0.
  3. Install AutoHotkey: Once the download is complete, run the installer and follow the prompts to complete the installation.

Create and Save Your Script

  1. Create a New AHK Script File: Anywhere on your computer, right-click and choose "New" > "AutoHotkey Script". Name the script "SwitchWindows.ahk".
    Alternatively, you can open a blank file using Windows Notepad.
  2. Copy and Paste the Script Content: Paste the following script code into the new .ahk file and save it:

    ; Define a hotkey, such as Alt + ` (similar to macOS Cmd + `)
    !`::
       ; Get the PID of the current active window
       WinGet, currentPID, PID, A
       ; Get the process name of the current active window
       WinGet, processName, ProcessName, A
       ; Initialize variables
       nextWindow := ""
       foundCurrent := false
       ; Iterate through all windows
       WinGet, id, list,,, Program Manager
       Loop, %id%
       {
           this_id := id%A_Index%
           ; Get the process name of the window
           WinGet, thisProcess, ProcessName, ahk_id %this_id%
           ; Check if the window belongs to the same process and is visible
           if (thisProcess = processName)
           {
               ; If the current window is found, the next matching window is the target
               if (foundCurrent)
               {
                   nextWindow := this_id
                   break
               }
               ; Check if this is the current active window
               if (this_id = WinExist("A"))
                   foundCurrent := true
               ; If the current window is not yet found, set the first matching window as the target
               if (nextWindow = "")
                   nextWindow := this_id
           }
       }
       ; Switch to the target window
       if (nextWindow != "")
           WinActivate, ahk_id %nextWindow%
    return

Place the AHK File in a Specific Location and Set It to Run on Startup

  1. Place the Script in a Specific Location: Place the newly created "SwitchWindows.ahk" script in the C:\Scripts\AHK1\ directory.
  2. Set It to Run on Startup:
    • Press Win + R, type shell:startup, and press Enter.
    • In the startup folder that opens, right-click and choose "Paste Shortcut" (Windows 11 may require expanding the menu first), and paste a shortcut to the "SwitchWindows.ahk" file.
    • This ensures that the script starts automatically every time you boot your computer, saving you from having to manually run it.

How to Temporarily Disable the AHK Script

If you need to temporarily disable the script, such as when you don't want the hotkeys to interfere, follow these steps:

  1. Find the AutoHotkey Icon in the System Tray: In the system tray at the bottom-right of the screen, you'll see a green "H" icon.
  2. Right-Click the Icon: Right-click the green "H" icon to open the menu, and choose "Suspend hotkeys" to pause the script. The icon will turn into an "S". Alternatively, choose "Exit" to completely close the script.

Conclusion

Using AutoHotkey 1.0, you can achieve the convenience of the macOS Cmd+ operation with just a few simple steps, allowing you to set it up and run it automatically.
I hope this guide helps you experience better multi-window switching in the Windows environment and boosts your productivity. Give this script a try and see how much convenience it can bring to your workflow!

Handling Line Breaks in Home Assistant’s YAML to Send LineMessenger Push Messages (Restful Request)

In this blog post, I won't guide you step-by-step on how to configure Home Assistant to send Gmail notifications to LINE, but focusing on how to correctly handle line breaks (\n). This seemingly simple requirement can become quite challenging due to the complexities between YAML, JSON, and various APIs.

This post will focus on ensuring that line breaks are correctly displayed in LINE messages.繼續閱讀...