Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --json flag to all query commands #577

Closed
nikitabobko opened this issue Oct 9, 2024 · 4 comments
Closed

Add --json flag to all query commands #577

nikitabobko opened this issue Oct 9, 2024 · 4 comments
Labels

Comments

@nikitabobko
Copy link
Owner

nikitabobko commented Oct 9, 2024

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

Currently presented query commnads:

  • list-windows
  • list-monitors
  • list-apps
  • list-workspaces
  • list-exec-env-vars (I plan to drop this command)

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

@thewinger
Copy link

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
Copy link
Owner Author

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
Copy link

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 added a commit that referenced this issue Oct 13, 2024
#577

The change is non-functional yet
@nikitabobko
Copy link
Owner Author

Released in 0.15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants