More on CocoaScript
From CocoaScript’s README:
You can use two different styles when writing your scripts: dot notation and bracket notation.
var l = a.length()
Here, a dot is used to say: “Call the ‘length’ method on the ‘a’ object”.
However, if you come from a Cocoa background, you may be happy to learn that you can also use a bracket notation, very similar to that in Objective-C:
var l = [a length]
You can even mix and match dot and bracket notation:
var l = [a length].toString()
However, it’s probably a good idea to stick with just one style.
You can access all Cocoa APIs from CocoaScript. For example, if you want to open a File Picker panel, you can use the NSOpenPanel class:
var openPanel = [NSOpenPanel openPanel] [openPanel setCanChooseDirectories:false] [openPanel setCanChooseFiles:true] [openPanel setCanCreateDirectories:false] [openPanel setDirectoryURL:[NSURL fileURLWithPath:"~/Documents/"]] [openPanel setTitle:"Choose a file"] [openPanel setPrompt:"Choose"] [openPanel runModal]
If you need more information about Cocoa, check the Resources section.
Other CocoaScript Syntax Notes
- Semicolons are optional in CocoaScript.
- You can evaluate nullness by using