Compile and Run C Code in TextWrangler

by georgeg4 in Circuits > Apple

14471 Views, 15 Favorites, 0 Comments

Compile and Run C Code in TextWrangler

c 2_Fotor_Collage.jpg
Screen Shot 2015-03-20 at 5.12.16 PM.png
Screen Shot 2015-03-20 at 3.05.32 PM.png
Screen Shot 2015-03-20 at 3.03.12 PM.png

In this tutorial i'll be demonstrating how to compile and run C code right inside of TextWrangler using Xcode's GCC C compiler , I assume that you have already installed Xcode's command line tools and i'll not be explaining how to do that in this tutorial , if you haven't , check this tutorial on OS X Daily first.

The AppleScript

Screen Shot 2015-03-20 at 3.03.12 PM.png

i made this apple script to use Xcode's GCC C compiler to compile and run the C file being edited in TextWrangler , it saves the changes made , compiles it to an app called "output" , then runs this "output" app.

the compiled app is saved in the same location of the C file.

download this AppleScript here.

Put the Script in TextWrangler

Screen Shot 2015-03-20 at 3.03.33 PM.png
Screen Shot 2015-03-20 at 3.03.48 PM.png
Screen Shot 2015-03-20 at 3.04.51 PM.png

Open up TextWrangler , then go to "Script menu > Open Scripts Folder"

Copy the AppleScript to TextWrangler's Scripts folder.

A new item should appear in the Scripts menu called "C compile and run".

Set a Shortcut (Optional)

Screen Shot 2015-03-20 at 3.05.00 PM.png
Screen Shot 2015-03-20 at 3.05.19 PM.png
Screen Shot 2015-03-20 at 3.05.32 PM.png

Open TextWrangler's preferences.

Navigate to "Menues & Shortcuts" > "Scripts" > "C compile and run"

Click it to set a keyboard shortcut.

I've set mine to "CMD ." , choose whatever you want but make sure not to replace a previously set default shortcut.

Enjoy Your Development

Screen Shot 2015-03-20 at 5.12.16 PM.png

Enjoy developing your C code , and don't forget to check my other projects on my website George Gabra Jr.