将脚本属性添加到从NSObject派生的Cocoa应用程序<nsapplicationdelegate>?</nsapplicationdelegate>

时间:2012-04-09 20:17:54

标签: objective-c cocoa applescript cocoa-scripting

有人能指出我这个工作的一个例子。我只想通过AppleScript设置属性值。我已经浏览了所有可编写脚本的示例,这些示例的设置方式不同。

<?xml version="1.0" encoding="UTF-8"?>
<dictionary title="">
<suite name="Circle View Scripting" code="bccS" description="Commands and classes for     Circle View Scripting">
    <class name="application" code="capp" description="" >
        <cocoa class="NSApplication"/>

        <property name="circletext" code="crtx" type="text" description="The text that gets spun into a circle">
            <cocoa key="circleText"/>
        </property>
        <property name="myint" code="crmy" type="integer" description="The text that gets spun into a circle">
            <cocoa key="myInt"/>
        </property>
    </class>
</suite>

头文件:

// header 
@interface MyDelegate : NSObject <NSApplicationDelegate> 
{
    WebScriptObject *scriptObject;
    WebView *webView;
    NSWindow *window;
    NSInteger myInt; 
}

// implementation
- (BOOL)application:(NSApplication*)sender delegateHandlesKey:(NSString*)key 
{ 
    return key isEqualToString:@"myInt"] || [key isEqualToString:@"circleText"];;
}

-(NSInteger)myInt
{
    NSInteger myInteger = 42;
    return myInteger;
}

-(void)setMyInt:(NSInteger*)newVal
{
    // do nothing right now
    NSLog(@"SETTER  CALLED");
}

// Applescript尝试设置属性“myInt”

tell application "BrowserConfigClient"  
set myint to 7
properties
end tell

最终,调用delegateHandlesKey方法,我能够返回属性的值,但永远不会调用setter。提前谢谢......

1 个答案:

答案 0 :(得分:1)

您的方法声明有错误...

-(void)setMyInt:(NSInteger*)newVal

不应该有“*”,因为NSInteger不是“指针”变量。我在你的问题的评论中看到Ken Thomases已经告诉过你,所以一定要解决它。

因此,如果这不是您的问题,那么请查看您的sdef文件。我可以看到你没有关闭字典标签。你需要这个作为该文件的最后一行。

</dictionary>

我也将此作为我的sdef文件中的第二行......

<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
相关问题