CodeKit can be manipulated with AppleScript. To see available commands, launch the AppleScript Editor app, then choose File > Open Dictionary. In the list that pops up, select CodeKit.
The following snippets show how to use the AppleScript API. See the CodeKit Dictionary in AppleScript Editor for each method's return value and other detailed information.
Add a Project Or Framework
tell application "CodeKit" to add project at path "~/clients/someProjectFolder"
tell application "CodeKit" to add framework at path "~/someFrameworkFolder"
If the specified folder is already in CodeKit, these methods do nothing. Otherwise, the folder is added and becomes the active project. If the item at the specified path is not a folder, these methods abort and log an error message to Console.app. Unless an error occurs, the CodeKit window will not come to the front. Inspect the return value of each method to determine what happened.
Select a Project Or Framework
tell application "CodeKit" to select project containing path "~/clients/aProject/app.scss"
tell application "CodeKit" to select framework containing path "~/someFrameworkFolder"
The path can be the root project folder or any item that is a descendent thereof. The descendent item need not be in CodeKit or even exist on disk. This makes the API really flexible because you don't need to figure out the path to the project folder if you know a certain file is part of that project and you have that file's path handy.
Note: If you call this right after adding a new project or framework, you must wait for CodeKit to finish adding the new project. Otherwise, this method will tell you that no matching project was found.
tell application "CodeKit" to pause file watching
tell application "CodeKit" to unpause file watching
If file-watching is already paused when you call the 'pause' command, nothing happens. This is the same for the 'unpause' command.
tell application "CodeKit" to refresh browsers
The command above reloads the full page of every browser that's viewing CodeKit's preview URL. To reload only the stylesheets and inject changes, use this:
tell application "CodeKit" to refresh browsers by reloading just stylesheets
You can tell CodeKit to wait up to 10 seconds before dispatching the refresh. Here's an example using multi-line AppleScript syntax:
tell application "CodeKit" refresh browsers by reloading the whole page after delay 3 end tell
Preview In Browser
tell application "CodeKit" to preview in browser
The above command opens CodeKit's preview server in the system-default browser. You can also specify popular browsers by name (for the full list, see the dictionary for CodeKit in AppleScript Editor):
tell application "CodeKit" to preview in browser Firefox
If the browser you want is not in the named list, use its bundle identifier:
tell application "CodeKit" to preview in browser bundle named "com.apple.Safari"
Finally, you can tell CodeKit which preview address to open. There are three:
tell application "CodeKit" preview in browser Firefox using bonjour address end tell
The other two options are using LAN address and using local feedback address. For details, see Browser Refreshing.
Add An Entry To The Log
You can add a message to CodeKit's log very easily:
tell application "CodeKit" log message "Hello World!" with title "My Log Entry" end tell
The message string and title are required. By default, messages have a success type (a green dot in the log). You can optionally specify a warning (yellow dot) or problem type (red dot). You may also provide an optional Project Name associated with this message:
tell application "CodeKit" log message "Hi!" with title "My Entry" and type warning for project named "myProject" end tell
You can build a Project the same way you select one—by providing the path to the root project folder or to any item that is a descendant thereof. You do not need to know the Project's root folder; CodeKit will figure that out for you.
tell application "CodeKit" build project containing path "~/some/path/to/a/file.js" end tell