Bash script called from native osx app produces the error "Operation not permitted"

#What I'm Trying to do#

Call a bash script from my native osx app that syncs a local directory on my mac to a remote server.

The bash script uses the following libraries:

The Error messages on the app's console:

watch.sh: line 4: /usr/local/bin/rsync: Operation not permitted watch.sh: line 6: /usr/local/bin/fswatch: Operation not permitted

#What I have done#

  • I have run the script outside the app in the terminal and it works so problem.
  • I have tried disabling and enabling System Integrity Protection with no effect on the errors.
  • I tried calling the Bash script from a python script, and it worked without any errors.

#Code# ###OSX App Code

//////////////////////////////////////////
// FUNCTION - VIEW DID LOAD    
override func viewDidLoad() {
    super.viewDidLoad()

    command(args: "sh","watch.sh")

} // END - FUNCTION


////////////////////////////////////////////
// FUNCTION - COMMAND
func command(args: String...) {

    // GET SCRIPTS PATH
    let scriptsDir = Bundle.main.resourceURL!.appendingPathComponent("scripts").path

    // CREATE A PROCESS INSTANCE
    let process = Process()

    // SET THE PROCESS PARAMETERS
    process.launchPath = "/usr/bin/env"
    process.currentDirectoryPath = scriptsDir
    process.arguments = args

    // CREATE A PIPE AND MAKE THE PROCESS
    // PUT ALL THE OUTPUT THERE
    let pipe = Pipe()
    process.standardOutput = pipe

    // LAUNCH THE PROCESS
    process.launch()

    // GET THE DATA
    let data = pipe.fileHandleForReading.readDataToEndOfFile()
    let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue)

    print(output!)

} // END - FUNCTION

###Bash Script

#!/bin/bash
/usr/local/bin/rsync --rsh="/usr/local/bin/sshpass -p ************* ssh -l username" -azP --delete "/path/to/local" [email protected]:/path/to/remote

/usr/local/bin/fswatch -o "/path/to/local" | while read f; do

    /usr/local/bin/rsync --rsh="/usr/local/bin/sshpass -p ************* ssh -l username" -azP --delete "/path/to/local" [email protected]:/path/to/remote

done

Relevant tags