Skip to content

License management scripted

waydabber edited this page Aug 7, 2024 · 3 revisions

Activating and deactivating licenses via command line comes handy in a corporate environment using automated license management solutions.

Note

The article reflects app version v2.3.0

Warning

License management CLI features are not accessible by using betterdisplaycli, you need to use the app binary itself!

Warning

Prior to app version v3.x always use absolute path to access the app binary. Using a relative path with v2.x versions will result in no response and may also instantly deactivate the local copy.

CLI license management features

The following features are available:

Print current activation status

/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay manageLicense -status

Activate the app

/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay manageLicense -activate -email=<email address> -key=<license key>

Deactivate the app

/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay manageLicense -deactivate

List existing activations

When the app is already activated, the license key can be omitted (the output will be a JSON structure, containing the activation date, activation ID and the primary network adapter MAC address of the Mac associated with the license):

/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay manageLicense -activations

/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay manageLicense -activations -key=<license key>

Deactivate an other activation

When the app is already activated, the license key can be omitted.

/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay manageLicense -deactivate -activationid=<activation ID> -key=<license key>

Hide or show the Pro activation/deacativation UI

Hiding activation/deactivation UI and the license key from the app GUI is useful in a corporate environment to avoid accidental deactivation or easy copying of the product key:

/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay manageLicense -hideui

/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay manageLicense -showui

Example script + activation as root

Please note that BetterDisplay stores the license activation files under a specific user's ~/Library/Application Support/BetterDisplay folder. If you run activation/deactivation commands as root, the operations will be performed for the root user, not for the actual main user of the Mac. However, the activation data is transferrable among local users (as the activation is tied to the Mac, not the actual user).

Here is a sample script (credits go to ynot) that allows running activation as root for a current user by copying the activation files from the root user's appropriate folder to the current user's appropriate folder.

#!/bin/bash

currentuser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')

app="/Applications/BetterDisplay.app/Contents/MacOS/BetterDisplay"

$app manageLicense -status
$app manageLicense -activate -email=[INSERT EMAIL ADDRESS HERE] -key=[INSERT LICENSE KEY HERE]

rootpath="/var/root/Library/Application Support/BetterDisplay"
userpath="/Users/$currentuser/Library/Application Support"

if [[ $currentuser == "it" ]]; then exit; fi
#if 'it' is user, then the install isn't meaningful. standard user is target.

cp -pr "$rootpath" "$userpath"
#yes i could have used mv but wanted to keep it!

chown -R "$currentuser":staff "$userpath/BetterDisplay"
su $currentuser
$app manageLicense -status