1

Try use this part part code

-(IBAction)goAway:(id)sender{
    SystemEventsApplication *systemEvents = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"];
    [systemEvents sleep];
}

But couldn't find from where import SystemEventsApplication and couldn't import SystemEvents.h

Find this solution here Programmatically put a Mac into sleep

Community
  • 1
  • 1
shami13
  • 57
  • 6

1 Answers1

2

To use Scripting Bridge you need to generate header files from the scripting definitions of the application in question. The Preparing to Code section of the Scripting Bridge Programming Guide leads with the following:

Before you begin writing any Scripting Bridge code for your project, there are a few steps you should complete:

  1. Generate header files for all scriptable applications that your code is sending messages to.
  2. Add these files to your project.
  3. In your header or implementation files, add #import statements for the generated header files.
  4. Add the Scripting Bridge framework to your project.

It goes on to say:

To create a header file, you need to run two command-line tools—sdef and sdp—together, with the output from one piped to the other. This is the recommended syntax:

sdef /path/to/application.app | sdp -fh --basename applicationName

So, for scripting using System Events you'd run:

sdef /System/Library/CoreServices/System\ Events.app | sdp -fh --basename SystemEvents

This would generate SystemEvents.h, containing a definition for SystemEventsApplication, which you can then include in your project.

bdash
  • 18,110
  • 1
  • 59
  • 91