Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RobRiley

macrumors member
Original poster
Feb 4, 2009
35
0
London
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,
 
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?
 
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)...
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.