💾 Archived View for gem.sdf.org › s.kaplan › cheatsheets › programming-languages › applescriptobjc.m… captured on 2023-09-28 at 16:23:02.

View Raw

More Information

-=-=-=-=-=-=-

## 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

- [AppleScriptObjC Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCScriptingGuide/Introduction/Introduction.html)
- [AppleScriptObjC Language Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCScriptingGuide/ScriptingOverview/ScriptingOverview.html)
- [AppleScriptObjC Release Notes](https://developer.apple.com/library/archive/releasenotes/InterapplicationCommunication/RN-AppleScriptObjC/index.html)
- [Objective-C Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html)