3

I really need to be able to have a .sh file ran from swift! I looked into t and for some reason people want me to run the shell program in the swift file but it doesn't end up working. I'm trying to run one command, really. The shell command does need argument which is going to be passed into from the app, though. The command I'm trying to run is:

chmod a-x /Applications/the input here

I also must be able to take the users input to put the password. How would I input the password?

EDIT

I have already tried:

import Foundation
let task = NSTask();
task.launchPath = "/bin/chmod"
task.arguments = ["a-x /Applications/application.app"]

task.launch()

Does anyone have any tips?

Jack
  • 955
  • 1
  • 9
  • 30
  • What did you try? Which part of your code doesn't work as expected? Unfortunately open source NSTask is not yet implemented ... – user3441734 Jan 17 '16 at 06:44
  • 1
    Possible duplicate of [How to execute external program from Swift?](http://stackoverflow.com/questions/25726436/how-to-execute-external-program-from-swift/25729093#25729093) – Eric Aya Jan 17 '16 at 16:06
  • Could be considered but mine is a very watered down version. The other involves taking outputs and implementing them but mine is just simply running the program. – Jack Jan 17 '16 at 16:08
  • In this particular case, why don't you use `FileManager.default.setAttributes([FileAttributeKey.posixPermissions: 0o000], ofItemAtPath: "/your/file")` (with suitable digits instead of `000`)? – Raphael Mar 27 '17 at 08:13

1 Answers1

3

Figured it out! I did not know that the arguments had to be like this:

task.arguments = ["a-x", "/Applications/application.app"]
Jack
  • 955
  • 1
  • 9
  • 30