Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with making Cocoa app AppleScript-scriptable
    primarykey
    data
    text
    <p>I want to make my app scriptable and am running into a few issues I hope some of you may help me with since my experience with making apps scriptable is not great.</p> <p>The app is <em>not</em> document-based and has a several global named objects of the same class that I want to be accessed from AppleScript. For example, say that I want to have a several catalogues, each named, say "animals", "plants", "cars". I have managed to add several properties to the application class (in AppleScript), each representing one of the catalogues:</p> <pre><code>&lt;class name="application" description="My application." code="capp" inherits="application"&gt; &lt;cocoa class="NSApplication"/&gt; &lt;property name="animals catalogue" code="acat" description="…" type="catalogue" access="r"&gt; &lt;cocoa key="animalsCatalogue"/&gt; &lt;/property&gt; &lt;property name="cars catalogue" code="ccat" description="…" type="catalogue" access="r"&gt; &lt;cocoa key="carsCatalogue"/&gt; &lt;/property&gt; &lt;property name="plants catalogue" code="pcat" description="…" type="catalogue" access="r"&gt; &lt;cocoa key="plantsCatalogue"/&gt; &lt;/property&gt; &lt;/class&gt; </code></pre> <p>I am able to <strong>successfully</strong> fetch any of those variables, e.g.</p> <pre><code>tell application "MyApp" set c to get animals catalogue end tell </code></pre> <p>gets me really the catalogue variable (<code>«class ����» "Animals" of application "MyApp"</code>).</p> <p>Unfortunately, where it gets tricky is when it comes to getting a property from the catalogue - for example 'empty'. Here is the catalogue definition:</p> <pre><code>&lt;class name="catalogue" code="ctlg" description="..."&gt; &lt;cocoa class="XYCatalogue"/&gt; &lt;property name="empty" code="empt" description="Is the catalogue empty?" type="boolean" access="r"&gt; &lt;cocoa key="isEmpty"/&gt; &lt;/property&gt; &lt;/class&gt; </code></pre> <p>The issue here is that when running this AppleScript:</p> <pre><code>tell application "MyApp" set c to get animals catalogue get empty of c end tell </code></pre> <p>results in an error: <code>MyApp got an error: Can’t make «class ����» "Animals" into type specifier.</code></p> <p>Implementation-wise, I have the NSApplication subclassed (and yes, I have specified the main class in Info.plist), which implements several methods, returning those particular catalogues. The <code>XYCatalogue</code> class implements the <code>-objectSpecifier</code> method this way:</p> <pre><code>return [[[NSNameSpecifier alloc] initWithContainerClassDescription: [NSScriptClassDescription classDescriptionForClass:[NSApp class]] containerSpecifier:nil key:@"allCatalogues" name:[self name]] autorelease]; </code></pre> <p>The NSApplication subclass implements a <code>-allCatalogues</code> method that returns all the catalogues. I have tried even using the <code>NSUniqueIDSpecifier</code> and the <code>NSPropertySpecifier</code>, all in vain. And yes, the NSApplication subclass does implement both <code>-valueWithName:inPropertyWithKey:</code> and <code>-valueInAllCataloguesWithName:</code> methods and neither is invoked (have breakpoints in both of them).</p> <p>I have sincerely read Apple's guide several times, however, still can't figure out where is the issue and I'm hanging on this for a few days now. I would be most thankful for any nudge in the right direction. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload