[BUG]: komorebic stop --ahk doesn't stop autohotkey because of trailing space in command line #543

Closed
opened 2026-01-05 14:51:25 +01:00 by adam · 6 comments
Owner

Originally created by @Ziron on GitHub (Dec 14, 2024).

Summary

Hello, when the AHK option is used and trying to stop the program, komorebi does not find the autohotkey process to stop it because there is a trailing space in the command line so the ($_.CommandLine -like '*komorebi.ahk"') condition does not match.

Output when trying to stop the script:

PS C:\Users\Sebbe> komorebic stop --ahk

if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) {
    (Get-CimInstance Win32_Process | Where-Object {
        ($_.CommandLine -like '*komorebi.ahk"') -and
        ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe'))
    } | Select-Object -First 1) | ForEach-Object {
        Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue
    }
} else {
    (Get-WmiObject Win32_Process | Where-Object {
        ($_.CommandLine -like '*komorebi.ahk"') -and
        ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe'))
    } | Select-Object -First 1) | ForEach-Object {
        Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue
    }
}

komorebi is still running, attempting to force-quit

Stop-Process -Name:komorebi -ErrorAction SilentlyContinue

Empty output of original command:

PS C:\Users\Sebbe> Get-CimInstance Win32_Process | Where-Object {
>>         ($_.CommandLine -like '*komorebi.ahk"') -and
>>         ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe'))
>>     }

Output of modified command:

PS C:\Users\Sebbe> Get-CimInstance Win32_Process | Where-Object {
>>         ($_.CommandLine -like '*komorebi.ahk"*') -and
>>         ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe'))
>>     } | Select-Object Name,Commandline

Name             Commandline
----             -----------
AutoHotkey64.exe "C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe" "C:\Users\Sebbe\Documents\Komorebi\komorebi.ahk"

Command line as hex bytes to show the hidden trailing space (0x20):

PS C:\Users\Sebbe> (Get-CimInstance Win32_Process | Where-Object {
>>         ($_.CommandLine -like '*komorebi.ahk"*') -and
>>         ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe'))
>>     }).Commandline | Format-Hex

   Label: String (System.String) <12494C45>

          Offset Bytes                                           Ascii
                 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          ------ ----------------------------------------------- -----
0000000000000000 22 43 3A 5C 50 72 6F 67 72 61 6D 20 46 69 6C 65 "C:\Program File
0000000000000010 73 5C 41 75 74 6F 48 6F 74 6B 65 79 5C 76 32 5C s\AutoHotkey\v2\
0000000000000020 41 75 74 6F 48 6F 74 6B 65 79 36 34 2E 65 78 65 AutoHotkey64.exe
0000000000000030 22 20 22 43 3A 5C 55 73 65 72 73 5C 53 65 62 62 " "C:\Users\Sebb
0000000000000040 65 5C 44 6F 63 75 6D 65 6E 74 73 5C 4B 6F 6D 6F e\Documents\Komo
0000000000000050 72 65 62 69 5C 6B 6F 6D 6F 72 65 62 69 2E 61 68 rebi\komorebi.ah
0000000000000060 6B 22 20                                        k"

Version Information

OS Name:                       Microsoft Windows 11 Pro
OS Version:                    10.0.26100 N/A Build 26100

komorebic 0.1.30
tag:v0.1.30
commit_hash:9a3dbccc
build_time:2024-11-03 23:49:52 +00:00
build_env:rustc 1.82.0 (f6e511eec 2024-10-15),stable-x86_64-pc-windows-msvc

Komorebi Configuration

{
  "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.30/schema.json",
  "app_specific_configuration_path": "$Env:KOMOREBI_CONFIG_HOME/applications.json",
  "window_hiding_behaviour": "Cloak",
  "cross_monitor_move_behaviour": "Insert",
  "default_workspace_padding": 20,
  "default_container_padding": 20,
  "border": true,
  "border_width": 8,
  "border_offset": -1,
  "theme": {
    "palette": "Base16",
    "name": "Ashes",
    "unfocused_border": "Base03",
    "bar_accent": "Base0D"
  },
  "stackbar": {
    "height": 40,
    "mode": "OnStack",
    "tabs": {
      "width": 300
    }
  },
  "monitors": [
    {
      "workspaces": [
        {
          "name": "I",
          "layout": "BSP"
        },
        {
          "name": "II",
          "layout": "VerticalStack"
        },
        {
          "name": "III",
          "layout": "HorizontalStack"
        },
        {
          "name": "IV",
          "layout": "UltrawideVerticalStack"
        },
        {
          "name": "V",
          "layout": "Rows"
        },
        {
          "name": "VI",
          "layout": "Grid"
        },
        {
          "name": "VII",
          "layout": "RightMainVerticalStack"
        }
      ]
    }
  ]
}

