#!/bin/zsh set -euo pipefail project_dir="${0:A:h}" app_dir="$HOME/Library/Application Support/RazerTilt/Razer Tilt Mapper.app" agent_file="$HOME/Library/LaunchAgents/local.razer-tilt.plist" service="gui/$(/usr/bin/id -u)/local.razer-tilt" if [[ ! -x "$project_dir/.build/Razer Tilt Mapper.app/Contents/MacOS/RazerTiltMapper" ]]; then /bin/zsh "$project_dir/build.sh" fi /usr/bin/codesign --verify --strict "$project_dir/.build/Razer Tilt Mapper.app" /bin/mkdir -p "${app_dir:h}" "${agent_file:h}" "$HOME/Library/Logs" if /bin/launchctl print "$service" >/dev/null 2>&1; then /bin/launchctl bootout "$service" fi /bin/rm -rf -- "$app_dir" /usr/bin/ditto "$project_dir/.build/Razer Tilt Mapper.app" "$app_dir" # tccutil resolves the bundle ID through Launch Services, so register the new copy first. /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f "$app_dir" # Each ad-hoc build gets a new signature, so old grants go stale; clear them so re-adding is clean. /usr/bin/tccutil reset Accessibility local.razer-tilt 2>/dev/null || true /usr/bin/tccutil reset ListenEvent local.razer-tilt 2>/dev/null || true # Use plutil so spaces or XML characters in the home path are encoded safely. /usr/bin/plutil -create xml1 "$agent_file" /usr/bin/plutil -insert Label -string local.razer-tilt "$agent_file" /usr/bin/plutil -insert ProgramArguments -json '[]' "$agent_file" /usr/bin/plutil -insert ProgramArguments.0 -string "$app_dir/Contents/MacOS/RazerTiltMapper" "$agent_file" /usr/bin/plutil -insert RunAtLoad -bool true "$agent_file" /usr/bin/plutil -insert KeepAlive -bool true "$agent_file" /usr/bin/plutil -insert ThrottleInterval -integer 10 "$agent_file" /usr/bin/plutil -insert ProcessType -string Interactive "$agent_file" /usr/bin/plutil -insert StandardOutPath -string "$HOME/Library/Logs/RazerTiltMapper.log" "$agent_file" /usr/bin/plutil -insert StandardErrorPath -string "$HOME/Library/Logs/RazerTiltMapper.log" "$agent_file" /bin/chmod 644 "$agent_file" /usr/bin/plutil -lint "$agent_file" /bin/launchctl enable "$service" /bin/launchctl bootstrap "gui/$(/usr/bin/id -u)" "$agent_file" /bin/launchctl print "$service" print "Installed: $app_dir" # Reveal the app so it can be dragged into Input Monitoring / Accessibility. /usr/bin/open -R "$app_dir" /usr/bin/open "x-apple.systempreferences:com.apple.preference.security?Privacy_ListenEvent"