问题描述
有人可以告诉我这个工作的例子。我只想通过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
$ b b
不应该有一个*,因为NSInteger不是一个指针变量。我在看你的问题的评论,肯汤姆斯已经告诉你这样一定要修复它。
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派生的Cocoa应用程序< NSApplicationDelegate> ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!