View Full Version : NSWorkspace question
RobRiley
May 14, 2009, 09:20 AM
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:
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,
robbieduncan
May 14, 2009, 09:34 AM
Don't use NSWorkspace for that! Use NSTask (http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSTask_Class/index.html).
RobRiley
May 15, 2009, 04:33 AM
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?
robbieduncan
May 15, 2009, 04:36 AM
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?
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)...
RobRiley
May 15, 2009, 04:40 AM
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)...
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.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.