lsagent-mac

🟒 LsAgent Mac Tools

macOS scripts for Lansweeper Agent management, force rescan, remote execution, and 3rd-party app version checking.

macOS Lansweeper License: MIT


πŸ“‹ What’s In This Repo

Script Purpose Run As
πŸ› οΈ force-rescan-lsagent.sh Interactive LsAgent rescan with settings editor sudo on Mac
πŸš€ remote-exec-template.sh GoTo Resolve remote execution template GoTo Resolve / sudo
πŸ” check-app-versions.sh Scan installed apps, check for updates via Homebrew Cask API Any user / sudo

How This Ties Into PA-LsAgent

These scripts complement the pa-lsagent Power Automate flow:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ–₯️ Mac Endpoints     β”‚       β”‚  ☁️ Lansweeper Cloud       β”‚
β”‚                      │──────▢│  (scans assets + software)β”‚
β”‚  LsAgent installed   β”‚ scan  β”‚                           β”‚
β”‚  check-app-versions  β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚  force-rescan        β”‚                 β”‚ GraphQL API
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β–Ό
                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                               β”‚  ⚑ PA-LsAgent Flow        β”‚
                               β”‚  (Power Automate)         β”‚
                               β”‚                           β”‚
                               β”‚  tblPCs / tblMonitors     β”‚
                               β”‚  tblPeripherals           β”‚
                               β”‚  tblNetwork               β”‚
                               β”‚  tblMacSoftware  ← NEW    β”‚
                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                         β”‚
                                         β–Ό
                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                               β”‚  πŸ“Š SharePoint Excel       β”‚
                               β”‚  Asset Tracking Workbook   β”‚
                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⚑ Quick Start

# 1. Clone the repo
git clone https://github.com/GreenHornet-Dev/lsagent-mac.git
cd lsagent-mac

# 2. Make scripts executable
chmod +x *.sh

# 3. Force rescan (interactive)
sudo ./force-rescan-lsagent.sh

# 4. Check app versions (no sudo needed)
./check-app-versions.sh

🍎 Run on Mac β€” Copy & Paste Commands

Open Terminal on your Mac and paste any of these blocks.

First-Time Setup (run once)

# Clone repo and make all scripts executable
git clone https://github.com/GreenHornet-Dev/lsagent-mac.git
cd lsagent-mac && chmod +x *.sh

One-Liner: Force Rescan LsAgent

cd ~/lsagent-mac && sudo ./force-rescan-lsagent.sh

Stops agent β†’ backs up config β†’ lets you edit settings β†’ clears cache β†’ restarts agent

One-Liner: Check 3rd-Party App Versions

cd ~/lsagent-mac && ./check-app-versions.sh

Scans all installed apps β†’ checks Homebrew Cask API for latest β†’ color-coded report + JSON output

One-Liner: Remote Exec Template (local test)

cd ~/lsagent-mac && sudo ./remote-exec-template.sh

Runs the GoTo Resolve template locally for testing before deploying remotely

Run Without Cloning (curl + bash)

If you just need the version checker on a Mac without cloning the full repo:

curl -fsSL https://raw.githubusercontent.com/GreenHornet-Dev/lsagent-mac/main/check-app-versions.sh | bash

Or download first, inspect, then run (recommended):

curl -fsSL https://raw.githubusercontent.com/GreenHornet-Dev/lsagent-mac/main/check-app-versions.sh -o /tmp/check-app-versions.sh
cat /tmp/check-app-versions.sh    # review the script
chmod +x /tmp/check-app-versions.sh && /tmp/check-app-versions.sh

For the force-rescan tool (requires sudo):

curl -fsSL https://raw.githubusercontent.com/GreenHornet-Dev/lsagent-mac/main/force-rescan-lsagent.sh -o /tmp/force-rescan-lsagent.sh
chmod +x /tmp/force-rescan-lsagent.sh && sudo /tmp/force-rescan-lsagent.sh

Update to Latest Version

cd ~/lsagent-mac && git pull origin main

βœ… Prerequisites


πŸ› οΈ force-rescan-lsagent.sh

Interactive tool for hands-on LsAgent rescan. Run this when you’re at the Mac or SSH’d in.

What It Does (Step by Step)

Step Action
1️⃣ Checks for root/sudo access
2️⃣ Stops LsAgent (graceful β†’ force kill if needed)
3️⃣ Creates timestamped backup of lsagent.ini
4️⃣ Displays ALL settings β€” color-coded πŸŸ’πŸ”΄
5️⃣ Interactive editor β€” change any setting by number
6️⃣ Auto-clears Field7 and Field8 (scan cache)
7️⃣ Restarts LsAgent and confirms it’s running
8️⃣ Prints summary with agent status check

