Service Management

RSS for tag

The Service Management framework provides facilities to load and unload launched services and read and modify launched dictionaries from within an application.

Posts under Service Management tag

200 Posts

Post

Replies

Boosts

Views

Activity

What does the Legacy Background Tasks toggle do on macOS 15?
On macOS 15 Sequoia, there is a new Legacy Background Tasks toggle in System Settings > Login Items & Extensions. It seems to initially appear (in an "on" state) when an app tries to install a launchd job and places a launch plist in /Library/LaunchDaemons. I have not found any effects of turning this toggle off. I still seem to be able to happily use launchctl bootstrap and launchctl bootout, for example. What does this toggle do? Is there a WWDC session or documentation I haven't found yet?
1
2
1.6k
Jun ’24
Issue with LaunchDaemon running bash showing up as unidentified developer
I have a couple of LaunchDaemon installed helper executables that are calling a bash script. As of MacOS 13, these are now showing up as unidentified developer in Login Items which I am trying to resolve. I have tried setting AssociateBundleIdentifiers in my plist file but the console tells me it is being ignored because bash does not have a Team Identifier. I believe the fully correct way to resolve this is to switch to the new Service Management API, but my understanding is that would only work on MacOS 13 and would therefore break my app on older versions of MacOS My questions are: is there any other way to make my helper as part of my app's login items that I have missed? is there an easy way to make an installer that will work for both newer and older versions of MacOS without having to package two separate versions? Sample plist file: <?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>AssociatedBundleIdentifiers</key> <array> <string>com.mycompany.ExampleApp</string> </array> <key>Label</key> <string>com.mycompany.ExampleApp.updater</string> <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>/var/root/Library/Group Containers/com.mycompany.ExampleApp/Library/Application Support/update.sh</string> </array> <key>StandardOutPath</key> <string>/var/root/Library/Group Containers/com.mycompany.ExampleApp/Library/update.log</string> <key>WorkingDirectory</key> <string>/var/root/Library/Group Containers/com.mycompany.ExampleApp/Library/Application Support/</string> <key>WatchPaths</key> <array> <string>/var/root/Library/Group Containers/com.mycompany.ExampleApp/Library/Application Support/latest.app.zip</string> </array> </dict> </plist>
1
0
866
May ’24
Restarting my SSH ( forgot my pass )
Emiliss-MacBook-Air ~ % launchctl bootout Usage: launchctl bootout [service-path1, service-path2, ...] | emiliscy@Emiliss-MacBook-Air ~ % sudo launchctl unload /System/Libraly/LaunchDae mons/ssh.plist Unload failed: 5: Input/output error Try running launchctl bootout as root for richer errors. I don't understand what's happening please help me I can't connect github rep with visual studio.
0
0
667
May ’24
How to identify If my executable is launched as User Agent in macOS
I have an executable in macOS that I m launching as a User Agent. The same executable can be launched in multiple ways like either user can directly click the exe to launch it, or user can launch it from the terminal using ./ etc. One similar way is when the user launches the exe as a User Agent(i.e daemon in user session). In this scenarios, I want to identify in my exe If my user has launched it as agent to perform certain task. I wanted to know how can I accurately determine this? I have tried figuring out If there is some unique session that agents operate in, but I could not find anything. Can someone help here? Is this even possible?
1
0
848
May ’24
launching a custom process with launchd is wiping out other application files
I built a custom binary which requires elevated privileges to execute. I wrote a launchd plist file and loaded it. On loading , the app is working as expected but lot of apps were corrupted. Apps like chrome, slack, zoom etc became un openable . Even my mouse right click stopped working. When I looked at the contents of the chrome in application directory it was missing few files. contents of chrome before launching my custom app -rw-r--r--@ 1 myusername admin 2556 May 14 16:49 CodeResources drwxr-xr-x@ 3 myusername admin 96 May 14 15:59 Frameworks -rw-r--r--@ 1 myusername admin 11851 May 14 16:17 Info.plist drwxr-xr-x@ 3 myusername admin 96 May 14 15:59 Library drwxr-xr-x@ 3 myusername admin 96 May 14 16:17 MacOS -rw-r--r--@ 1 myusername admin 8 May 14 15:59 PkgInfo drwxr-xr-x@ 61 myusername admin 1952 May 14 15:59 Resources drwxr-xr-x@ 3 myusername admin 96 May 14 16:17 _CodeSignature -rw-r--r--@ 1 myusername admin 12551 May 14 15:59 embedded.provisionprofile contents of chrome after launching my custom app drwxr-xr-x@ 3 myusername admin 96 May 14 15:59 Frameworks drwxr-xr-x@ 3 myusername admin 96 May 14 15:59 Library drwxr-xr-x@ 2 myusername admin 64 May 16 13:48 MacOS drwxr-xr-x@ 58 myusername admin 1856 May 16 13:48 Resources drwxr-xr-x@ 2 myusername admin 64 May 16 13:48 _CodeSignature my custom app plist file &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;com.zzzz.xxxx&lt;/string&gt; &lt;key&gt;Program&lt;/key&gt; &lt;string&gt;/path/to/app&lt;/string&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/plist&gt; If i run my custom app as a standalone process everything works as expected, no corruption or data loss. To restore the apps, I reinstalled them. But cant figure out why this is happening. Also not sure how to make secondary click work again. I tried with multiple mouses , same issue. Any help on this is appreciated.
1
0
678
May ’24
Shutdown event in macOS
I wanted to identify the shutdown event in macOS, so that If my application is running and the user performs a system shutdown then my application could be notified of the shutdown event and perform finalization. I came across NSWorkspaceWillPowerOffNotification which is exactly what I require, however, I created a sample application to observe for this notification. Is is observed that right before the system shuts down, the OS terminates my application invoking applicationWillTerminate(_:) delegate and the observer method for 'NSWorkspaceWillPowerOffNotification' is not invoked. I could perform my finalization in the applicationWillTerminate, but I wanted to know why is the observer not getting invoked. Also why is NSWorkspaceWillPowerOffNotification, even provided by apple when it invoked the termination delegate before shutdown? below is how I m adding the observer: NotificationCenter.default.addObserver(forName: NSWorkspace.willPowerOffNotification, object: nil, queue: nil, using: AppDelegate.handlePowerOffNotification) Below is my observer function, which just logs: public static func handlePowerOffNotification(_ notification: Notification) { NSLog (AppDelegate.TAG + "System will power off soon! Perform any necessary cleanup tasks.") // custom logger to log to a file TWLog.Log ("System will power off soon! Perform any necessary cleanup tasks.") }
3
0
1.3k
May ’24
Background processing options for Mac App Store apps?
I'm busy designing my app's functionality and really would like to provide some features that rely on background processing after the user has logged in. A Login Item seems ideal for this use case. I appreciate the lengths Apple go to, to communicate the complex technologies involved in app development, including the planning of macOS apps. I haven't found any information in the planning and design (admittedly under HIGs) documentation on whether it's possible to provide some background processing element along with an app destined for the Mac App Store. Perhaps it's not mentioned for a reason? However, it would be really useful to background processing dealt with up-front, especially under planning, because it has a huge impact on how one moves forward with product design. Especially when you're an indy developer with limited time and resources. I can't, for the life of me, find where I previously read that daemons and agents weren't allowed to be shipped with a Mac App Store app, because of the Sandbox requirements. It was probably a reply by Eskimo somewhere in the forums. Does the same apply to Login Items? The bulk of the Login Item documentation is in the documentation archive, most of which was written before the existence of the app stores, so I couldn't find any answers there. I previously believed that an app destined for the Mac App Store could only include a single binary, that of the main app itself. Although I've seen the recent article on including a command line utility binary in the distribution too. Also, if my understanding of code signing is correct, apps distributed via an app store are signed by Apple, and thus can't communicate via XPC with a binary signed and distributed via a Developer ID. Or is there some workaround there that might get me closer to my goal?
5
1
1.5k
Apr ’24
Launching agent installed with SMAppService
I am attempting to install and utilize an agent using the new(ish) SMAppService API with an existing app. The agent appears to install (no error is returned), but when I try to start the agent from Terminal, I get the following in the launchd.log: 2024-04-22 09:57:27.469039 (gui/502/com.redacted.service.agent) : internal event: WILL_SPAWN, code = 0 2024-04-22 09:57:27.469080 (gui/502/com.redacted.service.agent) : service state: spawn scheduled 2024-04-22 09:57:27.469081 (gui/502/com.redacted.service.agent) : service state: spawning 2024-04-22 09:57:27.469100 (gui/502/com.redacted.service.agent) : launching: one-shot 2024-04-22 09:57:27.469105 (gui/502/com.redacted.service.agent) : Allowing non-reentrant proxy for resolving path 2024-04-22 09:57:27.469947 (gui/502/com.redacted.service.agent [71866]) : xpcproxy spawned with pid 71866 2024-04-22 09:57:27.469960 (gui/502/com.redacted.service.agent [71866]) : internal event: SPAWNED, code = 0 2024-04-22 09:57:27.469964 (gui/502/com.redacted.service.agent [71866]) : service state: xpcproxy 2024-04-22 09:57:27.469997 (gui/502/com.redacted.service.agent [71866]) : internal event: SOURCE_ATTACH, code = 0 2024-04-22 09:57:27.506283 (gui/502/com.redacted.service.agent [71866]) : Service could not initialize: posix_spawn(/Users/chrisf/Library/Developer/Xcode/DerivedData/Redacted-gttupgdyakodzddurpavhmscwabs/Build/Products/Debug/Redacted App.app/Contents/MacOS/Service Agent.app), error 0xd - Permission denied 2024-04-22 09:57:27.506306 (gui/502/com.redacted.service.agent [71866]) : initialization failure: 23E224: xpcproxy + 31420 [1098][A7EF179C-FBCC-349E-A7D2-09B2F1408413]: 0xd 2024-04-22 09:57:27.506309 (gui/502/com.redacted.service.agent [71866]) : internal event: INIT, code = 13 2024-04-22 09:57:27.506313 (gui/502/com.redacted.service.agent [71866]) : job state = spawn failed 2024-04-22 09:57:27.507148 (gui/502/com.redacted.service.agent [71866]) : xpcproxy exited due to exit(78) 2024-04-22 09:57:27.507153 (gui/502/com.redacted.service.agent [71866]) : exited due to exit(78) 2024-04-22 09:57:27.507162 (gui/502/com.redacted.service.agent [71866]) : already handled failed init, ignoring 2024-04-22 09:57:27.507170 (gui/502/com.redacted.service.agent [71866]) : service state: exited 2024-04-22 09:57:27.507186 (gui/502/com.redacted.service.agent [71866]) : internal event: EXITED, code = 0 (tldr: error 0xd - Permission denied) I'd also be curious how we are expected to launch agents once registered with SMAppService. Is it sufficient simply to make an XPC call to an exposed method? Thanks!
1
0
1.3k
Apr ’24
What is the file permission between the Root and Admin account
I'm a bit confuse on the file permission between root and admin account. I'm developing the background user agent process, and I created the agent plist file with the permission R&amp;W for my admin account. When I tried to load my agent process with launchd, it said the plist file permission is not right. Only after I change the plist file owner to root chown root my.plist, did everything work. From the above situation, it seems that the root user cannot access files that are only authorized to the admin user. Admin account also can't access files authorized only to root, unless you add sudo or enter the password when the request admin password box pops up. But by sudo or password, it just temporarily converts your account from admin to root account. So am I right in my speculation?
1
0
1.1k
Apr ’24
launchctl load and unload com.vivi.control.serviceAgent.plist get error 5: Input/output error
1、 my plist /Library/LaunchAgents/com.vivi.control.serviceAgent.plist like this: &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;com.vivi.control.serviceAgent&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt; &lt;string&gt;/Users/yuellppa/Downloads/vivo_test&lt;/string&gt; &lt;/array&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/plist&gt; when the label is other any name but not "com.vivi.control.serviceAgent", use launchctl load /Library/LaunchAgents/com.vivi.control.serviceAgent.plist and launchctl unload /Library/LaunchAgents/com.vivi.control.serviceAgent.plist is ok. when label is "com.vivi.control.serviceAgent", launchctl load or launchctl unload get error 5: Input/output error. use launchctl list | grep com.vivi.control.serviceAgent get nothing, so has no conflicting service。 Can anyone help me take a look?
2
0
1.8k
Apr ’24
Running .app bundled application in non GUI environment causing app to fail at runtime
I am having a bundled application(.app file) and I am wanting to run this application via ssh session which does not have GUI access. Launching this application in a desktop GUI session, runs the application perfectly. However, on running it on the same machine via ssh session produces an error. Note: My application does not bring up any GUI window(it' just produces some logs on the terminal), so running it in a non-GUI environment should have worked. I get the below error when trying to launch the unix exe in the .app bundle( ./Myapp.app/Contents/MacOS/Myapp ) on the terminal. I have observed that applicationDidFinishLaunching(_:) gets called and then the below error occurs. +[NSXPCSharedListener endpointForReply:withListenerName:replyErrorCode:]: an error occurred while attempting to obtain endpoint for listener 'ClientCallsAuxiliary': Connection interrupted I tried running other bundled applications via ssh, but all seems to produce the same error. Can someone confirm Is running bundled application in a non GUI session not allowed by Apple. If its allowed, how can I solve this? Even running the .app file using the open command fails to launch the application, although it produces a different error which is consistent across different applications.
1
0
922
Apr ’24
Launch Agent service not starting post login
We have a test scenario where we install our app package on a Mac setup using MDM (Jamf). Below are the test steps and observation: This installation is done on this Mac with no user logged in. Installation is completed successfully. Now when an user log in on this mac machine, the expectation is that the app bundle will be started by the launchd (RunAtLoad). But the app is not started. When I check console logs I could see few logs around the app but from those logs I couldn't figure out why the app didn't start. I rebooted my test machine but that also didnt start my app. My app is not listed in 'launchctl list' command. My App bundle contains container app and a packet tunnel extension. Below is how my plist file looks like in '/Library/LaunchAgents/com.****.***ui.plist': { KeepAlive = 1; Label = "com.*****.client.****ui"; LimitLoadToSessionType = ( Aqua ); ProgramArguments = ( "/Applications/*********.app/Contents/MacOS/****Module" ); RunAtLoad = 1; SuccessfulExit = 1; Version = "110.200.0.100"; } In Console below are the last set of log which I could find related to my app: support_log.txt In above logs below statement mentions the extn which is related to my app bundle: 2024-03-19 15:48:55.256020+0530 0x462 Default 0x0 206 0 symptomsd: (SymptomEvaluator) [com.apple.symptomsd:analytics] [Skipping first 85 of 95 entries] 2024-03-19 15:48:55.256051+0530 0x462 Default 0x0 206 0 symptomsd: (SymptomEvaluator) [com.apple.symptomsd:analytics] entry: Thu Feb 8 20:48:26 2024 NetworkExtension.com.*****.client.*****-Client.*****ui.*****pkttunnel.104.2.12.191.104.2.12 (bundle) 0 0 0 0 0 0 Can someone please help me in understanding what could be wrong here, why would 'RunAtLoad' key word wont work here to start my app on user login or reboot? Note: Everything work fine when my app is installed with an user logged in to the test machine. Also App starts successfully if I run command 'lauchctl bootstrap gui/ /Library/LaunchAgents/com.****.****ui.plist' in the above mentioned test scenario where app didnt auto start by launchd: 'RunAtLoad'.
8
0
1.6k
Mar ’24
launchctl fails with "Bootstrap failed: 5: Input/output error", if the app is signed with sandbox
I am implementing parental control app via python 3.9 for macOS. Therefore I want to use launch agent to keep my application always alive (app reopened automatically after reboot pc and protected against to be closed via activity monitor.) I want to give keep alive enabling and disabling option to parents that they can deactivate or activate it in the app GUI. I achieved to keep alive my app standalone signed app without sandboxing(or via Terminal command) but if I sign it with sandbox then I get following error for "launchctl load" and "launchctl bootstrap" commands which are executed in the application "Load failed: 5: Input/output error" My steps without Sandbox which works fine: 1- Create a com.test_gui.macos.plist file under /Library/LaunchAgents with following content: `<?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>KeepAlive</key> <true/> <key>Label</key> <string>test_gui</string> <key>ProgramArguments</key> <array> <string>open</string> <string>-g</string> <string>-a</string> <string>/Applications/test_gui.app</string> </array> </dict> </plist>` 2- create a python file for launch agent activation (I know either launchctl load or bootstrap should be used but I used both of them to test both.): import subprocess cmd = "launchctl enable gui/501/test_gui" response = subprocess.call(cmd, shell=True) time.sleep(2) cmd = "launchctl load -w /Library/LaunchAgents/com.test_gui.macos.plist" response = subprocess.call(cmd, shell=True) time.sleep(2) cmd = "launchctl bootstrap system /Library/LaunchAgents/com.test_gui.macos.plist" response = subprocess.call(cmd, shell=True) time.sleep(50) 3- Create standalone app via nutika: python3.9 -m nuitka --run --standalone --macos-disable-console --macos-create-app-bundle \--macos-app-mode=ui-element --enable-plugin=pyside6 --macos-app-icon=/Users/emre/Documents/MrProtect/icons/app_icon.png \--include-data-dir=icons=icons test_gui.py 4-Create a .sh file to sign app without sandboxing: #!/bin/sh APP_PATH="/Users/emre/Documents/tests/Deployment/test_gui.app" SIGNING_IDENTITY_APP="Apple Development: Emre Guenay (xxx)" PASSWORD="xxx" codesign -s "$SIGNING_IDENTITY_APP" -f \ "$APP_PATH/Contents/MacOS/Python" codesign -s "$SIGNING_IDENTITY_APP" -f \ "$APP_PATH/Contents/MacOS/test_gui" exit 0 5-execute sh file and see following output: /Users/emre/Documents/MrProtect/tests/Deployment/test_gui.app/Contents/MacOS/Python: replacing existing signature /Users/emre/Documents/MrProtect/tests/Deployment/test_gui.app/Contents/MacOS/test_gui: replacing existing signature 6-copy paste signed standalone app(without sandbox) file under /Applications/ 7-execute app and try to close app via activity monitor and observe that the app is reopened automatically. so the launch agent works fine Failed Steps(Sign the same app with sandbox and observe that both launchctl load and bootstrap returns "Load failed: 5: Input/output error") 8- create an app.entitlements file with following content: \<?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\>com.apple.security.app-sandbox\</key\> \<true/\> \</dict\> \</plist\> 9-Create a .sh file to sign app with sandboxing: #!/bin/sh # APP_PATH="/Users/emre/Documents/tests/Deployment/test_gui.app" SIGNING_IDENTITY_APP="Apple Development: Emre Guenay (xxx)" PASSWORD="xxx" codesign -s "$SIGNING_IDENTITY_APP" -f \ \--entitlements app.entitlements \ "$APP_PATH/Contents/MacOS/Python" codesign -s "$SIGNING_IDENTITY_APP" -f \ \--entitlements app.entitlements \ "$APP_PATH/Contents/MacOS/test_gui" exit 0 10-execute sh file and see following output: /Users/emre/Documents/MrProtect/tests/Deployment/test_gui.app/Contents/MacOS/Python: replacing existing signature /Users/emre/Documents/MrProtect/tests/Deployment/test_gui.app/Contents/MacOS/test_gui: replacing existing signature 11-execute app and try to close app via activity monitor and observe that the app is closed although app started the launch agent. 12-you can re-execute app under /Applications/test_gui.app/Contents/MacOS folder with "./test_gui" or even with sudo "sudo ./test_gui" commands you would see following error message for both launchctl load and bootstrap returns: "Load failed: 5: Input/output error". So if you close the app, it will not be re-opened Moreover console tool launchd.log output shows also (1: Operation not permitted) error for launchctl load and bootstrap commands My questions: 1-Is there any other method different than launch agent for keep alive? I researched it in internet but I could not find any other method unfortunately. Moreover launch agent is not user friendly anyway, with the reason that sandboxed apps cannot copy paste any files under LaunchAgents folder automatically. I am planning to provide my plist file to users that they can copy paste the file themself into launch agent folder out of sandbox. 2-How can i get rid of "Load failed: 5: Input/output error", thereby I can proceed at least with lanuchctl? What I have tried additionally: 1-I have also tried to use these linux commands, before executing my sandboxed standalone app file: sudo -S chown 600 /Library/LaunchAgents/com.test_gui.macos.plist sudo -S chown root:wheel /Library/LaunchAgents/com.test_gui.macos.plist 2-I have already given security fulldisk access to my test_gui app, but it also did not work My Requirements: Nuitka: 1.9rc5 Commercial: None Python: 3.9.12 (v3.9.12:b28265d7e6, Mar 23 2022, 18:22:40) Flavor: CPython Official Executable: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 OS: Darwin Arch: x86_64 Version C compiler: /usr/bin/clang (clang). macOS Sonoma: 14.2.1
1
0
5k
Mar ’24
MacOS 14.4 ServiceManagement, cannot install sandboxed daemon from sandboxed main application anymore
I have made an app that requires a daemon to run. For this I use the ServiceManagement framework and the SMAppService.register to register the daemon. The macOS 14.4 update broke the installation process and the daemon cannot be installed anymore and instead returns an error when trying to install the helper. The installation works on MacOS 14.3.1 or lower. I have narrowed the error to the main app being sandboxed. Both the daemon and the main app are sandboxed (as MacOS 14.2 introduced the restriction that a sandboxed app can only run/install a sandboxed daemon, https://developer.apple.com/documentation/macos-release-notes/macos-14_2-release-notes#ServiceManagement). I have been able to confirm that removing the sandbox on the main application results in the register function working again on MacOS 14.4. However, the release notes of 14.4 do not mention anything regarding the ServiceManagement API or something related. So my question is, what has changed in MacOS 14.4 so that the register function for a daemon causes an error when the main app is sandboxed? And moreover, how can I prevent this error without removing the sandbox -- Information regarding the error: The .register function returns the following error: Error Domain=SMAppServiceErrorDomain Code=22 "Invalid argument" UserInfo={NSLocalizedFailureReason=Invalid argument I have also created a log file according to the procedure at the link below and attached it to this post: https://forums.developer.apple.com/forums/thread/707482#716553022 It appears from the log file and from observing the logs in the Console app, that the error "plist changed between client and smd" causes the issue but I don't understand what causes this error out2 2.log -- (I already use the com.apple.security.temporary-exception.sbpl entitlement in the daemon such that it can write to a specific file that the pmset command write to when invoked. This to indicate that I would prefer to keep the main app sandboxed as well. As I could also just remove the sandbox but I don't want to do that)
2
0
1.3k
Mar ’24
LaunchDaemons not launching my app, but LaunchAgents launch it instead
I am developing an app, in this case for macOS. My app has two parts: A GUI A Server From the GUI i can start and stop the serve. My problem is that i need the server starts when the mac boots. Using the LaunchAgents i got to launch it when the user logins on, but i need to initiate it before. I saw that i need to saving my .plis inside of /Library/LaunchDaemons. I did it but when i restart the computer the server didn t initiate. I checked that my service gave me the status 1 so, it didn t launch correctly. Maybe the failure is inside the plist... but i dont understand why it works in LaunchAgent and not inside LaunchDaemons My plist is: &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;com.turnoffpc.turnoffpcplist&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt; &lt;string&gt;/Applications/Turn Off PC.app/Contents/Resources/Turn Off PC/Server/dist/turn_off_pc_server.app/Contents/MacOS/turn_off_pc_server&lt;/string&gt; &lt;/array&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/plist&gt; For loading the service im using the following sh: #!/bin/bash # Copiar el archivo plist a /Library/LaunchDaemons/ sudo cp com.turnoffpc.turnoffpcplist.plist /Library/LaunchDaemons/ # Establecer los permisos adecuados sudo chown root:wheel /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist sudo chmod 644 /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist # Descargar y luego cargar el servicio utilizando launchctl sudo launchctl unload /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist sudo launchctl load /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist I checked that the service is in the correct location The path to my app is: inside /Applications Turn Off PC.app Resources Turn Off PC - Server - dist - turn_off_pc_server.app - Contents - MacOS - turn_off_pc_server Someone sees the error or the thing that i am doing wrong? Thanks in advance
2
0
1.8k
Mar ’24
Launchctl unable start service with error 0x1 - Operation not permitted after app signing updated
Hi, we are working on an application which will perform scheduled backup tasks in macOS 14. The app has been granted full disk permission. Recently we updated the code signing for the executable (/Applications/MyApp.app/Contents/MacOS/MyApp below) for passing the new notarization. After that, we found launchctl unable to load the plist for the schedule job &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;com.MyApp.scheduler&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt; &lt;string&gt;/Applications/MyApp.app/Contents/MacOS/MyApp&lt;/string&gt; &lt;string&gt;/Applications/MyApp.app&lt;/string&gt; &lt;/array&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;key&gt;AbandonProcessGroup&lt;/key&gt; &lt;true/&gt; &lt;key&gt;WorkingDirectory&lt;/key&gt; &lt;string&gt;/Applications/MyApp.app/bin&lt;/string&gt; &lt;/dict&gt; &lt;/plist&gt; Related error message found in /var/log/com.apple.xpc.launchd/launchd.log* 2023-12-13 13:59:34.639672 (system/com.MyApp.scheduler [13434]) &lt;Notice&gt;: internal event: SOURCE_ATTACH, code = 0 2023-12-13 13:59:34.644530 (system/com.MyApp.scheduler [13434]) &lt;Error&gt;: Service could not initialize: posix_spawn(/Applications/MyApp.app/Contents/MacOS/MyApp), error 0x1 - Operation not permitted 2023-12-13 13:59:34.644545 (system/com.MyApp.scheduler [13434]) &lt;Error&gt;: initialization failure: 23C64: xpcproxy + 38300 [1097][925DE4E7-0589-3B33-BB64-7BC2F8629897]: 0x1 2023-12-13 13:59:34.644548 (system/com.MyApp.scheduler [13434]) &lt;Notice&gt;: internal event: INIT, code = 1 2023-12-13 13:59:34.644915 (system/com.MyApp.scheduler [13434]) &lt;Notice&gt;: xpcproxy exited due to exit(78) We have tried to update the entitlements for library and main executable files while still not success on make it works again. We have no idea what else could do for troubleshooting this. &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;com.apple.security.cs.allow-jit&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.cs.allow-unsigned-executable-memory&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.cs.disable-library-validation&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.cs.allow-dyld-environment-variables&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.cs.debugger&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.application-identifier&lt;/key&gt; &lt;string&gt;...&lt;/string&gt; &lt;key&gt;com.apple.developer.team-identifier&lt;/key&gt; &lt;string&gt;...&lt;/string&gt; &lt;/dict&gt; &lt;/plist&gt; Appreciate for any suggestions. Thank you.
2
0
1.4k
Mar ’24
SMAppService: registerAndReturnError fails with Codesigning failure loading plist code: -67054
When registering the LaunchDaemons of the application using SMAppService:registerAndReturnError, I am seeing the below error. The operation couldn’t be completed. Codesigning failure loading plist: <plist name> code: -67054 Above issue is seen only on Ventura 13.0.1 and Ventura 13.1 versions. It is working fine on Ventura 13.5, Ventura 13.6 and Sonoma 14.2 as well. When I checked the system logs using sudo log stream --debug --info --predicate "process in { '<my process>', 'smd', 'backgroundtaskmanagementd'} and sender in {'ServiceManagement', 'BackgroundTaskManagement', 'smd', 'backgroundtaskmanagementd'}" I see below error 2024-02-27 16:02:22.382487+0530 0x4c006 Error 0x0 321 0 smd: [com.apple.libxpc.SMAppServiceShared:all] Static code signature check failed: -67054 2024-02-27 16:02:22.382500+0530 0x4c006 Error 0x0 321 0 smd: [com.apple.libxpc.SMAppServiceShared:all] Unable to validate code signature on bundle for <private>. Code: -67054 2024-02-27 16:02:22.384288+0530 0x4c006 Error 0x0 321 0 smd: [com.apple.xpc.smd:SMAppServiceFactory] Unable to load plist: <private> subpath: <private> status: -67054 There is no difference in the code between. There is no modification to the application bundle after codesigning in both cases (working and not working). Can someone let me know why is there a difference in the behavior in the earlier Ventura versions? Any steps to debug and resolve this issue would be highly appreciated. Thanks
1
0
1.1k
Mar ’24
Setup LaunchAgent in Xcode
Hi there :) I try to put an Xcode project in place within a LaunchAgent. The ultimate goal is to have an "application" with two component: macOS application with just an basic UI all the logic happens in a LaunchAgent that runs on background and is launch at startup. The macOS app uses XPC to send messages to the agent that will run either the app is opened or not. I struggled at first having this error (for the agent): An XPC Service cannot be run directly. Then I found using MachServices key in the .plist of the agent fixes the issue, plus: let listener = NSXPCListener.init(machServiceName: "com.tonygo.NetworkMonitorAgent") Then I wonder: Do we have somewhere a documentation about how to setup a LaunchAgent in Xcode I create the plist of the agent on side and run it manually, I could do this in a more automatic way How could I package a macOS applciation that will contains the agent, install it and load the agent? Note: This is mainly for learning and understanding what we could do at each level (XPCService, LaunchAgents, LaunchDaemon, etc.).
23
0
4.3k
Feb ’24
What does the Legacy Background Tasks toggle do on macOS 15?
On macOS 15 Sequoia, there is a new Legacy Background Tasks toggle in System Settings > Login Items & Extensions. It seems to initially appear (in an "on" state) when an app tries to install a launchd job and places a launch plist in /Library/LaunchDaemons. I have not found any effects of turning this toggle off. I still seem to be able to happily use launchctl bootstrap and launchctl bootout, for example. What does this toggle do? Is there a WWDC session or documentation I haven't found yet?
Replies
1
Boosts
2
Views
1.6k
Activity
Jun ’24
Issue with LaunchDaemon running bash showing up as unidentified developer
I have a couple of LaunchDaemon installed helper executables that are calling a bash script. As of MacOS 13, these are now showing up as unidentified developer in Login Items which I am trying to resolve. I have tried setting AssociateBundleIdentifiers in my plist file but the console tells me it is being ignored because bash does not have a Team Identifier. I believe the fully correct way to resolve this is to switch to the new Service Management API, but my understanding is that would only work on MacOS 13 and would therefore break my app on older versions of MacOS My questions are: is there any other way to make my helper as part of my app's login items that I have missed? is there an easy way to make an installer that will work for both newer and older versions of MacOS without having to package two separate versions? Sample plist file: <?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>AssociatedBundleIdentifiers</key> <array> <string>com.mycompany.ExampleApp</string> </array> <key>Label</key> <string>com.mycompany.ExampleApp.updater</string> <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>/var/root/Library/Group Containers/com.mycompany.ExampleApp/Library/Application Support/update.sh</string> </array> <key>StandardOutPath</key> <string>/var/root/Library/Group Containers/com.mycompany.ExampleApp/Library/update.log</string> <key>WorkingDirectory</key> <string>/var/root/Library/Group Containers/com.mycompany.ExampleApp/Library/Application Support/</string> <key>WatchPaths</key> <array> <string>/var/root/Library/Group Containers/com.mycompany.ExampleApp/Library/Application Support/latest.app.zip</string> </array> </dict> </plist>
Replies
1
Boosts
0
Views
866
Activity
May ’24
Restarting my SSH ( forgot my pass )
Emiliss-MacBook-Air ~ % launchctl bootout Usage: launchctl bootout [service-path1, service-path2, ...] | emiliscy@Emiliss-MacBook-Air ~ % sudo launchctl unload /System/Libraly/LaunchDae mons/ssh.plist Unload failed: 5: Input/output error Try running launchctl bootout as root for richer errors. I don't understand what's happening please help me I can't connect github rep with visual studio.
Replies
0
Boosts
0
Views
667
Activity
May ’24
How to identify If my executable is launched as User Agent in macOS
I have an executable in macOS that I m launching as a User Agent. The same executable can be launched in multiple ways like either user can directly click the exe to launch it, or user can launch it from the terminal using ./ etc. One similar way is when the user launches the exe as a User Agent(i.e daemon in user session). In this scenarios, I want to identify in my exe If my user has launched it as agent to perform certain task. I wanted to know how can I accurately determine this? I have tried figuring out If there is some unique session that agents operate in, but I could not find anything. Can someone help here? Is this even possible?
Replies
1
Boosts
0
Views
848
Activity
May ’24
launching a custom process with launchd is wiping out other application files
I built a custom binary which requires elevated privileges to execute. I wrote a launchd plist file and loaded it. On loading , the app is working as expected but lot of apps were corrupted. Apps like chrome, slack, zoom etc became un openable . Even my mouse right click stopped working. When I looked at the contents of the chrome in application directory it was missing few files. contents of chrome before launching my custom app -rw-r--r--@ 1 myusername admin 2556 May 14 16:49 CodeResources drwxr-xr-x@ 3 myusername admin 96 May 14 15:59 Frameworks -rw-r--r--@ 1 myusername admin 11851 May 14 16:17 Info.plist drwxr-xr-x@ 3 myusername admin 96 May 14 15:59 Library drwxr-xr-x@ 3 myusername admin 96 May 14 16:17 MacOS -rw-r--r--@ 1 myusername admin 8 May 14 15:59 PkgInfo drwxr-xr-x@ 61 myusername admin 1952 May 14 15:59 Resources drwxr-xr-x@ 3 myusername admin 96 May 14 16:17 _CodeSignature -rw-r--r--@ 1 myusername admin 12551 May 14 15:59 embedded.provisionprofile contents of chrome after launching my custom app drwxr-xr-x@ 3 myusername admin 96 May 14 15:59 Frameworks drwxr-xr-x@ 3 myusername admin 96 May 14 15:59 Library drwxr-xr-x@ 2 myusername admin 64 May 16 13:48 MacOS drwxr-xr-x@ 58 myusername admin 1856 May 16 13:48 Resources drwxr-xr-x@ 2 myusername admin 64 May 16 13:48 _CodeSignature my custom app plist file &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;com.zzzz.xxxx&lt;/string&gt; &lt;key&gt;Program&lt;/key&gt; &lt;string&gt;/path/to/app&lt;/string&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/plist&gt; If i run my custom app as a standalone process everything works as expected, no corruption or data loss. To restore the apps, I reinstalled them. But cant figure out why this is happening. Also not sure how to make secondary click work again. I tried with multiple mouses , same issue. Any help on this is appreciated.
Replies
1
Boosts
0
Views
678
Activity
May ’24
Shutdown event in macOS
I wanted to identify the shutdown event in macOS, so that If my application is running and the user performs a system shutdown then my application could be notified of the shutdown event and perform finalization. I came across NSWorkspaceWillPowerOffNotification which is exactly what I require, however, I created a sample application to observe for this notification. Is is observed that right before the system shuts down, the OS terminates my application invoking applicationWillTerminate(_:) delegate and the observer method for 'NSWorkspaceWillPowerOffNotification' is not invoked. I could perform my finalization in the applicationWillTerminate, but I wanted to know why is the observer not getting invoked. Also why is NSWorkspaceWillPowerOffNotification, even provided by apple when it invoked the termination delegate before shutdown? below is how I m adding the observer: NotificationCenter.default.addObserver(forName: NSWorkspace.willPowerOffNotification, object: nil, queue: nil, using: AppDelegate.handlePowerOffNotification) Below is my observer function, which just logs: public static func handlePowerOffNotification(_ notification: Notification) { NSLog (AppDelegate.TAG + "System will power off soon! Perform any necessary cleanup tasks.") // custom logger to log to a file TWLog.Log ("System will power off soon! Perform any necessary cleanup tasks.") }
Replies
3
Boosts
0
Views
1.3k
Activity
May ’24
Ways to automatically start a program when user opens session
Hello, I am trying to enumerate all ways on macOS for launching an application when a user opens a session. Please note i am not looking for a way which requires root or sudo privileges. I have found this: ~/Library/LaunchAgents/ Login Items (in macOS System Settings) But are there others ? Thanks
Replies
1
Boosts
0
Views
752
Activity
May ’24
Background processing options for Mac App Store apps?
I'm busy designing my app's functionality and really would like to provide some features that rely on background processing after the user has logged in. A Login Item seems ideal for this use case. I appreciate the lengths Apple go to, to communicate the complex technologies involved in app development, including the planning of macOS apps. I haven't found any information in the planning and design (admittedly under HIGs) documentation on whether it's possible to provide some background processing element along with an app destined for the Mac App Store. Perhaps it's not mentioned for a reason? However, it would be really useful to background processing dealt with up-front, especially under planning, because it has a huge impact on how one moves forward with product design. Especially when you're an indy developer with limited time and resources. I can't, for the life of me, find where I previously read that daemons and agents weren't allowed to be shipped with a Mac App Store app, because of the Sandbox requirements. It was probably a reply by Eskimo somewhere in the forums. Does the same apply to Login Items? The bulk of the Login Item documentation is in the documentation archive, most of which was written before the existence of the app stores, so I couldn't find any answers there. I previously believed that an app destined for the Mac App Store could only include a single binary, that of the main app itself. Although I've seen the recent article on including a command line utility binary in the distribution too. Also, if my understanding of code signing is correct, apps distributed via an app store are signed by Apple, and thus can't communicate via XPC with a binary signed and distributed via a Developer ID. Or is there some workaround there that might get me closer to my goal?
Replies
5
Boosts
1
Views
1.5k
Activity
Apr ’24
Launching agent installed with SMAppService
I am attempting to install and utilize an agent using the new(ish) SMAppService API with an existing app. The agent appears to install (no error is returned), but when I try to start the agent from Terminal, I get the following in the launchd.log: 2024-04-22 09:57:27.469039 (gui/502/com.redacted.service.agent) : internal event: WILL_SPAWN, code = 0 2024-04-22 09:57:27.469080 (gui/502/com.redacted.service.agent) : service state: spawn scheduled 2024-04-22 09:57:27.469081 (gui/502/com.redacted.service.agent) : service state: spawning 2024-04-22 09:57:27.469100 (gui/502/com.redacted.service.agent) : launching: one-shot 2024-04-22 09:57:27.469105 (gui/502/com.redacted.service.agent) : Allowing non-reentrant proxy for resolving path 2024-04-22 09:57:27.469947 (gui/502/com.redacted.service.agent [71866]) : xpcproxy spawned with pid 71866 2024-04-22 09:57:27.469960 (gui/502/com.redacted.service.agent [71866]) : internal event: SPAWNED, code = 0 2024-04-22 09:57:27.469964 (gui/502/com.redacted.service.agent [71866]) : service state: xpcproxy 2024-04-22 09:57:27.469997 (gui/502/com.redacted.service.agent [71866]) : internal event: SOURCE_ATTACH, code = 0 2024-04-22 09:57:27.506283 (gui/502/com.redacted.service.agent [71866]) : Service could not initialize: posix_spawn(/Users/chrisf/Library/Developer/Xcode/DerivedData/Redacted-gttupgdyakodzddurpavhmscwabs/Build/Products/Debug/Redacted App.app/Contents/MacOS/Service Agent.app), error 0xd - Permission denied 2024-04-22 09:57:27.506306 (gui/502/com.redacted.service.agent [71866]) : initialization failure: 23E224: xpcproxy + 31420 [1098][A7EF179C-FBCC-349E-A7D2-09B2F1408413]: 0xd 2024-04-22 09:57:27.506309 (gui/502/com.redacted.service.agent [71866]) : internal event: INIT, code = 13 2024-04-22 09:57:27.506313 (gui/502/com.redacted.service.agent [71866]) : job state = spawn failed 2024-04-22 09:57:27.507148 (gui/502/com.redacted.service.agent [71866]) : xpcproxy exited due to exit(78) 2024-04-22 09:57:27.507153 (gui/502/com.redacted.service.agent [71866]) : exited due to exit(78) 2024-04-22 09:57:27.507162 (gui/502/com.redacted.service.agent [71866]) : already handled failed init, ignoring 2024-04-22 09:57:27.507170 (gui/502/com.redacted.service.agent [71866]) : service state: exited 2024-04-22 09:57:27.507186 (gui/502/com.redacted.service.agent [71866]) : internal event: EXITED, code = 0 (tldr: error 0xd - Permission denied) I'd also be curious how we are expected to launch agents once registered with SMAppService. Is it sufficient simply to make an XPC call to an exposed method? Thanks!
Replies
1
Boosts
0
Views
1.3k
Activity
Apr ’24
What is the file permission between the Root and Admin account
I'm a bit confuse on the file permission between root and admin account. I'm developing the background user agent process, and I created the agent plist file with the permission R&amp;W for my admin account. When I tried to load my agent process with launchd, it said the plist file permission is not right. Only after I change the plist file owner to root chown root my.plist, did everything work. From the above situation, it seems that the root user cannot access files that are only authorized to the admin user. Admin account also can't access files authorized only to root, unless you add sudo or enter the password when the request admin password box pops up. But by sudo or password, it just temporarily converts your account from admin to root account. So am I right in my speculation?
Replies
1
Boosts
0
Views
1.1k
Activity
Apr ’24
launchctl load and unload com.vivi.control.serviceAgent.plist get error 5: Input/output error
1、 my plist /Library/LaunchAgents/com.vivi.control.serviceAgent.plist like this: &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;com.vivi.control.serviceAgent&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt; &lt;string&gt;/Users/yuellppa/Downloads/vivo_test&lt;/string&gt; &lt;/array&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/plist&gt; when the label is other any name but not "com.vivi.control.serviceAgent", use launchctl load /Library/LaunchAgents/com.vivi.control.serviceAgent.plist and launchctl unload /Library/LaunchAgents/com.vivi.control.serviceAgent.plist is ok. when label is "com.vivi.control.serviceAgent", launchctl load or launchctl unload get error 5: Input/output error. use launchctl list | grep com.vivi.control.serviceAgent get nothing, so has no conflicting service。 Can anyone help me take a look?
Replies
2
Boosts
0
Views
1.8k
Activity
Apr ’24
Running .app bundled application in non GUI environment causing app to fail at runtime
I am having a bundled application(.app file) and I am wanting to run this application via ssh session which does not have GUI access. Launching this application in a desktop GUI session, runs the application perfectly. However, on running it on the same machine via ssh session produces an error. Note: My application does not bring up any GUI window(it' just produces some logs on the terminal), so running it in a non-GUI environment should have worked. I get the below error when trying to launch the unix exe in the .app bundle( ./Myapp.app/Contents/MacOS/Myapp ) on the terminal. I have observed that applicationDidFinishLaunching(_:) gets called and then the below error occurs. +[NSXPCSharedListener endpointForReply:withListenerName:replyErrorCode:]: an error occurred while attempting to obtain endpoint for listener 'ClientCallsAuxiliary': Connection interrupted I tried running other bundled applications via ssh, but all seems to produce the same error. Can someone confirm Is running bundled application in a non GUI session not allowed by Apple. If its allowed, how can I solve this? Even running the .app file using the open command fails to launch the application, although it produces a different error which is consistent across different applications.
Replies
1
Boosts
0
Views
922
Activity
Apr ’24
Launch Agent service not starting post login
We have a test scenario where we install our app package on a Mac setup using MDM (Jamf). Below are the test steps and observation: This installation is done on this Mac with no user logged in. Installation is completed successfully. Now when an user log in on this mac machine, the expectation is that the app bundle will be started by the launchd (RunAtLoad). But the app is not started. When I check console logs I could see few logs around the app but from those logs I couldn't figure out why the app didn't start. I rebooted my test machine but that also didnt start my app. My app is not listed in 'launchctl list' command. My App bundle contains container app and a packet tunnel extension. Below is how my plist file looks like in '/Library/LaunchAgents/com.****.***ui.plist': { KeepAlive = 1; Label = "com.*****.client.****ui"; LimitLoadToSessionType = ( Aqua ); ProgramArguments = ( "/Applications/*********.app/Contents/MacOS/****Module" ); RunAtLoad = 1; SuccessfulExit = 1; Version = "110.200.0.100"; } In Console below are the last set of log which I could find related to my app: support_log.txt In above logs below statement mentions the extn which is related to my app bundle: 2024-03-19 15:48:55.256020+0530 0x462 Default 0x0 206 0 symptomsd: (SymptomEvaluator) [com.apple.symptomsd:analytics] [Skipping first 85 of 95 entries] 2024-03-19 15:48:55.256051+0530 0x462 Default 0x0 206 0 symptomsd: (SymptomEvaluator) [com.apple.symptomsd:analytics] entry: Thu Feb 8 20:48:26 2024 NetworkExtension.com.*****.client.*****-Client.*****ui.*****pkttunnel.104.2.12.191.104.2.12 (bundle) 0 0 0 0 0 0 Can someone please help me in understanding what could be wrong here, why would 'RunAtLoad' key word wont work here to start my app on user login or reboot? Note: Everything work fine when my app is installed with an user logged in to the test machine. Also App starts successfully if I run command 'lauchctl bootstrap gui/ /Library/LaunchAgents/com.****.****ui.plist' in the above mentioned test scenario where app didnt auto start by launchd: 'RunAtLoad'.
Replies
8
Boosts
0
Views
1.6k
Activity
Mar ’24
MacOS detect multiple logged-in users
Hi we are developing a launchDeamon application and need to be notified when a new session is initiated or when a user connects to the Mac We looked into the Notifications in Cocoa and the Security framework and couldn't get a precise number is there any way to detect the ammount of users/sessions currently active?
Replies
2
Boosts
0
Views
746
Activity
Mar ’24
launchctl fails with "Bootstrap failed: 5: Input/output error", if the app is signed with sandbox
I am implementing parental control app via python 3.9 for macOS. Therefore I want to use launch agent to keep my application always alive (app reopened automatically after reboot pc and protected against to be closed via activity monitor.) I want to give keep alive enabling and disabling option to parents that they can deactivate or activate it in the app GUI. I achieved to keep alive my app standalone signed app without sandboxing(or via Terminal command) but if I sign it with sandbox then I get following error for "launchctl load" and "launchctl bootstrap" commands which are executed in the application "Load failed: 5: Input/output error" My steps without Sandbox which works fine: 1- Create a com.test_gui.macos.plist file under /Library/LaunchAgents with following content: `<?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>KeepAlive</key> <true/> <key>Label</key> <string>test_gui</string> <key>ProgramArguments</key> <array> <string>open</string> <string>-g</string> <string>-a</string> <string>/Applications/test_gui.app</string> </array> </dict> </plist>` 2- create a python file for launch agent activation (I know either launchctl load or bootstrap should be used but I used both of them to test both.): import subprocess cmd = "launchctl enable gui/501/test_gui" response = subprocess.call(cmd, shell=True) time.sleep(2) cmd = "launchctl load -w /Library/LaunchAgents/com.test_gui.macos.plist" response = subprocess.call(cmd, shell=True) time.sleep(2) cmd = "launchctl bootstrap system /Library/LaunchAgents/com.test_gui.macos.plist" response = subprocess.call(cmd, shell=True) time.sleep(50) 3- Create standalone app via nutika: python3.9 -m nuitka --run --standalone --macos-disable-console --macos-create-app-bundle \--macos-app-mode=ui-element --enable-plugin=pyside6 --macos-app-icon=/Users/emre/Documents/MrProtect/icons/app_icon.png \--include-data-dir=icons=icons test_gui.py 4-Create a .sh file to sign app without sandboxing: #!/bin/sh APP_PATH="/Users/emre/Documents/tests/Deployment/test_gui.app" SIGNING_IDENTITY_APP="Apple Development: Emre Guenay (xxx)" PASSWORD="xxx" codesign -s "$SIGNING_IDENTITY_APP" -f \ "$APP_PATH/Contents/MacOS/Python" codesign -s "$SIGNING_IDENTITY_APP" -f \ "$APP_PATH/Contents/MacOS/test_gui" exit 0 5-execute sh file and see following output: /Users/emre/Documents/MrProtect/tests/Deployment/test_gui.app/Contents/MacOS/Python: replacing existing signature /Users/emre/Documents/MrProtect/tests/Deployment/test_gui.app/Contents/MacOS/test_gui: replacing existing signature 6-copy paste signed standalone app(without sandbox) file under /Applications/ 7-execute app and try to close app via activity monitor and observe that the app is reopened automatically. so the launch agent works fine Failed Steps(Sign the same app with sandbox and observe that both launchctl load and bootstrap returns "Load failed: 5: Input/output error") 8- create an app.entitlements file with following content: \<?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\>com.apple.security.app-sandbox\</key\> \<true/\> \</dict\> \</plist\> 9-Create a .sh file to sign app with sandboxing: #!/bin/sh # APP_PATH="/Users/emre/Documents/tests/Deployment/test_gui.app" SIGNING_IDENTITY_APP="Apple Development: Emre Guenay (xxx)" PASSWORD="xxx" codesign -s "$SIGNING_IDENTITY_APP" -f \ \--entitlements app.entitlements \ "$APP_PATH/Contents/MacOS/Python" codesign -s "$SIGNING_IDENTITY_APP" -f \ \--entitlements app.entitlements \ "$APP_PATH/Contents/MacOS/test_gui" exit 0 10-execute sh file and see following output: /Users/emre/Documents/MrProtect/tests/Deployment/test_gui.app/Contents/MacOS/Python: replacing existing signature /Users/emre/Documents/MrProtect/tests/Deployment/test_gui.app/Contents/MacOS/test_gui: replacing existing signature 11-execute app and try to close app via activity monitor and observe that the app is closed although app started the launch agent. 12-you can re-execute app under /Applications/test_gui.app/Contents/MacOS folder with "./test_gui" or even with sudo "sudo ./test_gui" commands you would see following error message for both launchctl load and bootstrap returns: "Load failed: 5: Input/output error". So if you close the app, it will not be re-opened Moreover console tool launchd.log output shows also (1: Operation not permitted) error for launchctl load and bootstrap commands My questions: 1-Is there any other method different than launch agent for keep alive? I researched it in internet but I could not find any other method unfortunately. Moreover launch agent is not user friendly anyway, with the reason that sandboxed apps cannot copy paste any files under LaunchAgents folder automatically. I am planning to provide my plist file to users that they can copy paste the file themself into launch agent folder out of sandbox. 2-How can i get rid of "Load failed: 5: Input/output error", thereby I can proceed at least with lanuchctl? What I have tried additionally: 1-I have also tried to use these linux commands, before executing my sandboxed standalone app file: sudo -S chown 600 /Library/LaunchAgents/com.test_gui.macos.plist sudo -S chown root:wheel /Library/LaunchAgents/com.test_gui.macos.plist 2-I have already given security fulldisk access to my test_gui app, but it also did not work My Requirements: Nuitka: 1.9rc5 Commercial: None Python: 3.9.12 (v3.9.12:b28265d7e6, Mar 23 2022, 18:22:40) Flavor: CPython Official Executable: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 OS: Darwin Arch: x86_64 Version C compiler: /usr/bin/clang (clang). macOS Sonoma: 14.2.1
Replies
1
Boosts
0
Views
5k
Activity
Mar ’24
MacOS 14.4 ServiceManagement, cannot install sandboxed daemon from sandboxed main application anymore
I have made an app that requires a daemon to run. For this I use the ServiceManagement framework and the SMAppService.register to register the daemon. The macOS 14.4 update broke the installation process and the daemon cannot be installed anymore and instead returns an error when trying to install the helper. The installation works on MacOS 14.3.1 or lower. I have narrowed the error to the main app being sandboxed. Both the daemon and the main app are sandboxed (as MacOS 14.2 introduced the restriction that a sandboxed app can only run/install a sandboxed daemon, https://developer.apple.com/documentation/macos-release-notes/macos-14_2-release-notes#ServiceManagement). I have been able to confirm that removing the sandbox on the main application results in the register function working again on MacOS 14.4. However, the release notes of 14.4 do not mention anything regarding the ServiceManagement API or something related. So my question is, what has changed in MacOS 14.4 so that the register function for a daemon causes an error when the main app is sandboxed? And moreover, how can I prevent this error without removing the sandbox -- Information regarding the error: The .register function returns the following error: Error Domain=SMAppServiceErrorDomain Code=22 "Invalid argument" UserInfo={NSLocalizedFailureReason=Invalid argument I have also created a log file according to the procedure at the link below and attached it to this post: https://forums.developer.apple.com/forums/thread/707482#716553022 It appears from the log file and from observing the logs in the Console app, that the error "plist changed between client and smd" causes the issue but I don't understand what causes this error out2 2.log -- (I already use the com.apple.security.temporary-exception.sbpl entitlement in the daemon such that it can write to a specific file that the pmset command write to when invoked. This to indicate that I would prefer to keep the main app sandboxed as well. As I could also just remove the sandbox but I don't want to do that)
Replies
2
Boosts
0
Views
1.3k
Activity
Mar ’24
LaunchDaemons not launching my app, but LaunchAgents launch it instead
I am developing an app, in this case for macOS. My app has two parts: A GUI A Server From the GUI i can start and stop the serve. My problem is that i need the server starts when the mac boots. Using the LaunchAgents i got to launch it when the user logins on, but i need to initiate it before. I saw that i need to saving my .plis inside of /Library/LaunchDaemons. I did it but when i restart the computer the server didn t initiate. I checked that my service gave me the status 1 so, it didn t launch correctly. Maybe the failure is inside the plist... but i dont understand why it works in LaunchAgent and not inside LaunchDaemons My plist is: &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;com.turnoffpc.turnoffpcplist&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt; &lt;string&gt;/Applications/Turn Off PC.app/Contents/Resources/Turn Off PC/Server/dist/turn_off_pc_server.app/Contents/MacOS/turn_off_pc_server&lt;/string&gt; &lt;/array&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;/dict&gt; &lt;/plist&gt; For loading the service im using the following sh: #!/bin/bash # Copiar el archivo plist a /Library/LaunchDaemons/ sudo cp com.turnoffpc.turnoffpcplist.plist /Library/LaunchDaemons/ # Establecer los permisos adecuados sudo chown root:wheel /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist sudo chmod 644 /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist # Descargar y luego cargar el servicio utilizando launchctl sudo launchctl unload /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist sudo launchctl load /Library/LaunchDaemons/com.turnoffpc.turnoffpcplist.plist I checked that the service is in the correct location The path to my app is: inside /Applications Turn Off PC.app Resources Turn Off PC - Server - dist - turn_off_pc_server.app - Contents - MacOS - turn_off_pc_server Someone sees the error or the thing that i am doing wrong? Thanks in advance
Replies
2
Boosts
0
Views
1.8k
Activity
Mar ’24
Launchctl unable start service with error 0x1 - Operation not permitted after app signing updated
Hi, we are working on an application which will perform scheduled backup tasks in macOS 14. The app has been granted full disk permission. Recently we updated the code signing for the executable (/Applications/MyApp.app/Contents/MacOS/MyApp below) for passing the new notarization. After that, we found launchctl unable to load the plist for the schedule job &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;com.MyApp.scheduler&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt; &lt;string&gt;/Applications/MyApp.app/Contents/MacOS/MyApp&lt;/string&gt; &lt;string&gt;/Applications/MyApp.app&lt;/string&gt; &lt;/array&gt; &lt;key&gt;RunAtLoad&lt;/key&gt; &lt;true/&gt; &lt;key&gt;AbandonProcessGroup&lt;/key&gt; &lt;true/&gt; &lt;key&gt;WorkingDirectory&lt;/key&gt; &lt;string&gt;/Applications/MyApp.app/bin&lt;/string&gt; &lt;/dict&gt; &lt;/plist&gt; Related error message found in /var/log/com.apple.xpc.launchd/launchd.log* 2023-12-13 13:59:34.639672 (system/com.MyApp.scheduler [13434]) &lt;Notice&gt;: internal event: SOURCE_ATTACH, code = 0 2023-12-13 13:59:34.644530 (system/com.MyApp.scheduler [13434]) &lt;Error&gt;: Service could not initialize: posix_spawn(/Applications/MyApp.app/Contents/MacOS/MyApp), error 0x1 - Operation not permitted 2023-12-13 13:59:34.644545 (system/com.MyApp.scheduler [13434]) &lt;Error&gt;: initialization failure: 23C64: xpcproxy + 38300 [1097][925DE4E7-0589-3B33-BB64-7BC2F8629897]: 0x1 2023-12-13 13:59:34.644548 (system/com.MyApp.scheduler [13434]) &lt;Notice&gt;: internal event: INIT, code = 1 2023-12-13 13:59:34.644915 (system/com.MyApp.scheduler [13434]) &lt;Notice&gt;: xpcproxy exited due to exit(78) We have tried to update the entitlements for library and main executable files while still not success on make it works again. We have no idea what else could do for troubleshooting this. &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;com.apple.security.cs.allow-jit&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.cs.allow-unsigned-executable-memory&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.cs.disable-library-validation&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.cs.allow-dyld-environment-variables&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.security.cs.debugger&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.application-identifier&lt;/key&gt; &lt;string&gt;...&lt;/string&gt; &lt;key&gt;com.apple.developer.team-identifier&lt;/key&gt; &lt;string&gt;...&lt;/string&gt; &lt;/dict&gt; &lt;/plist&gt; Appreciate for any suggestions. Thank you.
Replies
2
Boosts
0
Views
1.4k
Activity
Mar ’24
SMAppService: registerAndReturnError fails with Codesigning failure loading plist code: -67054
When registering the LaunchDaemons of the application using SMAppService:registerAndReturnError, I am seeing the below error. The operation couldn’t be completed. Codesigning failure loading plist: <plist name> code: -67054 Above issue is seen only on Ventura 13.0.1 and Ventura 13.1 versions. It is working fine on Ventura 13.5, Ventura 13.6 and Sonoma 14.2 as well. When I checked the system logs using sudo log stream --debug --info --predicate "process in { '<my process>', 'smd', 'backgroundtaskmanagementd'} and sender in {'ServiceManagement', 'BackgroundTaskManagement', 'smd', 'backgroundtaskmanagementd'}" I see below error 2024-02-27 16:02:22.382487+0530 0x4c006 Error 0x0 321 0 smd: [com.apple.libxpc.SMAppServiceShared:all] Static code signature check failed: -67054 2024-02-27 16:02:22.382500+0530 0x4c006 Error 0x0 321 0 smd: [com.apple.libxpc.SMAppServiceShared:all] Unable to validate code signature on bundle for <private>. Code: -67054 2024-02-27 16:02:22.384288+0530 0x4c006 Error 0x0 321 0 smd: [com.apple.xpc.smd:SMAppServiceFactory] Unable to load plist: <private> subpath: <private> status: -67054 There is no difference in the code between. There is no modification to the application bundle after codesigning in both cases (working and not working). Can someone let me know why is there a difference in the behavior in the earlier Ventura versions? Any steps to debug and resolve this issue would be highly appreciated. Thanks
Replies
1
Boosts
0
Views
1.1k
Activity
Mar ’24
Setup LaunchAgent in Xcode
Hi there :) I try to put an Xcode project in place within a LaunchAgent. The ultimate goal is to have an "application" with two component: macOS application with just an basic UI all the logic happens in a LaunchAgent that runs on background and is launch at startup. The macOS app uses XPC to send messages to the agent that will run either the app is opened or not. I struggled at first having this error (for the agent): An XPC Service cannot be run directly. Then I found using MachServices key in the .plist of the agent fixes the issue, plus: let listener = NSXPCListener.init(machServiceName: "com.tonygo.NetworkMonitorAgent") Then I wonder: Do we have somewhere a documentation about how to setup a LaunchAgent in Xcode I create the plist of the agent on side and run it manually, I could do this in a more automatic way How could I package a macOS applciation that will contains the agent, install it and load the agent? Note: This is mainly for learning and understanding what we could do at each level (XPCService, LaunchAgents, LaunchDaemon, etc.).
Replies
23
Boosts
0
Views
4.3k
Activity
Feb ’24