Integrated GUI and OS X command-line application

Is it possible to create one application for Mac OS X that can be run strictly from the * nix command line (using stdin / stdout, from the terminal console or via ssh, etc.), but can I also start from the application icon and use the Mac GUI for all user interactions (no terminal needed)? If so, how?

I can already achieve something similar using two executable files: one for the GUI interface for the other, with pipes, sockets, shared memory or Applescript (et.al.) for communication. This question is whether I can do this using one executable and single-process application space.

Is there a way to do this without passing a new command line argument to the command line executable? (since there are obsolete problems associated with using the command line application).

+5
source share
6 answers

What you are looking for, I believe, is a way to determine if you are running from the GUI or command line. An easy way would be to get the parent process id. If you are a graphical user interface, you are launched using launchd (launch a user session). If you are a command line, then the shell or script started you (in any case, DO NOT run).

, - proc_info (# 336), libproc (check <libproc.h>). , proc_bsdinfo (. <sys/proc_info.h>) pbi_ppid, ( pbi_comm ), , .) , , NSApplicationMain.

( , .app/Contents/MacOS/<binary>, , )

+2

, --command-line. , --command-line .

./myprog --command-line

, .

+1

100%, , LSEnvironment Info.plist, -, , , Finder.

LSEnvironment ( MYAPP_GUI) , Finder, Terminal. , stdio

+1

, , .Net, , .

, - GUI. , , , GUI, , , .

, - , , . , ( ssh, , GUI).

0

, , . GUI OSX , , , . , , , (, ./MyApplication.app --some-option , , ), , , , GUI open MyApplication.app. , , CLI - , Xcode , , CLI, GUI.

, , (.. , , $PATH, - ./MyApplication.app/Contents/MacOS/actualbinaryname). , , CLI , (,/usr/local/bin) . CLI , , ( ).

0

Sorry if I miss the point, but if you use objective-C, it is not part of the answer to using the NSProcessInfo class in objective-C and look at the "arguments" variable to determine if there were any arguments and then state your code in code on what to do next?

0
source

All Articles