nikitabobko / AeroSpace

AeroSpace is an i3-like tiling window manager for macOS
https://nikitabobko.github.io/AeroSpace/guide
MIT License
8k stars 131 forks source link

Add `--json` flag to all query commands #577

Closed nikitabobko closed 1 month ago

nikitabobko commented 1 month ago

All query commands must provide --json flag to make it easier to use them for reliable scripting.

Currently presented query commnads:

It's an open question how --json should interact with --format flag that those commands also have

thewinger commented 1 month ago

This would save me a lot for a Raycast extension in developing.

Right now I’m using —format to retrieve a JSON object-like list of windows in focused workspace but when doing JSON.parse it breaks if a window has “ in the %{window-title}.

nikitabobko commented 1 month ago

It's an open question how --json should interact with --format flag that those commands also have

I think it should work this way:

$ aerospace list-windows --all --json --format "%{app-name}"
[
  { "app-name": "Google Chrome" },
  { "app-name": "IntelliJ IDEA" }
]

$ aerospace list-windows --all --json --format "%{app-name} %{app-pid}%{app-bundle-id}"
[
  { 
    "app-name": "Google Chrome",
    "app-pid": 354,
    "app-bundle-id": "com.google.chrome",
  },
  {
    "app-name": "IntelliJ IDEA",
    "app-pid": 132,
    "app-bundle-id": "org.jetbrains.intellij",
  }
]

$ aerospace list-windows --all --json --format "%{app-name} | %{app-pid}"
error: non-whitespace characters are not allowed in <output-format> when --json is used
thewinger commented 1 month ago

This looks good to me. The output is the exact one I “hacked” for the Raycast extension.

Something I struggled, but don’t know up to which point you have control is: If you ask for the %{window-title}, and this has double quotes (for example a browser title for a web), they should be escaped, because if not and you try to JSON.parse() the output it will give errors.

nikitabobko commented 1 month ago

Released in 0.15.0