Questions tagged [cocoa-scripting]

Cocoa Scripting is a framework for OS X for making applications scriptable

Use this tag for questions related to making an OS X application scriptable, i.e. when you write your code in Objective-C or in Swift.

Do not use it for questions related to writing code in AppleScript or JavaScript (JXA) - for those, use the applescript or the cocoascript tag.

26 questions
6
votes
4 answers

How to pass an arbitrary AppleScript Record to Cocoa in a scriptable app?

I have a Cocoa application with an AppleScript dictionary described in a .sdef XML file. All of the AppleScript classes, commands, etc. defined in the sdef are working property. Except for my "submit form" command. The "submit form" command is my…
Todd Ditchendorf
  • 11,217
  • 14
  • 69
  • 123
4
votes
1 answer

Cocoa Scripting: Accept and return NSData

In order to support binary data exchange in my scriptable Mac app, I like to make it possible to receive and deliver data as NSData, using the AS-ObjC bridge, if that's possible. For instance, I like to make this code possible in AppleScript: use…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
4
votes
1 answer

Simple Tutorial to Create a Scriptable Cocoa Application (Scripting Bridge)

Can anyone point me to a really simple hello world type of application that introduces ScriptingBridge? Something that takes you step by step to creating a 1 class - 1 method project that can be instantiated from ruby/python/applescript, etc. I'm…
Dave Rapin
  • 1,471
  • 14
  • 18
4
votes
1 answer

Returning a record-type to applescript (from objective-C)

I am trying to return a record to applescript. The current solution is to return an NSDictionary and define the a record-type (Lyx return value) in the sdef file, but this does not work - should I construct a specific AppleScript object? Here is the…
3
votes
2 answers

Cocoa Scripting: Returning "null" vs. "missing value"

It appears that AppleScript knows the special value null. How do I return such a value from my Cocoa Scripting based app for a scriptable property? If I return nil (NULL) or NSNull for a scriptable property getter from my Cocoa Scripting-based app,…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
3
votes
2 answers

Unable to unwrap NSAppleEventDescriptor in SWIFT

I'm having an Applescript which gives me a result. But I am unable to unwarp the value to String so i can use it. var set: String = "set windowTile to \"\"\n" var tell: String = "tell application \"System Events\"\n" var setFrontApp: String = "set…
2
votes
2 answers

How to get a checkbox input in a Sketch plugin with Cocoascript?

I have a Sketch plugin that generates three different files based on the user's selection within an artboard. I want to allow the user to select which of the three files they actually want to have generated via checkboxes (instead of always…
Phil Sinatra
  • 419
  • 3
  • 11
2
votes
2 answers

Cocoa Scripting: Integrating the Text Suite

I am attempting to use the Text Suite in my scriptable Mac app. The little documentation I found in the Cocoa Scripting Guide suggests to use NSTextStorage. But it does not explain how the rest needs to be set up, both in the Sdef and on the coding…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
2
votes
3 answers

Cocoa Scripting: Deletion of elements in a loop getting out of sync

While adding scriptability to my Mac program, I am struggling with the common programming problem of deleting items from an indexed array where the item indexes shift due to removal of items. Let's say my app maintains a data store in which objects…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
2
votes
0 answers

Returning a NSUniqueIDSpecifier in -objectSpecifier with key Key does not result in valueInWithUniqueID: getting evaluated

The reference documentation for the class NSUniqueIdentifier claims that unique ID specifiers are evaluated in the following scheme: If the container implements a method whose selector matches the relevant valueInWithUniqueID: pattern…
mz2
  • 4,672
  • 1
  • 27
  • 47
2
votes
1 answer

Issues with making Cocoa app AppleScript-scriptable

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. The app is not document-based and has a several global named objects of the same…
Charlie Monroe
  • 1,210
  • 9
  • 24
1
vote
2 answers

Sketch Plugin - NSFileManager contentsOfDirectoryAtPath - not a function

I'm trying to make a plugin for Sketch that allows me to automate the production of multilingual assets. Right now, I select a list of languages files that kick off the process. I use NSOpen Panel to select these. For each language file, it makes a…
Ratedg
  • 11
  • 3
1
vote
2 answers

Cocoa Scripting: Returning the cloned objects from a "duplicate" command

The AppleScript duplicate command is supposed to return the copied objects. And while apps using the original AE-based functions seem to do that, apps based on the Cocoa Scripting framework seem to never return anything but missing value. It appears…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
1
vote
1 answer

Cocoa Scripting: Return a floating point (double) value for "any" type

When specifying the any type for a command result in the Sdef, it seems that one cannot simply return the NS types such as NSNumber. Instead, one needs to return an NSAppleEventDescriptor. However, NSAppleEventDescriptor is rather limited in the…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
1
vote
1 answer

AppleScript: Using "whose" with record values does not work

In my scriptable app, one of the properties is of a named record type, and that record type has been declared in the sdef as well (named "custom record"). I can get the record like this: get owner of anElement --> {pool:"test", position:2} I…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
1
2