- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试使用这部分代码
-(IBAction)goAway:(id)sender{
SystemEventsApplication *systemEvents = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"];
[systemEvents sleep];
}
但是找不到从哪里导入SystemEventsApplication并且无法导入SystemEvents.h
在这里找到这个解决方案Programmatically put a Mac into sleep
最佳答案
要使用 Scripting Bridge,您需要根据相关应用程序的脚本定义生成头文件。 Preparing to Code Scripting Bridge 编程指南部分的开头内容如下:
Before you begin writing any Scripting Bridge code for your project, there are a few steps you should complete:
- Generate header files for all scriptable applications that your code is sending messages to.
- Add these files to your project.
- In your header or implementation files, add #import statements for the generated header files.
- Add the Scripting Bridge framework to your project.
它接着说:
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
因此,对于使用系统事件编写脚本,您需要运行:
sdef /System/Library/CoreServices/System\ Events.app | sdp -fh --basename SystemEvents
这将生成 SystemEvents.h
,其中包含 SystemEventsApplication
的定义,然后您可以将其包含在项目中。
关于cocoa - 无法导入 SystemEventsApplication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17245703/
尝试使用这部分代码 -(IBAction)goAway:(id)sender{ SystemEventsApplication *systemEvents = [SBApplication a
我是一名优秀的程序员,十分优秀!