Mac parameters for starting program

macfreaker

macrumors newbie
Original poster
Aug 19, 2008
9
0
Belgium
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.

Code:
#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
 

macfreaker

macrumors newbie
Original poster
Aug 19, 2008
9
0
Belgium
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:
Code:
-- 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.
 

Attachments

robbieduncan

Moderator emeritus
Jul 24, 2002
24,594
59
Harrogate
Read the documentation for NSTask. 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

macrumors newbie
Original poster
Aug 19, 2008
9
0
Belgium
Read the documentation for NSTask. 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 :
Code:
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

macrumors regular
Oct 15, 2007
126
0
Yeah , was already reading the doc.
I've also changed my code to :
Code:
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.