macOS launchd LaunchAgent daemon

  • Updated

Introduction

Using macOS LaunchAgents, it is possible to automatically link to a LucidLink Filespace upon logging in to a local user account on macOS. 

Workflow Overview

  1. Create the script to launch the lucid daemon
  2. Create the LaunchAgent .plist file
  3. Test loading and unloading the LaunchAgent

Launch Script Setup

  1. Create a script directory in /usr/local/bin:

sudo mkdir -p /usr/local/bin
  1. Create the newlucidlaunch.sh bash script in /usr/local/bin using your preferred text editor.
sudo nano /usr/local/bin/newlucidlaunch.sh

Using the text editor, add the following content. Be sure to change the Filespaceusername, and password to your own details (omitting the <> brackets).

#!/bin/bash
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
lucid daemon --fs filespace.domain --user <yourEmail> --password <password> --mount-point ~/Lucid
  1. Save newlucidlaunch.sh and make it executable:

sudo chmod +x /usr/local/bin/newLucidLaunch.sh

LaunchAgent Property List Setup

1. Create the property list file in /Library/LaunchAgents:

sudo nano /Library/LaunchAgents/com.newlucidlink.startup.plist

Inside the nano editor, add the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.newlucidlink.startup</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/newlucidlaunch.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/com.newlucidlink.startup.out</string>
<key>StandardErrorPath</key>
<string>/tmp/com.newlucidlink.startup.err</string>
</dict>
</plist>

Test Loading and Unloading the LaunchAgent

1. Load the LaunchAgent plist:

launchctl bootstrap gui/$(id -u) /Library/LaunchAgents/com.newlucidlink.startup.plist

Verify the Filespace has mounted.

If it hasn’t, check the logs generated at: /tmp/com.lucidlink.startup.err

2. To unload the LaunchAgent.

launchctl bootout gui/$(id -u) /Library/LaunchAgents/com.newlucidlink.startup.plist

3. Perform a Final Test by logging out and back into the macOS user account and verifying that the LaunchAgent has successfully mounted the Filespace.

Was this article helpful?

0 out of 0 found this helpful