refactor(macos): Improve solaar executable lookup in launchagent script

This change improves how the `create-macos-launchagent.sh` script locates the `solaar` executable.

Previously, the script defaulted to a hardcoded path (`/opt/homebrew/bin/solaar`) and would exit with an error if that specific file was not found and executable. This was too restrictive and failed in environments where `solaar` is installed in a different location, such as through `pipx` or in standard system paths like `/usr/local/bin`.

Now, the script defaults the `SOLAAR_PATH` to just `solaar` and uses the `command -v` utility to find the executable in the user's `PATH`. This allows the system to resolve the correct location of the `solaar` binary automatically. If the executable cannot be found in the `PATH`, the script now issues a warning instead of exiting, and proceeds to use the provided `SOLAAR_PATH` value in the generated LaunchAgent plist. This makes the script more flexible and robust for different installation methods.
This commit is contained in:
Din Tort 2025-10-27 20:51:25 +01:00
parent 43600668fc
commit 4192044f82
1 changed files with 6 additions and 6 deletions

View File

@ -2,11 +2,11 @@
# Helper to install a LaunchAgent for Solaar to keep it running in the background.
set -euo pipefail
SOLAR_PATH=${SOLAR_PATH:-/opt/homebrew/bin/solaar}
if [[ ! -x "${SOLAR_PATH}" ]]; then
echo "Error: Unable to execute ${SOLAR_PATH}. Set SOLAR_PATH to the solaar binary." >&2
exit 1
SOLAAR_PATH=${SOLAAR_PATH:-solaar}
SOLAAR_RESOLVED_PATH=$(command -v "${SOLAAR_PATH}" 2>/dev/null || echo "")
if [ -z "${SOLAAR_RESOLVED_PATH}" ]; then
echo "Warning: '${SOLAAR_PATH}' not found" >&2
SOLAAR_RESOLVED_PATH="${SOLAAR_PATH}"
fi
LAUNCH_AGENT_DIR="${HOME}/Library/LaunchAgents"
@ -28,7 +28,7 @@ cat > "${LAUNCH_AGENT_PLIST}" <<EOF
<string>io.github.pwr-solaar.solaar</string>
<key>ProgramArguments</key>
<array>
<string>${SOLAR_PATH}</string>
<string>${SOLAAR_PATH}</string>
<string>--window=hide</string>
</array>
<key>RunAtLoad</key>