Interactive Menu

[1] Server = lansweeper.yourdomain.com
[2] Port = 9524
[3] ScanInterval = 86400
[4] Field7 = a3f8c2... ← WILL BE CLEARED πŸ”΄
[5] Field8 = 1711234... ← WILL BE CLEARED πŸ”΄
────────────────────────────────────────
Options:
  [number]  - Edit a setting by its number
  [a]       - Show all settings again
  [c]       - Continue with rescan
  [q]       - Quit without restarting

v1.1 Improvements


πŸš€ remote-exec-template.sh

Silent, unattended execution via GoTo Resolve Remote Execution. Copy and customize for any remote macOS task.

How to Use in GoTo Resolve

  1. Open GoTo Resolve
  2. Navigate to Remote Execution (or Helpdesk > Scripts)
  3. Click New Script or Paste Script
  4. Copy/paste the entire contents of remote-exec-template.sh
  5. Set OS Type to macOS
  6. Select target device(s)
  7. Click Run
  8. Check results in dashboard β€” exit code 0 = βœ… SUCCESS

How to Test Locally

chmod +x remote-exec-template.sh
sudo ./remote-exec-template.sh

Built-in Helper Functions

Function What It Does
setup_logging() Creates log directory, rotates old logs (30+ days)
log() Timestamped logging β€” color in terminal, plain text in GoTo
preflight() Logs hostname, macOS version, arch, user, connectivity
stop_service() Graceful unload β†’ force kill β†’ error reporting
start_service() Load plist β†’ verify process β†’ delayed retry
backup_file() Timestamped .bak copy before any edits
edit_ini_field() Safely set or clear any key=value with sed escaping
display_config() Dump full config to log with line numbers
report_result() SUCCESS/FAILURE exit code for GoTo dashboard

Creating a New Task

cp remote-exec-template.sh my-new-task.sh

Edit the header:

TASK_NAME="My Custom Task"
TASK_VERSION="1.0"

Replace only main() β€” all helpers stay the same.

v1.1 Improvements

Log Location

/var/log/goto-resolve-scripts/<TIMESTAMP>_<TASK_NAME>.log

πŸ” check-app-versions.sh

Scans all installed 3rd-party Mac apps and checks for available updates using the Homebrew Cask API.

What It Does

  1. Scans /Applications and ~/Applications
  2. Skips Apple built-in apps (com.apple.* bundle IDs)
  3. Reads each app’s version from Info.plist
  4. Looks up the latest version via https://formulae.brew.sh/api/cask/<token>.json
  5. Compares installed vs. latest using semver sort
  6. Outputs:
    • πŸ–₯️ Color-coded terminal report (outdated = πŸ”΄, current = 🟒, unknown = βšͺ)
    • πŸ“„ JSON file for the pa-lsagent Power Automate flow

How to Run

# No sudo needed for basic scan
chmod +x check-app-versions.sh
./check-app-versions.sh

Example Output

  APP NAME                            INSTALLED       LATEST          STATUS
  ─────────────────────────────────────────────────────────────────────────
  Google Chrome                       131.0.6778.86   132.0.6834.57   πŸ”΄ UPDATE
  Slack                               4.39.95         4.39.95         🟒 OK
  Visual Studio Code                  1.96.0          1.96.0          🟒 OK
  Zoom                                6.3.5           6.3.6           πŸ”΄ UPDATE
  Firefox                             133.0           133.0           🟒 OK
  Docker                              4.37.1          4.37.2          πŸ”΄ UPDATE

  ═══════════════════════════════════════════════════
    πŸ“Š Summary β€” MACBOOK-PRO.local
  ═══════════════════════════════════════════════════

  Total scanned:    42
  🟒 Up to date:     35
  πŸ”΄ Needs update:   5
  πŸ”΅ Newer than repo: 0
  βšͺ Unknown/N/A:    2

  ⚠️  5 app(s) need updating!

  Outdated apps:
    β€’ Google Chrome  131.0.6778.86 β†’ 132.0.6834.57
    β€’ Zoom           6.3.5 β†’ 6.3.6
    β€’ Docker         4.37.1 β†’ 4.37.2
    ...

JSON Output

The script writes a JSON file to /tmp/lsagent-mac/ that the pa-lsagent Power Automate flow can consume:

