Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically shutdown, restart, sleep in a sandboxed cocoa application

I have a problem with the apple sandbox and the functionality of my app. The app should put my mac into sleep, or shutdown or restart it. I am using "com.apple.security.temporary-exception.apple-events" as the entitlement for sandbox with the value "com.apple.finder". I have imported ScriptingBridge and generated a Finder.h file which i have also included in my project like its proposed in https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/UsingScriptingBridge/UsingScriptingBridge.html#//apple_ref/doc/uid/TP40006104-CH4-SW12

Then i tried to use the provided methods from Finder.h like shutDown, restart or sleep but they just don't work.

FinderApplication *theFinder = [SBApplication applicationWithBundleIdentifier:@"com.apple.finder"];
[theFinder shutDown];

Can anyone tell me how i can implement these functionalities in a sandboxed app?

Many Thanks!

like image 847
user2212391 Avatar asked Dec 31 '25 06:12

user2212391


1 Answers

Checkout https://developer.apple.com/library/mac/qa/qa1134/_index.html

This guide provides the exact code you are looking for. I have tried this and it works perfectly.

like image 99
Mital Vora Avatar answered Jan 07 '26 19:01

Mital Vora



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!