LaunchAgent
LaunchAgent copied to clipboard
Error when try to write into /Library/LaunchAgents
Hi,
I tried to save plist file in global agent by changing userDomainMask -> localDomainMask
let library = try FileManager.default.url(for: .libraryDirectory, in: .localDomainMask, appropriateFor: nil, create: false)
then i got error in macOS Ventura 13.2.1
Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “com.test.plist” in the folder “LaunchAgents”." UserInfo={NSFilePath=/Library/LaunchAgents/com.test.plist, NSUnderlyingError=0x600000d4b870 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}
***Note that my application built with sandbox is off.
Do you have any idea? Thanks
@trinhtran-markany
I'm just coming by, but I don't think you have the permission to write to /Library
as a normal user (you might need sudo
or something like that). Hope this helps!
Hi @trinhtran-markany, I somehow missed when you originally opened the issue, but as mentioned even without being sandboxed you can't write to system directories. I believe you need to create a helper tool which actually writes the data that then gets called with elevated privileges.
There's more information in the Authorization Services docs, but the examples are all Obj-C.