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.
Get Preview Server Status
tell application "CodeKit" to get preview server status
This command returns '1' if the Preview Server is running normally, '0' if it's not running, '2' or '3' if the Server is starting up or updating, and '-1' if an error occurs.
Get Preview Server Address
tell application "CodeKit" to get preview server url
This command returns the current address of the Preview Server as a string. You can add "using" and one of "bonjour address", "LAN address", or "local feedback address" to get the type of address you want. If you omit that optional parameter, you'll get whichever address you've picked as the default in CodeKit. Returns an empty string if an error occurs or the Preview Server isn't running.
Add An Entry To The Log
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
Process A File
tell application "CodeKit" process file at path "~/path/to/file.scss" end tell
The file must be part of a Project currently in CodeKit and must not be in a Skipped Folder. Note: CodeKit will process the file even if its Output Action is set to "ignore", because you're explicitly telling the app to do so.
Build A Project
tell application "CodeKit" build project containing path "~/some/path/to/a/file.js" 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.