Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a launchd agent that will run only once?

Tags:

macos

launchd

Since there is no "Year" parameter in the launchd plist format, how is it possible to create an agent that will run only once and not once a year?

like image 553
brandelune Avatar asked Dec 04 '17 15:12

brandelune


People also ask

What is a launch agent?

Launch Agents are often installed to perform updates to programs, launch user specified programs at login, or to conduct other developer tasks. Launch Agents can also be executed using the Launchctl command. Adversaries may install a new Launch Agent that executes at login by placing a .

What is a launch daemon?

Using a launch daemon is another privilege escalation method applicable to Apple-based operating systems, especially OS X. When OS X boots up, launchd is normally run to end system initialization.

Can I delete launch agents Mac?

There's no unique uninstall process for this—simply trash the . plist file and reboot your Mac. Or you can cut and paste it to your desktop to keep a copy to be on the safe side. Don't delete any items from the System LaunchAgents or System LaunchDaemons folders, as they're required for macOS to run smoothly.

What is launchd in IOS?

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 command to load or unload launchd daemons and agents.


2 Answers

Since your reference "Year", I assume you are using StartCalendarInterval. If you don't want to run at an interval, use the RunAtLoad key, which will cause it to run once each time the system starts.

<key>RunAtLoad</key>
    <true/>

Now if you truly only want the script to run once (ever), don't use launchctl at all, just run it once on the command line and be done with it.

like image 161
user6096369 Avatar answered Oct 21 '22 03:10

user6096369


Use the key LaunchOnlyOnce for this:

<key>LaunchOnlyOnce</key>
<true/>

This will launch the agent only once if the system is not rebooted.

like image 2
Tamás Sengel Avatar answered Oct 21 '22 05:10

Tamás Sengel