Macos 在AppleScriptObjC中防止睡眠

Macos 在AppleScriptObjC中防止睡眠,macos,cocoa,sleep,applescript-objc,Macos,Cocoa,Sleep,Applescript Objc,我想在AppleScriptObjC中防止睡眠。我发现这个问题: 我可以用Objective-C阻止睡眠,但用AppleScriptObjC不行。我该怎么做 格雷厄姆·米尔恩的例子: #import <IOKit/pwr_mgt/IOPMLib.h> // kIOPMAssertionTypeNoDisplaySleep prevents display sleep, // kIOPMAssertionTypeNoIdleSleep prevents idle sleep //r

我想在AppleScriptObjC中防止睡眠。我发现这个问题:

我可以用Objective-C阻止睡眠,但用AppleScriptObjC不行。我该怎么做

格雷厄姆·米尔恩的例子:

#import <IOKit/pwr_mgt/IOPMLib.h>

// kIOPMAssertionTypeNoDisplaySleep prevents display sleep,
// kIOPMAssertionTypeNoIdleSleep prevents idle sleep

//reasonForActivity is a descriptive string used by the system whenever it needs 
//  to tell the user why the system is not sleeping. For example, 
//  "Mail Compacting Mailboxes" would be a useful string.

//  NOTE: IOPMAssertionCreateWithName limits the string to 128 characters. 
CFStringRef* reasonForActivity= CFSTR("Describe Activity Type");

IOPMAssertionID assertionID;
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, 
                                kIOPMAssertionLevelOn, reasonForActivity, &assertionID); 
if (success == kIOReturnSuccess)
{

    //Add the work you need to do without 
    //  the system sleeping here.

    success = IOPMAssertionRelease(assertionID);
    //The system will be able to sleep again. 
}

Xcode在下面的代码行中给了我一个警告,说指针类型不兼容。CFStringRef*reasonForActivity=cfStrDescripte活动类型;我通过将代码行更改为以下内容修复了警告:CFStringRef reasonForActivity=cfStrDescripte活动类型;请记住,在CFStringRef中,Ref表示它已声明为指针。请发布不起作用的AppleScript ObjectiveC代码好吗?抱歉,我无法将Objective-C转换为AppleScriptObjC,尽管我总是可以,因为我不知道如何在ASOC中编写cfStrDescripte活动类型。IOPMAssertionID断言ID alsoI将在编辑部分发布错误的ASOC代码。我在编辑部分发布了它。
tell class "CFStringRef" of current application
    set reasonForActivity to CFSTR("Describe Activity Type")
end tell
tell class "IOPMAssertionID" of current application
    set assertionID
end tell
tell class "IOReturn" of current application
    set success to IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, 
                                kIOPMAssertionLevelOn, reasonForActivity, assertionID)
end tell
if success = kIOReturnSuccess then
    -- Add the work you need to do without the system sleeping here.
    set success to IOPMAssertionRelease(assertionID)
    -- The system will be able to sleep again.
end if