AI Generated Cheatsheets

AppleScriptObjC Cheatsheet: Objective-C Interoperability

Overview

AppleScriptObjC is a powerful framework that allows developers to write AppleScript code using Objective-C syntax. One of the key benefits of AppleScriptObjC is its ability to easily interoperate with Objective-C code. This cheatsheet focuses on the Objective-C interoperability features of AppleScriptObjC.

Declaring Variables

Declaring Objective-C Variables

set myArray to current application's NSMutableArray's arrayWithObjects:"Hello", "World"

Calling Objective-C Methods

Calling Objective-C Methods on Objects

set myArray to current application's NSMutableArray's arrayWithObjects:"Hello", "World"
set objectCount to myArray's count()

Calling Objective-C Class Methods

set myArray to current application's NSMutableArray's arrayWithObjects:"Hello", "World"
set newArray to current application's NSMutableArray's arrayWithArray:myArray

Working with Objective-C Objects

Creating Objective-C Objects

set myArray to current application's NSMutableArray's alloc()
set myArray to myArray's initWithCapacity:10

Releasing Objective-C Objects

set myArray to current application's NSMutableArray's arrayWithObjects:"Hello", "World"
set myArray to missing value

Working with Objective-C Properties

Getting Objective-C Property Values

set myWindow to current application's NSApplication's sharedApplication()'s mainWindow()
set windowTitle to myWindow's title()

Setting Objective-C Property Values

set myWindow to current application's NSApplication's sharedApplication()'s mainWindow()
myWindow's setTitle:"My Window Title"

Working with Objective-C Constants

Getting Objective-C Constants

set myConstant to current application's NSApplication's NSAppKitVersionNumber

Resources