Hotkey Configuration

#Requires AutoHotkey v2.0.2
#SingleInstance Force

Komorebic(cmd) {
    RunWait(format("komorebic.exe {}", cmd), , "Hide")
}

!q::Komorebic("close")
!m::Komorebic("minimize")

; Focus windows
!h::Komorebic("focus left")
!j::Komorebic("focus down")
!k::Komorebic("focus up")
!l::Komorebic("focus right")

!+[::Komorebic("cycle-focus previous")
!+]::Komorebic("cycle-focus next")

; Move windows
!+h::Komorebic("move left")
!+j::Komorebic("move down")
!+k::Komorebic("move up")
!+l::Komorebic("move right")

; Stack windows
!Left::Komorebic("stack left")
!Down::Komorebic("stack down")
!Up::Komorebic("stack up")
!Right::Komorebic("stack right")
!;::Komorebic("unstack")
![::Komorebic("cycle-stack previous")
!]::Komorebic("cycle-stack next")

; Resize
!=::Komorebic("resize-axis horizontal increase")
!-::Komorebic("resize-axis horizontal decrease")
!+=::Komorebic("resize-axis vertical increase")
!+_::Komorebic("resize-axis vertical decrease")

; Manipulate windows
!t::Komorebic("toggle-float")
!f::Komorebic("toggle-monocle")

; Window manager options
!+r::Komorebic("retile")
!p::Komorebic("toggle-pause")

; Layouts
!x::Komorebic("flip-layout horizontal")
!y::Komorebic("flip-layout vertical")

; Workspaces
!1::Komorebic("focus-workspace 0")
!2::Komorebic("focus-workspace 1")
!3::Komorebic("focus-workspace 2")
!4::Komorebic("focus-workspace 3")
!5::Komorebic("focus-workspace 4")
!6::Komorebic("focus-workspace 5")
!7::Komorebic("focus-workspace 6")
!8::Komorebic("focus-workspace 7")

; Move windows across workspaces
!+1::Komorebic("move-to-workspace 0")
!+2::Komorebic("move-to-workspace 1")
!+3::Komorebic("move-to-workspace 2")
!+4::Komorebic("move-to-workspace 3")
!+5::Komorebic("move-to-workspace 4")
!+6::Komorebic("move-to-workspace 5")
!+7::Komorebic("move-to-workspace 6")
!+8::Komorebic("move-to-workspace 7")

Output of komorebic check

KOMOREBI_CONFIG_HOME detected: C:\Users\Sebbe\Documents\Komorebi

Looking for configuration files in C:\Users\Sebbe\Documents\Komorebi

Found komorebi.json; this file can be passed to the start command with the --config flag

