Swift Execute command line command in Sandbox mode
Yeah, I already thought so, but I was thinking about if it is possible to explicitly ask the user to give the application the permission for this specific folder
You are thinking in the right direction. Clearly sandboxes apps would be pretty useless if they couldn't access files and folders, and the key to them doing so is the user granting them permission. This permission is granted using the standard open and save dialogs, when the user selects a file/folder the app is granted permission to read/write/create it.
Need access to a specific file/folder? Customise the open dialog to guide the user to select that particular file/folder, and check the result to make sure they have - handling the situation when they choose not to.
Wish your app to retain across launches the access right granted by the user to to a file/folder? Then you need to create and store a security scoped bookmark.
Time to do some reading, if you get stuck ask a new question and someone will undoubtedly help you. Remember to show what you've found out, code you've written, etc.
HTH
Can't execute shell script commands in sandboxed cocoa app
Probably not what you want to hear:
- The first thing I've done is to get permission to execute "BuildTask.command".
You have two problems here. First if you wish to change the permissions on a file from within an app you should be using framework or system calls to do so directly, not calling NSTask
to execute a shell which in turn executes a command which calls those framework or system calls...
Second you should not be trying to change the contents of your application bundle from within the application. If you need a file in your application bundle to have execute permission then set it when you build the app. You can do that with a build phase in Xcode.
So, have I any chance to release this tool to Mac App Store?
Little or none.
Xcode itself is not a sandboxed application and the error messages you are getting indicate that it is trying to do operations which violate the sandbox it has inherited from your app.
HTH
Running terminal commands in in cocoa app
Simple answer is found by disabling App Sandbox in your Cocoa Application (found under your Project app target > Capabilities tab > App Sandbox switch). You'll find that you're being blocked by a sandbox exception. Disabling sandboxing should fix your issue.
You can also see this in Console.app if you filter for your app name or the sandboxd process. You'll likely have an entry like this when sandboxing is enabled:
error 00:21:57.502273 +0000 sandboxd Sandbox: sh(17363) deny(1) file-read-data /dev/ttys003
How to sandbox a command line tool?
I was having this exact problem, and it went away when I added an embedded Info.plist.
Try these clang flags (assuming you have info.plist
in the build directory):
-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker info.plist
Swift shell command returns empty result
Since chrome-cli 1.6.0 was released in 2018 but new Chrome versions with new features appear regularly I suggest to use Chrome directly via SBApplication
to access to any needed info e.g.:
import ScriptingBridge
@objc protocol ChromeTab {
@objc optional var id: Int {get}
@objc optional var title: String {get}
}
extension SBObject: ChromeTab {}
@objc protocol ChromeWindow {
@objc optional var tabs: [ChromeTab] {get}
}
extension SBObject: ChromeWindow {}
@objc protocol ChromeApplication {
@objc optional var windows: [ChromeWindow] {get}
}
extension SBApplication : ChromeApplication {}
// Print all tabs
if let chrome = SBApplication(bundleIdentifier: "com.google.Chrome") as ChromeApplication? {
if let window = chrome.windows?.first {
window.tabs?.forEach {
if let id = $0.id, let title = $0.title {
print("[\(id)] -", title)
}
}
}
}
For more info about Chrome Extensions look at https://developer.chrome.com/extensions/devguide
Related Topics
Set Maximum Characters (To One) in a Nstextfield in Swift
How to Name File Stored to Files App via Uactivityviewcontroller
How to Set .Realm File on Realm
Preload a Scene to Prevent Lag
How to Use Protocols for Stucts to Emulate Classes Inheritance
Showing Action Sheet in The Custom Cell in Swift
Higlight Speech Utterance in Swiftui
Swift Custom Response Serializer Is Returning Images at Random
Data Structure for Fast Lookup with Multiple Criteria
Swift: How to Update UI When Listening to a Stream
Closure (With Default Value) as Function Parameter
Why Is a Firestore Listener Returning .Added Twice When a Single Document Is Added
Change The 2Nd and 3Rd Pickerview Acording to What Row from The 1St Picker Is Selected
Streaming .M3U8 Using Mpmovieplayercontroller Does Not Work
Swift 3/iOS 10/Todayextension - Userdefaults Always Returns Nil