Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 查找器脚本桥关闭_Objective C_Cocoa_Macos_Scripting Bridge - Fatal编程技术网

Objective c 查找器脚本桥关闭

Objective c 查找器脚本桥关闭,objective-c,cocoa,macos,scripting-bridge,Objective C,Cocoa,Macos,Scripting Bridge,我尝试使用应用程序脚本桥将我的Mac送至睡眠状态。 代码如下所示: #import "Finder.h" FinderApplication *Finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.finder"]; [Finder sleep]; 但它不起作用。你知道为什么它不起作用吗?没有编译错误或警告,但它不起作用…如果脚本桥不足以执行非特定于应用程序的操作,例如关闭Mac,那么您就可以转

我尝试使用应用程序脚本桥将我的Mac送至睡眠状态。 代码如下所示:

#import "Finder.h"
 FinderApplication *Finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.finder"];
        [Finder sleep];

但它不起作用。你知道为什么它不起作用吗?没有编译错误或警告,但它不起作用…

如果脚本桥不足以执行非特定于应用程序的操作,例如关闭Mac,那么您就可以转移到Applescript(扩展为脚本桥)无法直接访问的其他框架。要关闭Mac,请参阅核心服务:

正如我在中发布的,我已经使用以下代码超过8年,没有出现任何问题:

MDRestartShutdownLogout.h:

#import <CoreServices/CoreServices.h>
/*
    *    kAERestart        will cause system to restart
    *    kAEShutDown       will cause system to shutdown
    *    kAEReallyLogout   will cause system to logout
    *    kAESleep          will cause system to sleep
 */
extern OSStatus MDSendAppleEventToSystemProcess(AEEventID eventToSend);

请注意,上面的代码基于中的代码,但我的代码被重新处理为使用
AESendMessage()
而不是
AESend()
AESend()
位于
HIToolbox.framework
中,它位于
Carbon.framework
中,因此64位应用程序无法使用。(
AESendMessage()
CoreServices
aes.framework
的一部分)。

太好了。发现苹果的页面也有,但看到它使用了碳……它在10.13上不起作用。你有什么建议吗?我得到以下错误:AppleEvents:received mach msg不是getMemoryReference中预期的复杂类型。
#import "MDRestartShutdownLogout.h"

OSStatus MDSendAppleEventToSystemProcess(AEEventID eventToSendID) {
    AEAddressDesc targetDesc;
    static const ProcessSerialNumber kPSNOfSystemProcess = {0, kSystemProcess };
    AppleEvent eventReply = {typeNull, NULL};
    AppleEvent eventToSend = {typeNull, NULL};

    OSStatus status = AECreateDesc(typeProcessSerialNumber,
         &kPSNOfSystemProcess, sizeof(kPSNOfSystemProcess), &targetDesc);

    if (status != noErr) return status;

    status = AECreateAppleEvent(kCoreEventClass, eventToSendID,
          &targetDesc, kAutoGenerateReturnID, kAnyTransactionID, &eventToSend);

    AEDisposeDesc(&targetDesc);

    if (status != noErr) return status;

    status = AESendMessage(&eventToSend, &eventReply,
                          kAENormalPriority, kAEDefaultTimeout);

    AEDisposeDesc(&eventToSend);
    if (status != noErr) return status;
    AEDisposeDesc(&eventReply);
    return status;
}