Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Agent with Relative Path

Tags:

bash

macos

Is it possible to execute a script in the current user's home directory with a ~/Library/LaunchAgents/ agent? I current have (not working):

<?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.puppies</string>
        <key>OnDemand</key>
        <true/>
        <key>RunAtLoad</key>
        <true/>
        <key>ProgramArguments</key>
        <array>
          <string>/bin/sh</string>
          <string>~/script.sh</string>
        </array>
        <key>StartInterval</key>
        <integer>3600</integer></dict>
</plist>
like image 569
Kevin Sylvestre Avatar asked Dec 04 '13 07:12

Kevin Sylvestre


People also ask

What are launch agents on Mac?

Mac LaunchAgents start when a user logs in. Unlike daemons, they can access the user interface and display information. For example, a calendar app can monitor the user's calendar account for events and notify you when the event occurs.

What is launch daemon in Mac?

Launch Daemons are plist files used to interact with Launchd, the service management framework used by macOS. Launch Daemons require elevated privileges to install, are executed for every user on a system prior to login, and run in the background without the need for user interaction.


1 Answers

Set EnableGlobbing to true:

<key>EnableGlobbing</key>
<true/>
<key>ProgramArguments</key>
<array>
    <string>say</string>
    <string>~/*</string>
</array>

EnableGlobbing enables expanding tildes and globs in ProgramArguments but not in Program. Tildes are expanded in WatchPaths and QueueDirectories by default.

like image 117
Lri Avatar answered Sep 23 '22 05:09

Lri