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?
Asked
Active
Viewed 4,043 times
7

Tamás Sengel
- 55,884
- 29
- 169
- 223

brandelune
- 116
- 1
- 7
-
"Only once" as in once per cold boot or once in the existence of that system? – zneak Dec 05 '17 at 00:37
-
"only once" as in "only once". My understanding is that the fact that Year is not a possible parameter makes any agent minimally a yearly agent since it is not possible to specify a unique date. I want the agent to work only once, on a unique date. – brandelune Dec 05 '17 at 01:44
-
Did you ever get answer to this? I am trying to do the same and my unload script is not working reliably. – OrigamiEye Apr 01 '20 at 11:57
-
Did anyone figure out this? The closest thing I've found is https://discussions.apple.com/thread/2592680?answerId=12334487022#12334487022 but it's not very clear. – Galder Zamarreño May 02 '23 at 15:59
-
I think it's not possible. Because there is no way to set a single point in time. I seem to remember that I posted that question around the time I wrote this blog article: https://mac4translators.blogspot.com/2017/12/automation-scheduling-file-and.html There are plenty of references that I had gathered during the writing process. Maybe you'll find an answer there, but I doubt it. – brandelune May 05 '23 at 03:38
2 Answers
3
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.

user6096369
- 31
- 1
-
Thank you for the hint. The issue is that I want to set an event to take place only once in the future. So it's not like I want to run it right now or want to wait until that time. I want to set the date and be done with it. I do understand that launchd may not be the best tool for that though. – brandelune Jun 20 '18 at 01:28
2
Use the key LaunchOnlyOnce
for this:
<key>LaunchOnlyOnce</key>
<true/>
This will launch the agent only once if the system is not rebooted.

Tamás Sengel
- 55,884
- 29
- 169
- 223
-
1Which is not what I am asking. See my comment above. I need either a way to create a unique date, or a way to unload the agent once it has worked once, etc. If launchd syntax does not allow for that I'm fine, I can use an external script to check that, I just need to know if it's possible within the launchd syntax. – brandelune Dec 05 '17 at 01:49