No ~/.config/whkdrc found; you may not be able to control komorebi with your keyboard
Originally created by @Ziron on GitHub (Dec 14, 2024). ### Summary Hello, when the AHK option is used and trying to stop the program, komorebi does not find the autohotkey process to stop it because there is a trailing space in the command line so the `($_.CommandLine -like '*komorebi.ahk"')` condition does not match. #### Output when trying to stop the script: ```pwsh PS C:\Users\Sebbe> komorebic stop --ahk if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { (Get-CimInstance Win32_Process | Where-Object { ($_.CommandLine -like '*komorebi.ahk"') -and ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe')) } | Select-Object -First 1) | ForEach-Object { Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue } } else { (Get-WmiObject Win32_Process | Where-Object { ($_.CommandLine -like '*komorebi.ahk"') -and ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe')) } | Select-Object -First 1) | ForEach-Object { Stop-Process -Id $_.ProcessId -ErrorAction SilentlyContinue } } komorebi is still running, attempting to force-quit Stop-Process -Name:komorebi -ErrorAction SilentlyContinue ``` #### Empty output of original command: ```pwsh PS C:\Users\Sebbe> Get-CimInstance Win32_Process | Where-Object { >> ($_.CommandLine -like '*komorebi.ahk"') -and >> ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe')) >> } ``` #### Output of modified command: ```pwsh PS C:\Users\Sebbe> Get-CimInstance Win32_Process | Where-Object { >> ($_.CommandLine -like '*komorebi.ahk"*') -and >> ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe')) >> } | Select-Object Name,Commandline Name Commandline ---- ----------- AutoHotkey64.exe "C:\Program Files\AutoHotkey\v2\AutoHotkey64.exe" "C:\Users\Sebbe\Documents\Komorebi\komorebi.ahk" ``` #### Command line as hex bytes to show the hidden trailing space (0x20): ```pwsh PS C:\Users\Sebbe> (Get-CimInstance Win32_Process | Where-Object { >> ($_.CommandLine -like '*komorebi.ahk"*') -and >> ($_.Name -in @('AutoHotkey.exe', 'AutoHotkey64.exe', 'AutoHotkey32.exe')) >> }).Commandline | Format-Hex Label: String (System.String) <12494C45> Offset Bytes Ascii 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ------ ----------------------------------------------- ----- 0000000000000000 22 43 3A 5C 50 72 6F 67 72 61 6D 20 46 69 6C 65 "C:\Program File 0000000000000010 73 5C 41 75 74 6F 48 6F 74 6B 65 79 5C 76 32 5C s\AutoHotkey\v2\ 0000000000000020 41 75 74 6F 48 6F 74 6B 65 79 36 34 2E 65 78 65 AutoHotkey64.exe 0000000000000030 22 20 22 43 3A 5C 55 73 65 72 73 5C 53 65 62 62 " "C:\Users\Sebb 0000000000000040 65 5C 44 6F 63 75 6D 65 6E 74 73 5C 4B 6F 6D 6F e\Documents\Komo 0000000000000050 72 65 62 69 5C 6B 6F 6D 6F 72 65 62 69 2E 61 68 rebi\komorebi.ah 0000000000000060 6B 22 20 k" ``` ### Version Information ``` OS Name: Microsoft Windows 11 Pro OS Version: 10.0.26100 N/A Build 26100 komorebic 0.1.30 tag:v0.1.30 commit_hash:9a3dbccc build_time:2024-11-03 23:49:52 +00:00 build_env:rustc 1.82.0 (f6e511eec 2024-10-15),stable-x86_64-pc-windows-msvc ``` ### Komorebi Configuration ```json { "$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.30/schema.json", "app_specific_configuration_path": "$Env:KOMOREBI_CONFIG_HOME/applications.json", "window_hiding_behaviour": "Cloak", "cross_monitor_move_behaviour": "Insert", "default_workspace_padding": 20, "default_container_padding": 20, "border": true, "border_width": 8, "border_offset": -1, "theme": { "palette": "Base16", "name": "Ashes", "unfocused_border": "Base03", "bar_accent": "Base0D" }, "stackbar": { "height": 40, "mode": "OnStack", "tabs": { "width": 300 } }, "monitors": [ { "workspaces": [ { "name": "I", "layout": "BSP" }, { "name": "II", "layout": "VerticalStack" }, { "name": "III", "layout": "HorizontalStack" }, { "name": "IV", "layout": "UltrawideVerticalStack" }, { "name": "V", "layout": "Rows" }, { "name": "VI", "layout": "Grid" }, { "name": "VII", "layout": "RightMainVerticalStack" } ] } ] } ``` ### Hotkey Configuration ```ahk #Requires AutoHotkey v2.0.2 #SingleInstance Force Komorebic(cmd) { RunWait(format("komorebic.exe {}", cmd), , "Hide") } !q::Komorebic("close") !m::Komorebic("minimize") ; Focus windows !h::Komorebic("focus left") !j::Komorebic("focus down") !k::Komorebic("focus up") !l::Komorebic("focus right") !+[::Komorebic("cycle-focus previous") !+]::Komorebic("cycle-focus next") ; Move windows !+h::Komorebic("move left") !+j::Komorebic("move down") !+k::Komorebic("move up") !+l::Komorebic("move right") ; Stack windows !Left::Komorebic("stack left") !Down::Komorebic("stack down") !Up::Komorebic("stack up") !Right::Komorebic("stack right") !;::Komorebic("unstack") ![::Komorebic("cycle-stack previous") !]::Komorebic("cycle-stack next") ; Resize !=::Komorebic("resize-axis horizontal increase") !-::Komorebic("resize-axis horizontal decrease") !+=::Komorebic("resize-axis vertical increase") !+_::Komorebic("resize-axis vertical decrease") ; Manipulate windows !t::Komorebic("toggle-float") !f::Komorebic("toggle-monocle") ; Window manager options !+r::Komorebic("retile") !p::Komorebic("toggle-pause") ; Layouts !x::Komorebic("flip-layout horizontal") !y::Komorebic("flip-layout vertical") ; Workspaces !1::Komorebic("focus-workspace 0") !2::Komorebic("focus-workspace 1") !3::Komorebic("focus-workspace 2") !4::Komorebic("focus-workspace 3") !5::Komorebic("focus-workspace 4") !6::Komorebic("focus-workspace 5") !7::Komorebic("focus-workspace 6") !8::Komorebic("focus-workspace 7") ; Move windows across workspaces !+1::Komorebic("move-to-workspace 0") !+2::Komorebic("move-to-workspace 1") !+3::Komorebic("move-to-workspace 2") !+4::Komorebic("move-to-workspace 3") !+5::Komorebic("move-to-workspace 4") !+6::Komorebic("move-to-workspace 5") !+7::Komorebic("move-to-workspace 6") !+8::Komorebic("move-to-workspace 7") ``` ### Output of komorebic check ``` KOMOREBI_CONFIG_HOME detected: C:\Users\Sebbe\Documents\Komorebi Looking for configuration files in C:\Users\Sebbe\Documents\Komorebi Found komorebi.json; this file can be passed to the start command with the --config flag No ~/.config/whkdrc found; you may not be able to control komorebi with your keyboard ```
adam added the bugi-will-not-work-on-thisi-am-stuckapps-behaving-badlykomorebic labels 2026-01-05 14:51:26 +01:00
adam closed this issue 2026-01-05 14:51:26 +01:00
Author
Owner

