Question

I will begin by saying that I'm a complete newbie as far as AppleScript goes. So here you are...

This is what I've done so far :

  • Studied the apple reference for SimpleScripting
  • Implemented an IDENTICAL .sdef file
  • Set a new property myname
  • Set principal class (in info.plist) to ppApplication (my main class inheriting from NSApplication)
  • Set up the accessor to the myname property

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="MyApplication Suite" code="PpRm" description="MyApplication Suite">
        <class name="application" code="capp" description="MyApplication&apos;s top-level scripting object." inherits="application">
            <cocoa class="ppApplication"/>
            <property name="myname" code="PEnm" description="The name of the application" type="text" access="r">
                <cocoa key="myname"/>
            </property>
        </class>
    </suite>
</dictionary>

My ppApplication class :

#import <Foundation/Foundation.h>

#import "ppCore.h"

@interface ppApplication : NSApplication {
    ppCore* core;
}

@property (assign) ppCore* core;

@property (readonly) NSString* myname;

@end

#import "ppApplication.h"

@implementation ppApplication

@synthesize core;

- (void)awakeFromNib
{
    [self setCore:[[ppCore alloc] init]];
}

/*******************************************************
 *
 * APPLESCRIPT SUPPORT
 *
 *******************************************************/

- (NSString*)myname
{
    return @"DONE";
}

@end

Now, here's the issue :

When I'm trying to run the following script (in AppleScript Editor)

tell application "myApplication"
     myname
end tell

I'm getting a the variable myname is not defined error.

However :

If I go back to Xcode, Build Settings and change the Product Name to - let's say - myApplicationX and recompile, then the above code (changing it to tell application "myApplicationX") DOES WORK.

So, what am I doing wrong? Is it possible that the AppleScript Editor doesn't "talk" to my active compilation of the application, but to a previous one? How could I deal with this WITHOUT changing my Product Name?

Was it helpful?

Solution

There was NO issue with the above code.

Simply restarting AppleScript Editor (after making any serious changes to the application) does the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top