Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Scheduling in a Sandboxed app?

Tags:

macos

cocoa

I need to add scheduling to my app. So that my app will launch automatically at a specified time and date. I have done it by referring Scheduling Timed Jobs. I have placed the plist file for scheduling in /Users/username/Library/LaunchAgents. It works well in the non-sandboxed app, but it is not working in a sandboxed app. I can't able to add the scheduling file to the path /Users/username/Library/LaunchAgents. It gives me the error

Error Domain=NSCocoaErrorDomain Code=513 "“com.sample.schedule.plist” couldn’t be copied because you don’t have permission to access “LaunchAgents”." UserInfo=0x100114f10 {NSSourceFilePathErrorKey=/Users/username/Library/Developer/Xcode/DerivedData/SchedulingInSandbox-cernhnigkuqhehbndryxlekpiiiu/Build/Products/Debug/SchedulingInSandbox.app/Contents/Resources/com.sample.schedule.plist, NSUserStringVariant=(
    Copy
), NSDestinationFilePath=/Users/username/Library/LaunchAgents/com.sample.schedule.plist, NSFilePath=/Users/username/Library/Developer/Xcode/DerivedData/SchedulingInSandbox-cernhnigkuqhehbndryxlekpiiiu/Build/Products/Debug/SchedulingInSandbox.app/Contents/Resources/com.sample.schedule.plist, NSUnderlyingError=0x1001132d0 "The operation couldn’t be completed. Operation not permitted"}

I have added the LaunchAgents Path in Entitlements too.

<key>com.apple.security.temporary-exception.files.home-relative-path.read-write</key>
<array>
    <string>/Library/LaunchAgents/</string>
</array>

But still I can't able to add the scheculing plist in LaunchAgents Directory. Whether I am doing correctly or there is another way for the doing the scheduling in sandboxed app.

EDIT 1:
If I manually create the folder in /Library/Containers/LaunchAgents and put the plist there I am getting this error:

Could not open job overrides database at: /private/var/db/launchd.db/com.apple.launchd.peruser.501/overrides.plist: 1: Operation not permitted
launch_msg(): Socket is not connected
like image 420
Aravindhan Avatar asked May 21 '13 09:05

Aravindhan


People also ask

What is app sandbox?

App Sandbox provides protection to system resources and user data by limiting your app's access to resources requested through entitlements. Important. To distribute a macOS app through the Mac App Store, you must enable the App Sandbox capability.

What is kernel sandbox?

Android uses the UID to set up a kernel-level Application Sandbox. The kernel enforces security between apps and the system at the process level through standard Linux facilities such as user and group IDs that are assigned to apps. By default, apps can't interact with each other and have limited access to the OS.


1 Answers

Try putting your job plist into

/Users/<username>/Library/Containers/<my app identifier>/Data/Library/LaunchAgents/<my app identifier>.<somename>.plist

This would be the data container for your sandboxed app.

Looking on my Mac I see that FaceTime has two scheduled job plists in there you can probably use as an example.

like image 82
macshome Avatar answered Nov 11 '22 12:11

macshome