{
  "hostname": "MACBOOK-PRO.local",
  "macosVersion": "14.5",
  "scanDate": "2026-03-24T05:00:00Z",
  "scriptVersion": "1.0",
  "summary": {
    "total": 42,
    "current": 35,
    "outdated": 5,
    "newer": 0,
    "unknown": 2
  },
  "apps": [
    {
      "appName": "Google Chrome",
      "bundleId": "com.google.Chrome",
      "installedVersion": "131.0.6778.86",
      "latestVersion": "132.0.6834.57",
      "caskToken": "google-chrome",
      "status": "outdated",
      "hostname": "MACBOOK-PRO.local",
      "scanDate": "2026-03-24T05:00:00Z"
    }
  ]
}

Feeding Into PA-LsAgent

The JSON output is designed to match a tblMacSoftware Excel table in the pa-lsagent spreadsheet:

Column JSON Key Description
Hostname hostname Mac computer name
AppName appName Application name
BundleID bundleId macOS bundle identifier
InstalledVersion installedVersion Currently installed version
LatestVersion latestVersion Latest available from Homebrew
CaskToken caskToken Homebrew Cask identifier
Status status outdated / current / newer / unknown
ScanDate scanDate When the check ran (UTC)

How the Cask Lookup Works

  1. Script maps app names β†’ Homebrew Cask tokens (60+ built-in mappings)
  2. For unmapped apps, auto-generates a token from the name (lowercase, hyphens)
  3. Queries https://formulae.brew.sh/api/cask/<token>.json
  4. Caches responses for 1 hour to avoid hitting the API repeatedly
  5. Compares versions using sort -V (handles semver correctly)

Adding Custom App Mappings

Edit the CASK_MAP array at the top of the script:

CASK_MAP=(
    # Your custom mappings
    ["My Internal App"]="my-internal-cask"
    ["Company Tool"]="company-tool"
    ...
)

Or use the version-check-apps.json from the pa-lsagent repo for centralized config.


πŸ“„ lsagent.ini Field Reference

Field Purpose Action
Server Lansweeper server hostname or IP ✏️ Verify/correct if agent isn’t reporting
Port Communication port (default 9524) ✏️ Match your server config
Field7 Last scan timestamp cache πŸ—‘οΈ Clear to force fresh scan
Field8 Scan result/status cache πŸ—‘οΈ Clear to force fresh scan
Other fields Various agent state values ✏️ Edit only if directed by Lansweeper support

πŸ’‘ Tip: View the ini manually to confirm your exact field names:

sudo cat "/Library/Application Support/LanSweeper/LsAgent/lsagent.ini"

πŸ”§ Troubleshooting

LsAgent won’t stop

# Force kill by process name
sudo pkill -9 -f lsagent
# Confirm
pgrep -f lsagent && echo "Still running" || echo "Stopped"

lsagent.ini not found

# Search for it
sudo find / -name "lsagent.ini" 2>/dev/null

Update INI_PATH at the top of the script to match.

LsAgent won’t restart

# Manually load the plist
sudo launchctl load /Library/LaunchDaemons/com.lansweeper.lsagent.plist
# Check system logs
log show --predicate 'process == "lsagent"' --last 10m

Agent reports but scan doesn’t update in Lansweeper

Backup restore

# List backups
ls "/Library/Application Support/LanSweeper/LsAgent/"*.bak.*

# Restore most recent
sudo cp "/Library/Application Support/LanSweeper/LsAgent/lsagent.ini.bak.YYYYMMDDHHMMSS" \
        "/Library/Application Support/LanSweeper/LsAgent/lsagent.ini"

check-app-versions.sh shows β€œnot_found” for an app

The app doesn’t have a matching Homebrew Cask. Add a custom mapping:

# In the CASK_MAP array at the top of check-app-versions.sh
["Your App Name"]="homebrew-cask-token"

Find the cask token at formulae.brew.sh/cask.


πŸ“ Files

File Version Description
force-rescan-lsagent.sh v1.1 Interactive LsAgent rescan + settings editor
remote-exec-template.sh v1.1 GoTo Resolve remote execution template
check-app-versions.sh v1.0 Mac app version checker (terminal + JSON)
README.md β€” This documentation

Repo Description
pa-lsagent Power Automate flow β€” syncs Lansweeper data to SharePoint Excel
green-tools Windows PowerShell toolkit β€” system updates, app scanning
little-helper Java console tool β€” WinGet automation, deployment checklists

πŸ“ Notes


Built by GreenHornet-Dev / Custom Design Systems 🟒