Reputation: 41
Im attempting to build a swift OSX app that can run some shell commands to mount the users requested VPNs. I tried using NSAppleScript but got an error every time I tried to run with Admin privileges so I decided to use NSTask to call an apple script that will run as admin and mount the VPNs.
In order to debug getting the shell commands working in swift through NSTask I made a test script file that just has a simple whoami command that works when I run it in the script editor and in the terminal using osascript /Users/amaloney/Desktop/test.scpt
However in my Swift file
import Foundation
let task = NSTask();
task.launchPath = "/usr/bin/osascript"
task.arguments = ["/Users/amaloney/Desktop/test.scpt"]
task.launch()
I continue to get the following error
script error -54. Couldn't get error text because of error -1700.
Any thoughts on how I can get this working?
Thanks!
For reference - test.scpt
do shell script "whoami"
Upvotes: 3
Views: 2314
Reputation: 41
I was running this in an Xcode Playground, which apparently was the source of the problems. Once I went ahead and integrated this code into my OSX app it worked fine.
Upvotes: 1
Reputation: 47284
The issues appear to be related to the AppleScript
portions of your code:
script error -54
↳ -54 File permission error
Couldn't get error text because of error -1700.
↳ Can’t make ... into type item.
It's likely your script tries to perform an operation that it doesn't have permission to do, and also tries to assign the wrong type — Without seeing the script or knowing what it does it's unknown.
Upvotes: 0