Thanks to visit codestin.com
Credit goes to github.com

Skip to content

StrangeRanger/custom-daemon-agents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom macOS Daemons and Agents

Project Tracker

A collection of custom macOS LaunchAgents, LaunchDaemons, and supporting scripts for automating tasks.

If you are unfamiliar with launchd jobs, they are part of macOS's unified service management framework. launchd is the system’s init process, responsible for starting, stopping, and managing jobs — including system daemons, user agents, applications, and scripts — based on configuration and triggers.

If you are interested in learning more about launchd, daemons, agents, and related tools, check out the Additional Resources section of this document.

Table of Contents

Directory Structure

Below is a brief overview of the repository's directory structure, to help you understand its organization:

custom-daemon-agents/
├── agent-scripts/  # AppleScript and shell scripts executed by launchd jobs
└── launch-agents/  # LaunchAgent plist files

Existing Agents and Daemons

The table below lists the LaunchAgents, LaunchDaemons, and their associated scripts in this repository:

launchd Job Associated Script Type Description
local.StrangeRanger.LogitechMonitor logitech-monitor.scpt LaunchAgent Opens Logitech G Hub when a Logitech USB device (Vendor ID 0x046d) is detected.
local.StrangeRanger.MouseMonitor mouse-monitor.scpt LaunchAgent Opens LinearMouse when the configured mouse (by Product ID) is detected.

Launch Agents

These LaunchAgents start automatically upon login, running scripts within your user context.

How to Use

  1. Create a directory for the scripts, then copy them into it:
    mkdir -p ~/.agent-scripts/
    cp agent-scripts/* ~/.agent-scripts/
  2. Copy the .plist files to ~/Library/LaunchAgents/:
    cp launch-agents/* ~/Library/LaunchAgents/
  3. Replace hunter with your username in the .plist files:
    sed -i '' -e 's/\/Users\/hunter/\/Users\/YOUR_USERNAME/' ~/Library/LaunchAgents/PLIST_FILE.plist
  4. Load and start the agent(s):
    • Modern (recommended on recent macOS versions):
      # Load the job
      launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/<plist>
      # Enable the job
      launchctl enable gui/$(id -u)/<Label>
      # (Re)start the job
      launchctl kickstart -k gui/$(id -u)/<Label>
    • Legacy (still works):
      launchctl load ~/Library/LaunchAgents/<plist>

Note

  • If you used a directory other than ~/.agent-scripts/, update the ProgramArguments path(s) in the .plist file(s).

Launch Daemons

Currently, this repository does not contain any LaunchDaemons.

Supported macOS Versions

macOS Version Status Notes
macOS 26 Supported N/A
≤ macOS 15 Unsupported SPUSBDataType isn't available in macOS 26 and later. Use branch 15 instead.

Troubleshooting

The agent is not listed or didn’t start — how can I check status?

Use this to see if the job is loaded in your user domain:

launchctl list | grep StrangeRanger

If it’s not listed, load it using the steps in “How to Use.”

How can I inspect details for a specific agent?

Print the runtime state and last exit status:

launchctl print gui/$(id -u)/local.StrangeRanger.MouseMonitor
launchctl print gui/$(id -u)/local.StrangeRanger.LogitechMonitor
How do I unload, disable, or restart an agent?

Modern commands:

# Stop/unload
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/<plist>
# Disable so it won’t auto-start
launchctl disable gui/$(id -u)/<Label>
# (Re)start immediately
launchctl kickstart -k gui/$(id -u)/<Label>

Legacy alternative:

launchctl unload ~/Library/LaunchAgents/<plist>
launchctl load ~/Library/LaunchAgents/<plist>
Why am I seeing AppleScript alerts from these agents?

On fatal errors, the scripts show an AppleScript alert and then unloads the agent to avoid retry loops. Because they run as LaunchAgents (in your user session), alerts are allowed. If you prefer non‑interactive behavior, remove the alert from the script(s) and log the error instead.

How do I find my device IDs (Vendor ID and Product ID)?

List connected USB devices and filter for IDs:

system_profiler SPUSBHostDataType | grep -E "(Vendor ID|Product ID|Manufacturer)"

Look for lines such as:

Vendor ID: 0x1234
Product ID: 0xabcd

Use those values to set the vendorID and/or product ID variables in the AppleScript(s) for your specific hardware.

Additional Resources

Support and Issues

Please use GitHub Issues for bug reports.

License

This project is licensed under the MIT License.

About

Contains the source code of custom Daemons and Agents for macOS.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published