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:
system("nohup /PATH/Arguments.app/Contents/MacOS/Arguments argument1 argument2 &");
nohup is unix service that allows you to attach processes to itself so if you close the terminal window, the process remains alive.
Next problem that came along was capturing the arguments from within the Cocoa app. "How would I get the arguments from AppDelegate.m
if main.m
is the one that receives them and just returns an int."
Among Apple's frameworks and libraries I found one that exactly solved the problem. This library is called crt_externs.h and contains two useful variables, one to learn the number of arguments, and another one to obtain the arguments themselves.
extern char ***_NSGetArgv(void);
extern int *_NSGetArgc(void);
So, inside at the AppDelegate's from the Cocoa app we would write the following code to parse the arguments into NSString's:
char **argv = *_NSGetArgv();
NSString *argument1 = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
NSString *argument2 = [NSString stringWithCString:argv[2] encoding:NSUTF8StringEncoding];
As we can see we skip directly to the position 1 of the arguments array since position 0 contains the path itself:
argv[0] = '/PATH/Arguments.app/Contents/MacOS/Arguments'
argv[1] = 'argument1'
argv[2] = 'argument2'
Thank you all for your time and help. I learned a lot from you guys. I also hope this answer helps someone else :)
Cheers and happy coding!