JSON input

Send a BetterDisplay command as a JSON object from Terminal, the app console, an HTTP client, a custom URL or a local Mac app. This lets a script prepare the same request once and choose how to deliver it. Each method returns its usual response.

Write a request

For example, get -displayWithMainStatus -brightness reads the main display’s brightness. Its JSON form uses the two required fields, commands and parameters.

{
  "commands": ["get"],
  "parameters": {
    "displayWithMainStatus": null,
    "brightness": null
  }
}

Put one or more operation names in the commands array. Put the selectors, features and their values in the parameters object, using the names from the CLI reference without leading hyphens. Use an empty object ({}) when an operation takes no parameters.

Use JSON strings for values, including numbers such as "42", percentages such as "35%" and switches such as "on". Use null for a flag you would normally supply without a value. Leaving out a key leaves out that parameter. In the example above, removing displayWithMainStatus would remove the main-display filter.

To set the main display’s brightness to 35% and read it back in one request, include both operations in the array.

{"commands":["set","get"],"parameters":{"displayWithMainStatus":null,"brightness":"35%"}}

Terminal and the app console

Pass the whole object as the value of -request to the json command. Keep all command parameters inside the object. Single quotes around the JSON in this Terminal example preserve the double quotes in the request.

betterdisplaycli json -request='{"commands":["get"],"parameters":{"displayWithMainStatus":null,"brightness":null}}'

The app executable accepts the same arguments. If your script already holds the JSON in a shell variable named request, use betterdisplaycli json -request="$request".

The Homebrew companion betterdisplaycli v1.0.1 cuts off the request at the first = inside the JSON. The launcher installed from BetterDisplay's Settings and the app executable both preserve equals signs. With the Homebrew companion, write the character as \u003D inside the JSON string. For example, "A\u003DB" reaches BetterDisplay as A=B.

In the app console, enter the command without the executable name and press Return.

json -request='{"commands":["get"],"parameters":{"displayWithMainStatus":null,"brightness":null}}'

If the command fails, check the JSON syntax and the operation and parameter names. The json command accepts a single request. Adding another command or selector outside the object, or nesting a second json command inside it, causes the request to fail.

HTTP and custom URLs

Enable the access method you want in Integration settings. For HTTP, send a GET request to /json. For a custom URL, use betterdisplay://json. In either case, supply the entire JSON object as one request query value.

These Terminal examples use the same encoded request to read the main display’s brightness. The first prints the HTTP response using the default port. The second delivers the request through the custom URL scheme.

request='%7B%22commands%22%3A%5B%22get%22%5D%2C%22parameters%22%3A%7B%22displayWithMainStatus%22%3Anull%2C%22brightness%22%3Anull%7D%7D'
curl "http://localhost:55777/json?request=$request"
open "betterdisplay://json?request=$request"

When constructing the URL, percent-encode the JSON once as a query value. For example, in JavaScript use encodeURIComponent(JSON.stringify(requestObject)). A space is %20, a literal percent sign is %25, and an ampersand inside a value is %26. BetterDisplay reads a plus sign as a literal +.

If you configured a security token, add token as a separate query item. A custom URL can also carry x-success and x-error callback URLs as separate query items to receive the result. Encode each value individually.

The HTTP server limits the entire GET request line, including the percent-encoded JSON, to 8 KiB. A longer line returns HTTP 414. For a larger local request, use the CLI.

Distributed notifications

For a local Mac app, send the JSON itself as the string in the distributed notification’s object. Use the pro.betterdisplay.BetterDisplay.request notification name. You can add a top-level uuid string to match the response to your request.

{"uuid":"C0E2719F-39F5-4267-9C17-1C56CC19BDBD","commands":["get"],"parameters":{"displayWithMainStatus":null,"brightness":null}}

Generate a new UUID for each request you need to track. Third-party app integration shows how to listen for responses, check the result and read the returned payload.

Additional information

The selected access method and requested operation determine availability.

Features requiring Pro license

JSON input is available with the free app. Each requested operation keeps its own licensing requirements.

Platform compatibility

All features described on this page are available on both Apple silicon and Intel Macs. The selected display must support the requested operation.