MacOS: How to edit & upload your sketch in BBedit

While I am extremely grateful for the Arduino environment - it is free, it works, it is supported and oh so cool - as a text editor it is lacking in some basic 2010 level features such as code completion, A FREAKING WINDOW MENU, (sorry), clippings, etc etc. I didn't want to bite off the entire GCC/Eclipse/Make file/hex extravaganza just to get a modern text editor to write my sketches, so here is a little script that lets you edit in BBedit (you could use any other scriptable text editor) and then allows you to send that file to your Arduino to be uploaded with a single keyboard shortcut.

To make this work: 1) Turn on the "Use External Editor" preference. This disables editing of your sketch in the Arduino environmen. Editing now happens from whichever application has the sketch open, in this case BBedit. When you compile or upload, the Arduino IDE reloads the latest version from disk and compiles that, so hit save before you upload. You have to have the sketch open in both places. The script below checks for that and opens the sketch in the IDE if it is not already there. 2) Copy the script below into the Applescrip Script Editor and save it as "run only" and put it in the scripts folder for BBedit. 3) Assign it a keyboard shortcut from the "Keyboard and Mouse" preferences panel.

Thats it. Now you can open a sketch in BBedit, edit it, get code completion and all the other features it has and when you want to upload your sketch, use your keyboard shortcut (I use shift-command U) and the Arduino IDE will be made active, the file you are editing will be re-loaded even if it is not currently active file in the IDE and then uploaded to the board.

Let me know if you have any questions. If you know about BBedit, you probably already came up with something like this on your own, but if not, here it is for anyone to use.


Applescript code:

set MYFilePath to quoted form of POSIX path of (path to documents folder)
set MyArduinoPath to quoted form of POSIX path of (path to applications folder) & "/Arduino.app" -- set the path to your Arduino app here, this is the default location.

tell application "BBEdit"
      set BBeditFilePath to get file of first document
      set DocName to get name of first document
      copy first word of DocName to BBEditDocName
end tell

set ActiveFile to quoted form of the POSIX path of BBeditFilePath

tell application "Arduino" to activate
delay 1
tell application "System Events" to set ArduinoFileName to get name of first window in process "Arduino"

if ArduinoFileName starts with BBEditDocName then
      tell application "System Events" to tell process "Arduino"
            keystroke "u" using command down
      end tell
else
      tell application "Arduino" to activate
      set command to "open -a " & MyArduinoPath & " " & ActiveFile
      do shell script command
      delay 2
      tell application "System Events" to tell process "Arduino"
            keystroke "u" using command down
      end tell
end if

Hi, I recently made a Codeless Language Module to work with BBEdit on this.

I can't post the link b/c I can't track down my old login for some reason so I'll have to post this first and THEN post that link...

You loose the color change on numeric constants for some reason I can't figure out, but I think you need to write a language plug in to do anything more fancy than I've done here.

Best, -- Carlyn

Here is the link, hopefully -

http://23longacre.com/sharedFiles/code/arduino/BBEdit_LanguageModule/