向从 NSObject <NSApplicationDelegate> 派生的 Cocoa 应用程序添加可编写脚本的属性? [英] Add scriptable property to Cocoa application derived from NSObject <NSApplicationDelegate>?

查看:20
本文介绍了向从 NSObject <NSApplicationDelegate> 派生的 Cocoa 应用程序添加可编写脚本的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我指出这个工作的例子吗?我只想通过 AppleScript 设置一个属性值.我已经浏览了所有可编写脚本的示例,它们的设置不同.

Can someone point me to an example of this working. I just want to set a property value via AppleScript. I have gone through all of the scriptable examples, which are setup differently.

<?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"

// Applescript attempt to set property "myInt"

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

最终,delegateHandlesKey 方法被调用,我能够为该属性返回一个值,但从未调用 setter.提前致谢...

Ultimately, the delegateHandlesKey method is called, I am able to return a value for the property, but the setter is never called. Thanks in advance...

推荐答案

你的方法语句有错误...

Your method statement has an error...

-(void)setMyInt:(NSInteger*)newVal

不应该有*",因为 NSInteger 不是指针"变量.我在您问题的评论中看到 Ken Thomases 已经告诉过您这一点,因此请务必修复它.

There should not be a "*" as NSInteger is not a "pointer" variable. I see in the comments of your question that Ken Thomases has already told you this so make sure to fix it.

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

So if this is not your problem then look at your sdef file. I can see you did not close the dictionary tag. You need this as the last line of that file.

</dictionary>

我也有这个作为我的 sdef 文件中的第二行...

I also have this as the second line in my sdef files...

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

这篇关于向从 NSObject &lt;NSApplicationDelegate&gt; 派生的 Cocoa 应用程序添加可编写脚本的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