Run command for Objective-C

58 views
Skip to first unread message

Derek Yates

unread,
Apr 12, 2024, 8:33:05 AMApr 12
to BBEdit Talk
I am learning Objective-C and would like to be able to compile and run code snippets using BBEdit. I presume I need to use the Run command and somehow send the snippet to clang using a shell script. 

I can run Python snippets, but can't figure out how to do the same for Objective-C. For a start, all the shebang menu items are grey (presumably because Objective-C is not an interpreted language).

Can't find anything online or in the manual on how to do this. Can someone point me in the right direction?

Derek Yates

unread,
Apr 15, 2024, 2:57:25 PMApr 15
to BBEdit Talk
The following seems to work:

1) Create the following script:
#!/bin/zsh
CLANG_OUTFILE=${BB_DOC_PATH%%\.m}.out
clang -x objective-c -o $CLANG_OUTFILE $BB_DOC_PATH
$CLANG_OUTFILE

2) Save it (with extension .sh, although this might not be necessary) in the Scripts Folder (typically ~/Library/Application Support/BBEdit/Scripts)

3) Write and save (somewhere on disk) the Objective-C source code  (I used '.m' suffix which the script will remove and replace with '.out')

4) With the saved source file as the active window in BBEdit, select the script from the script menu. The results should appear in the Unix Script Output.log window.

Rich Siegel

unread,
Apr 15, 2024, 3:04:30 PMApr 15
to 'Derek Yates' via BBEdit Talk
On 15 Apr 2024, at 14:48, 'Derek Yates' via BBEdit Talk wrote:

> The following seems to work:
> [...]

Glad to hear you found a working solution.

You might find BBEdit's support for the Language Server Protocol useful: https://www.barebones.com/support/bbedit/lsp-notes.html

Additionally, piping the output of the `clang` command through `bbresults` might provide a nicer experience for compile errors (if you aren't using clangd).

R.

--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <https://www.barebones.com/>

Someday I'll look back on all this and laugh... until they sedate me.
Reply all
Reply to author
Forward
0 new messages