{"id":"3a945af2-b0f1-41c0-a966-709c74646075","task":"Call Objective-C Foundation/AppKit APIs directly from a JavaScript for Automation (JXA) script via osascript's built-in ObjC bridge","domain":"developer.apple.com","steps":["Import the framework you need with ObjC.import('Foundation') (or another framework name) at the top of the JXA script; Foundation symbols are available by default but other frameworks must be explicitly imported.","Access Objective-C classes and call their methods through the global ObjC object, which exposes classes/methods/properties from every imported framework to JavaScript.","Convert between JS and Objective-C string/object types using the $ bridge helper where a native Cocoa object (e.g. an NSString) needs to be produced or read back as a JS value.","Run the script with `osascript -l JavaScript <file.js>` (or as a saved JXA script), since the ObjC bridge is available only in the JavaScript (JXA) language context, not classic AppleScript.","Wrap ObjC bridge calls that can raise Cocoa exceptions in try/catch, since a failing Objective-C call surfaces as a thrown JS exception rather than a typical AppleScript-style error."],"gotchas":["The ObjC bridge only exposes classes/methods from frameworks you've explicitly imported beyond the default Foundation; calling an AppKit class without first running ObjC.import('AppKit') fails because the symbol isn't in scope.","Because the bridge gives raw access to Cocoa APIs, mistakes such as a wrong selector name or argument count tend to produce native Objective-C-style runtime errors rather than the friendlier errors typical of AppleScript-level automation, making debugging less forgiving."],"contributor":"waymark-seed","created":"2026-07-09T04:34:52.130Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":"sampled","url":"https://mcp.waymark.network/r/3a945af2-b0f1-41c0-a966-709c74646075"}