parameters for starting program

Discussion in 'Mac Programming' started by macfreaker, Sep 6, 2008.

  1. macrumors newbie

    macfreaker

    Joined:
    Aug 19, 2008
    Location:
    Belgium
    #1
    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
    
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. thread starter macrumors newbie

    macfreaker

    Joined:
    Aug 19, 2008
    Location:
    Belgium
    #3
    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.
     

    Attached Files:

  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    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?
     
  5. thread starter macrumors newbie

    macfreaker

    Joined:
    Aug 19, 2008
    Location:
    Belgium
    #5
    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.
     
  6. macrumors regular

    Joined:
    Oct 15, 2007
    #6
    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.
     

Share This Page