Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All your answers worked properly for me, but I found another solution that suits better my needs. I needed to launch a Cocoa app from a Command Line Tool, which I achieved with the following line:</p> <pre><code>system("nohup /PATH/Arguments.app/Contents/MacOS/Arguments argument1 argument2 &amp;"); </code></pre> <p><em>nohup</em> is unix service that allows you to attach processes to itself so if you close the terminal window, the process remains alive.</p> <p>Next problem that came along was capturing the arguments from within the Cocoa app. "How would I get the arguments from <code>AppDelegate.m</code> if <code>main.m</code> is the one that receives them and just returns an int."</p> <p>Among Apple's frameworks and libraries I found one that exactly solved the problem. This library is called <a href="http://opensource.apple.com/source/Libc/Libc-391.5.21/include/crt_externs.h" rel="nofollow">crt_externs.h</a> and contains two useful variables, one to learn the number of arguments, and another one to obtain the arguments themselves.</p> <pre><code>extern char ***_NSGetArgv(void); extern int *_NSGetArgc(void); </code></pre> <p>So, inside at the <em>AppDelegate's</em> from the Cocoa app we would write the following code to parse the arguments into <em>NSString's</em>:</p> <pre><code>char **argv = *_NSGetArgv(); NSString *argument1 = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding]; NSString *argument2 = [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding]; </code></pre> <p>As we can see we skip directly to the position 1 of the arguments array since position 0 contains the path itself:</p> <pre><code>argv[0] = '/PATH/Arguments.app/Contents/MacOS/Arguments' argv[1] = 'argument1' argv[2] = 'argument2' </code></pre> <p>Thank you all for your time and help. I learned a lot from you guys. I also hope this answer helps someone else :)</p> <p>Cheers and happy coding!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload