CodeKit 2 Hook for Coda (auto-upload)

Just a few days ago CodeKit 2 has been released. It's an awesome piece of software and you really should try it. CodeKit 2 has a new feature called "hooks". With hooks you can run any Applescript or bash script after files have been processed. You can take a look at this video for more details about hooks in CodeKit.

Now to the best part... I'm using Coda 2 by Panic as my code editor. With it's built in FTP it's already possible to publish changed files to the server with a simple keyboard shortcut (^⌘P). Now with CodeKits hooks you can easily automate this. All you need to do is to go into the project settings tab of CodeKit and select "Hooks" from the bottom. Add a new hook with the "+" and paste the following Applescript into the textarea:

delay 1
tell application "Coda 2" to activate
tell application "System Events"
	keystroke "p" using {command down, control down}
end tell

This is only running the publish function with the keyboard shortcut. I also added a short delay since Coda was too fast in my tests and didn't upload source maps every time.

What you need to know

For Codas "publish" function you need to specify the local and remote root paths into your site settings (both to the same relative path!). So if you're CodeKit project folder is "assets", you need to set the remote root path in Coda also to the "assets" folder at your remote server.

You might also run into the problem that Coda is not recognizing changed files by CodeKit. But there's a solution for that: Go to Coda and navigate to your local project folder. Right-click each file that has been compiled by CodeKit and click "open with" and select CodeKit 2. Do this with every compiled file! Now Coda will recognize file changes from CodeKit and automatically add them to the publish queue.

Share the article!

Share your thoughts!