[Interest] console on OSX

René J. V. Bertin rjvbertin at gmail.com
Thu Sep 22 10:06:09 CEST 2016


Thiago Macieira wrote:

> For macOS, there may be something equivalent in the Info.plist file for your
> bundle. Please consult Apple documentation.

No, not that I know of.

The automatic way of launching a console application via Terminal is to build is 
as a traditional (POSIX-style) executable: CONFIG-=app_bundle (if that's not 
done automatically by CONFIG+=console). Double-clicking one of those in the 
Finder will use Terminal to run the application.

It will be a bit tricky to put an icon on the executable that's visible in the 
Finder and shows up when the app is running (if you want that, of course).

Alternatively, you can set up an app bundle that does the hand-off for you. This 
is done most easily on the finished app bundle: 

%> mv build/foo.app/Contents/MacOS/foo build/foo.app/Contents/MacOS/foo.bin
%> cp -p wrapper.sh build/foo.app/Contents/MacOS/foo
%> chmod 755 build/foo.app/Contents/MacOS/foo

wrapper.sh will contain something like

#!/bin/sh
open -W -n -a Terminal.app foo.bin

you can also use iTerm.app or any other terminal emulator you prefer.

Note though that applications launched like this will most likely not be able to 
receive any arguments, notably files to be opened. If you drop files on a console 
app in MS Windows the filenames are (or used to be) passed as standard argc,argv 
arguments. On OS X this is not the case. If you need that you'll need to 
investigate utilities like DropScript, use AppleScript, or write your own 
launcher.

---------
Bonus:
Here's a little script to execute any commandline in a Terminal.app window:

#!/bin/sh

SCRIPT="${TMPDIR}/RunInTerminal.$$.sh"

CleanUp() {
        rm -f "${SCRIPT}"
}

trap CleanUp 0
trap CleanUp 1
trap CleanUp 2
trap CleanUp 15

if [ $# != 0 ] ;then
        echo "$@" > "${SCRIPT}"
else
        cat - > "${SCRIPT}"
fi
chmod 700 "${SCRIPT}"

echo "Running the requested command(s) in a new Terminal instance"
echo "Remember to quit the Terminal application!"

open -W -n -F -a Terminal.app "${SCRIPT}"





More information about the Interest mailing list