NSWorkspace question

Discussion in 'Mac Programming' started by RobRiley, May 14, 2009.

  1. RobRiley macrumors member

    Joined:
    Feb 4, 2009
    Location:
    London
    #1
    Hi,

    My app needs to run scripts in terminal using NSWorkspace but also needs to pass arguments depending on various other conditions. My code is as follows but I don't know how to pass the arguments:

    Code:
    NSString * path    = @"/path/to/script/script.sh";
    NSURL * fileURL = [NSURL fileURLWithPath: path];
    NSWorkspace * ws = [NSWorkspace sharedWorkspace];
    [ws openFile:[fileURL path] withApplication:@"Terminal"];
    
    Can anyone help?

    Thanks,
     
  2. robbieduncan Moderator emeritus

    robbieduncan

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

    Joined:
    Feb 4, 2009
    Location:
    London
    #3
    Thanks - I already use NSTask for some other bits in my app and have it pipe the output back to the window. But the problem is the scripts I want to run here require user interaction so (for now) they need to run in Terminal. Can I still use NSTask to open Terminal and run these scripts?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    In that case I'm not sure. Are you trying to pass arguments to Terminal.app or to the script? If it's to the script then I'm not sure how you can do this within Terminal.app (unless, perhaps, it supports AppleScript)...
     
  5. RobRiley thread starter macrumors member

    Joined:
    Feb 4, 2009
    Location:
    London
    #5
    To the script itself. It's only a temp solution until I come up with something more sophisticated so maybe Applescript would work as a quick fix :)

    Thanks.
     

Share This Page