Launch Agent problem

Hello, I have a problem with a particular plist file that executes one of my scripts.

The script executes a named pipe over the command:

pmset -g pslog

in other to monitor the power source and its work perfectly if executed manually or with a cron job.

I am trying to use launchd to execute this script because I am migrating all my automatic script execution over this service.


The content of the net.minilan.ps_observer.plist file is 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>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>
    
    <key>Author</key>
        <string>PB</string>
    <key>Description</key>
        <string>Monitor power state and export over MQTT</string>
    <key>Version</key>
        <string>0.1</string>


    <key>Label</key>
    <string>net.minilan.ps_observer</string>
    
    <key>ProgramArguments</key>
    <array>
      <string>/bin/bash</string>
      <string>~/Development/ps_observer.sh</string>
    </array>
    
    <key>RunAtLoad</key>
    <true/>
    
    <key>KeepAlive</key>
    <dict>
        <key>Crashed</key>
        <true/>
    </dict>
    
    <key>ThrottleInterval</key>
    <integer>10</integer>
</dict>
</plist>


This .plist file is located in ~/Library/LaunchAgents because I no need to execute this with other users or without login users, just with my user.


Then I have loaded it with:

launchctl load ~/Library/LaunchAgents/net.minilan.ps_observer.plist


Unfortunately, that plist file doesn't work.


The cronjob "equivalent" configuration (non exactly equivalent) is:

@reboot cd ~/Development && ./ps_observer.sh


Many thanks for any help.


Mac mini, macOS 10.13

Posted on Jun 4, 2021 8:38 AM

Reply

Similar questions

5 replies

Jun 4, 2021 9:16 AM in response to paolo_83

Script management with launchd

The launchd process is used by macOS to manage daemons and agents, and you can use it to run your shell scripts. You don’t interact with launchd directly; instead you use the launchctl tool to load or unload launchd daemons and agents.

During system startup, launchd is the first process the kernel runs to set up the computer. If you want your shell script to be run as a daemon, it should be started by launchd. Other mechanisms for starting daemons and agents are subject to removal at Apple’s discretion.


https://support.apple.com/guide/terminal/script-management-with-launchd-apdc6c1077b-5d5d-4d35-9c19-60f2397b2369/2.8/mac/10.13

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Launch Agent problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.