Reputation: 31
I am creating an OS X Today Widget. To get the data I need, I am using a python script which is called by an NSTask object.
This is the code which calls the python script and displays its output:
func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)!) {
let task = NSTask()
let pipe = NSPipe()
task.launchPath = "/usr/bin/arch"
task.arguments = ["-x86_64", "/usr/bin/python", "/Users/tomas/Developement/N_news_reader/NReader1/ahoj.py"]
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
var news: String = (NSString(data: data, encoding: NSUTF8StringEncoding) as? String)!
self.widgetLabel.stringValue = news
completionHandler(.NewData)
}
In Terminal I have also changed ahoj.py's access rights with chmod 777 ahoj.py
However, after running the code, Xcode gives me following error:
/usr/bin/python: can't open file '/Users/tomas/Developement/N_news_reader/NReader1/ahoj.py': [Errno 1] Operation not permitted'
Upvotes: 3
Views: 831
Reputation: 11
Have you try to use sudo and place the arch command inside task.arguments
Like this :
task.launchPath = "/usr/bin/sudo" task.arguments = ["arch", "-x86_64", "/usr/bin/python", "/Users/tomas/Developement/N_news_reader/NReader1/ahoj.py"]
It works for me as long as I change the visudo settings to avoid the "enter your password" step.
Upvotes: 1