Add scriptable property to Cocoa application derived from NSObject <NSApplicationDelegate>?

 ̄綄美尐妖づ 提交于 2019-12-13 07:36:47

问题


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>

the header file:

// 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 attempt to set property "myInt"

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

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...


回答1:


Your method statement has an error...

-(void)setMyInt:(NSInteger*)newVal

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.

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>

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

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


来源:https://stackoverflow.com/questions/10079263/add-scriptable-property-to-cocoa-application-derived-from-nsobject-nsapplicatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!