I tried to use Application Scripting Bridge to send my Mac to sleep.
The code look like the following:
#import "Finder.h"
FinderApplication *Finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.finder"];
[Finder sleep];
But it doesn’t work. Any ideas why it doesn’t work? No compiling errors or warnings, but it doesn’t work…
As I posted in this answer, I’ve been using the following code for over 8 years without issues:
MDRestartShutdownLogout.h:
MDRestartShutdownLogout.m:
Note that the above code is based on the code from Technical Q&A QA1134, but mine is re-worked to use
AESendMessage()rather thanAESend().AESend()is inHIToolbox.framework, which is inCarbon.frameworkand is therefore unavailable to 64-bit apps. (AESendMessage()is part of theAE.frameworkinCoreServices).