PDA

View Full Version : parameters for starting program




macfreaker
Sep 6, 2008, 02:23 PM
Since i'm new in programming in xcode (cocoa), i have a question. I'm making a program that must start another program with parameters. The other program is vlc and must be started with parameters to stream video and audio from my sat receiver (dreambox) to my mac. Here is already a part of my code. Maybe someone can tell me how to add paramters.

#import "MAFoo.h"

@implementation MAFoo
- (IBAction)startknop:(id)sender {

NSWorkspace * ws = [NSWorkspace sharedWorkspace];
[ws launchApplication:@"VLC"];
}

- (IBAction)stopvlcknop:(id)sender {

}

-(void)awakeFromNib
{
//NSString *string = [dreamboxip stringValue];

// [dreamboxip setTextView:"192.168.0.100"];
[dreamboxport setIntValue:8001];
}

@end



robbieduncan
Sep 6, 2008, 02:29 PM
Don't use NSWorkspace. Use NSTask

macfreaker
Sep 6, 2008, 03:01 PM
Don't use NSWorkspace. Use NSTask
I've change it but don't see how to add the parameters.Maybe you can help me. a example of how i did it in AS you can see here:
-- display dialog dreamboxip
tell application "VLC"
OpenURL "http://" & dreamboxip & ":" & dreamboxpoort & "/1:0:1:31E7:45C:35:C00000:0:0:0:"
play
end tell
The port and the ip i wil get from a textfield , but how to paste this in the arguments. And i've also a permission error.

robbieduncan
Sep 6, 2008, 03:14 PM
Read the documentation for NSTask (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/Reference/Reference.html). There are clearly marked methods for setting the arguments.

Also you, as a developer, should be aware that /Applications/VLC.app is a directory, not an executable.

If you are comfortable using AppleScript then why not use AppleScript Studio to make the app?

macfreaker
Sep 6, 2008, 03:19 PM
Read the documentation for NSTask (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/Reference/Reference.html). There are clearly marked methods for setting the arguments.
Also you, as a developer, should be aware that /Applications/VLC.app is a directory, not an executable.
If you are comfortable using AppleScript then why not use AppleScript Studio to make the app?
Yeah , was already reading the doc.
I've also changed my code to :
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/Applications/VLC.app/Contents/MacOS/VLC"];

Because you're right.
And i've made this in applescript, but it was to slow .
But thanks anyway for the help.

hhas
Sep 6, 2008, 04:54 PM
Yeah , was already reading the doc.
I've also changed my code to :
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/Applications/VLC.app/Contents/MacOS/VLC"];

Because you're right.
And i've made this in applescript, but it was to slow .
But thanks anyway for the help.

IIRC, launching GUI applications this way isn't recommended by Apple due to differences in the way that bundle-based Mac applications are launched compared traditional *nix executables. Admittedly, VLC is already a *nix port so may be a bit more forgiving of you bypassing the normal Mac launch procedure.

Still, if it provides an Apple event API for the purpose, that's probably the best (and most official) way to do it, either via NSAppleScript or an ObjC-Apple event bridge.