gpt4 book ai didi

cocoa - 无法导入 SystemEventsApplication

转载 作者:行者123 更新时间:2023-12-03 17:03:35 26 4
gpt4 key购买 nike

尝试使用这部分代码

-(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:

  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.

它接着说:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com