-1

i've got a file "Script.sh", which includes different shell commands, like some defaults write or creating folders, moving files etc. For Example:

#!/bin/sh
defaults write com.apple.finder AppleShowAllFiles -bool TRUE
killall Finder

However, im pretty new to Objective C and didnt find any solution to run the whole file with NSTask. I only found some solutions with directly coding it into Objective C.

Is it even possible?

samecat
  • 335
  • 1
  • 11
  • The correct use is described here https://stackoverflow.com/questions/19183664/using-nstask-to-launch-shell-script-that-launches-node-js – ivion Nov 20 '18 at 14:32

1 Answers1

-1

Got it working. Just set the path of a Shell script as the argument of NSTask and launch it.

NSURL *myscript =[[NSBundle mainBundle] URLForResource:@"script" withExtension:@"sh"]; 


NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/bin/sh";

task.arguments =@[myscript.path];
[task launch];
[task waitUntilExit];
samecat
  • 335
  • 1
  • 11