@Ziron commented on GitHub (Dec 14, 2024):

Looks like it is known behavior that using Start-Process adds an extra space at the end of the commandline: PowerShell/PowerShell#13094

@Ziron commented on GitHub (Dec 14, 2024): Looks like it is known behavior that using `Start-Process` adds an extra space at the end of the commandline: PowerShell/PowerShell#13094
Author
Owner

@LGUG2Z commented on GitHub (Dec 14, 2024):

Thanks for the deep dive here @Ziron! If someone would like to rewrite this logic in pure Rust to avoid the PowerShell issue I'd be willing to accept a patch.

@LGUG2Z commented on GitHub (Dec 14, 2024): Thanks for the deep dive here @Ziron! If someone would like to rewrite this logic in pure Rust to avoid the PowerShell issue I'd be willing to accept a patch.
Author
Owner

@Dethada commented on GitHub (Feb 8, 2025):

I will be happy to take this up, I think we should handle all the process creation/deletion in rust directly through windows APIs, which would fix this issue and it should also reduce the start up time since we are removing the middleman which is powershell.

@Dethada commented on GitHub (Feb 8, 2025): I will be happy to take this up, I think we should handle all the process creation/deletion in rust directly through windows APIs, which would fix this issue and it should also reduce the start up time since we are removing the middleman which is powershell.
Author
Owner

@LGUG2Z commented on GitHub (Feb 8, 2025):

This would be great - honestly I don't use the start or stop commands anymore and just manage all of these daemon-type processes with wpm instead. However I think that the time investment in learning how to use wpm, especially for people not already familiar with systemd, is way too high to make it a part of the "recommended" quickstart.

@LGUG2Z commented on GitHub (Feb 8, 2025): This would be great - honestly I don't use the `start` or `stop` commands anymore and just manage all of these daemon-type processes with [wpm](https://github.com/LGUG2Z/wpm) instead. However I think that the time investment in learning how to use wpm, especially for people not already familiar with systemd, is way too high to make it a part of the "recommended" quickstart.
Author
Owner

@azinsharaf commented on GitHub (Oct 15, 2025):

@Dethada is this issue resolved with PR #1269? I still can't stop autohotkey process. #1103

@azinsharaf commented on GitHub (Oct 15, 2025): @Dethada is this issue resolved with PR #1269? I still can't stop autohotkey process. #1103
Author
Owner

@LGUG2Z commented on GitHub (Oct 17, 2025):

Closing issues related to launching AHK from komorebic because this feature is now EOL, meaning no more work will be done on it and it will eventually be dropped during a major version bump

@LGUG2Z commented on GitHub (Oct 17, 2025): Closing issues related to launching AHK from `komorebic` because this feature is now EOL, meaning no more work will be done on it and it will eventually be dropped during a major version bump
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/komorebi#543