NSUserScriptTask unhappy about script format

I've got a trivial MacOS script:

#!/bin/sh

#  OpenInSafari.sh

open /tmp/GitNAVs.html

that I try to invoke with:

let bundle = Bundle.main
  if let script = bundle.url(forResource: "OpenInSafari", withExtension: "sh") {
  do {
  let scriptTask = try NSUserScriptTask(url: script)
  scriptTask.execute(completionHandler: nil)
  } catch {
  print(error)
  }

But I get:

Error Domain=NSCocoaErrorDomain Code=259 "The file “OpenInSafari.sh” couldn’t be opened because it isn’t in the correct format."

The *.sh file was created by Xcode and is where it's supposed to be in the bundle with read and write permissions. Any clue what's the problem?


Thanks,

Richard

Accepted Reply

Answering my own question:


chmod +x OpenInSafari.sh


Why Xcode would create a shell file without the execute permission is really brain-dead.

Replies

Answering my own question:


chmod +x OpenInSafari.sh


Why Xcode would create a shell file without the execute permission is really brain-dead.