HomeAppleMaking launchd agent uninstall itself

Making launchd agent uninstall itself


I can inform the launchd agent plist to delete itself by including its full path and modifying it each time for each software, however is there a greater means?

I’m unaware of any launchd .plist setting/command that can enable it to “delete itself.”

When your Mac boots and once you load a .plist, launchd scans (as relevant): /Library/LaunchAgents, ~/Library/LaunchAgents, /Library/LaunchDaemons, /System/Library/LaunchAgents and /System/Library/LaunchDaemons. If the .plist is not there, it would not load.

So, for those who “examine to see if the software exists and take away itself” you will want to include that logic as a part of the script that is kicked off by launchd.

Is there (for instance) a variable I may seize the place the launchd returns its personal identify or path?

launchd would not return “its personal identify or path;” it hundreds/unloads/launches/stops a job outlined by a .plist at a path. Subsequently, in order for you that variable to be out there, you will have to set it as a part of the surroundings outlined within the .plist.

That stated, I do not imagine it attainable you can each have a job operating and concurrently unload it particularly by itself; extra so if it requires elevated privileges to take action. That is most likely why set up/uninstall requires consumer intervention.

Moreover, per the man web page for launchd.plist it addresses brokers/daemons accessing “protected” information/folders:

CAVEATS

Daemons and brokers managed by launchd are topic to macOS consumer privateness protections. Specifying privateness delicate information and folders in a launchd plist might not have the specified impact, and should stop the job from operating.

By having an agent name a script that in impact deletes itself (from one of many directories listed above) might have unintended penalties and should not even run.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments