0

I have an application : TexturePacker. If I click on the application icon in the application folder it launches the gui. If I type "texturepacker" in terminal, it runs the command line version.

I want to launch the command line version programmatically! When I use the code below, it launches the GUI. What shell command should I use so that the application (command line version) launches as if I typed in "texture packer" in terminal.

NSTask *theProcess = [[NSTask alloc] init];    
[theProcess setLaunchPath:@"/usr/bin/open"];

[theProcess setArguments:[NSArray arrayWithObjects:
                                @"-a", 
                                @"/Applications/TexturePacker.app",
                                nil]];  
            // Arguments to the command: the name of the
            // Applications directory

            [theProcess launch];
            // Run the command

            [theProcess release];

If this is a noob question. I apologize. I am noobtastic. :S

EDIT: Figured out part of it. I needed to specify the path to the binary inside the app to launch it. But How do I pass arguments to that? If I add any more arguments to the array, the shell assumes that it is an argument to the "open" command. If I add it to the string with the path to texture packer, the shell says the application is not found. :S

tcovo
  • 7,550
  • 2
  • 20
  • 13
Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190
  • Why are you using `/usr/bin/open` for launching the program? For launching a command-line program like this, you should be able to set the NSTask launch path to your texturepacker binary, and then you can simply setArguments to an array containing the arguments for texturepacker. – tcovo Mar 22 '12 at 14:28
  • If you really want to use `/usr/bin/open`, then you can pass the texturepacker arguments by adding them to the array, but separated from the previous arguments by "--args" (see documentation of [open](https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/open.1.html)). But I don't think `open` is appropriate in this situation. – tcovo Mar 22 '12 at 14:30
  • You are correct! I should access the binary directly and then pass the arguments. If you answer the question I will mark it correct! :D Thanks. – Rahul Iyer Mar 22 '12 at 15:14

1 Answers1

2

For launching an executable program, there is no need to use open. You can set the NSTask launch path to your texturepacker binary, and then you can setArguments to an array containing the arguments for texturepacker:

NSTask *theProcess = [[NSTask alloc] init];

[theProcess setLaunchPath:@"/path/to/texturepacker"];

// Set arguments for invoking texturepacker
[theProcess setArguments:[NSArray arrayWithObjects:
                                @"-x", 
                                @"-y",
                                @"-z",
                                nil]];

// Run the task
[theProcess launch];

[theProcess release];
tcovo
  • 7,550
  • 2
  • 20
  • 13