0

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

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
  • At a guess, KVC may be introspecting your `-setMyInt:` method, seeing that it takes an `NSInteger*` parameter and failing because that's not something it can coerce an `NSNumber*` into. So, it may be falling back to direct instance variable access. Your method should just take an NSInteger, not a pointer to one. You might also consider routinely overriding `+accessInstanceVariablesDirectly` to return `NO` in your classes to rule out this sort of thing. – Ken Thomases Apr 09 '12 at 22:53
  • Thanks Ken. It may have been an issue as well, but doesn't turn out to fix my problem. The getter is called but not the setter. Back to the drawing board... – Brad Bittiker Apr 09 '12 at 23:43
  • If you've changed your code, you should probably edit your question to reflect that. Is the ivar being set without the setter being called? Also, I will point out that your getter isn't actually getting the value of the ivar. It's just returning a local which happens to be the constant 42. – Ken Thomases Apr 09 '12 at 23:48
  • Try setMyInt_(7) or set self()'s myInt to 7 and see if that helps. At least within an applescript app, you have to call an overriden setter one of those 2 ways – rdelmar Apr 10 '12 at 00:40

1 Answers1

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">
regulus6633
  • 18,848
  • 5
  • 41
  • 49