I am trying to write a trivial Objective-C application: I just want an app that will display a word in the status bar and allow the word to be updated via AppleScript. To be honest, I know little about AppleScript and nothing about Objective-C. But, it can't be that hard because it only took me 2 hours to get a menubar app that has menu items and responds to core AppleScript commands like "quit", so I'm 95% of the way there. Unfortunately, I spent the next 6 hours try to find some way of giving this application a simple property I can get and set through AppleScript.
Here is my .h code:
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
IBOutlet NSMenu *statusMenu;
NSStatusItem *statusItem;
}
@property (assign) IBOutlet NSWindow *window;
- (NSString*) foobaz;
@end
The foobaz
method is the one that I was using to try to make a readable property (*window
is part of the boilerplate I was given by XCode and not relevant to the issue at hand). Here is my .sdef file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include
href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef"
xpointer="xpointer(/dictionary/suite)"/>
<suite name="StatusMenuApp suite" code="smas"
description="StatusMenuApp specific classes.">
<class name="application" code="smaa" inhereits="application"
description="Application object.">
<cocoa class="AppDelegate"/>
<property name="foobaz" code="smas" type="text" access="r"/>
</class>
</suite>
</dictionary>
So I've got it set up just like the SimpleScripting example from Apple here: https://developer.apple.com/library/mac/#samplecode/SimpleScripting/Introduction/Intro.html
However, I've tried running this in the script editor:
tell application "StautsMenuApp"
properties
end tell
And I just get a list of the core properties, with no mention of foobaz
whatsoever, unlike Apple's example, in which the custom property appears alongside the core properties when I run it.
I feel like I've tried a hundred variations on this and read a hundred examples but can't get anything to work. Any help is appreciated.
The only thing I see offhand is a problem in your sdef. The code for this line needs to be "capp". That's standard and this will be the same in any sdef file. It is defined by Apple so you need that.
After you do that, you would access that method like this...