Objective c CGEventCreateKeyboardEvent和沙盒
我正在尝试使用这段代码在Mac OS X的沙盒应用程序中向finder发送击键:Objective c CGEventCreateKeyboardEvent和沙盒,objective-c,xcode,macos,cocoa,Objective C,Xcode,Macos,Cocoa,我正在尝试使用这段代码在Mac OS X的沙盒应用程序中向finder发送击键: CGEventRef a = CGEventCreateKeyboardEvent(NULL, keycode, true); CGEventSetFlags(a, kCGEventFlagMaskControl); CGEventPost(kCGHIDEventTap, a); CFRelease(a); 它在非sanboxed环境中工作,但在沙盒环境中不工作,如果我使用此权限:
CGEventRef a = CGEventCreateKeyboardEvent(NULL, keycode, true);
CGEventSetFlags(a, kCGEventFlagMaskControl);
CGEventPost(kCGHIDEventTap, a);
CFRelease(a);
它在非sanboxed环境中工作,但在沙盒环境中不工作,如果我使用此权限:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.apple.systemevents</string>
</array>
</dict>
</plist>
com.apple.security.app-sandbox
com.apple.security.temporary-exception.apple-events
com.apple.systemevents
我发现有人建议改用Apple脚本,它可以工作,但速度很慢,不适合我的需要
有机会吗