https://github.com/buresdv/sudo-helper
https://github.com/buresdv/sudo-helper
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/buresdv/sudo-helper
- Owner: buresdv
- Created: 2024-06-01T21:12:53.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-02T12:13:38.000Z (about 2 years ago)
- Last Synced: 2025-10-20T14:56:43.863Z (10 months ago)
- Language: Swift
- Size: 4.88 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# Swift Askpass Helper
This project aims to create a native-looking input alert for ASKPASS operations on macOS.
## Motivation
I started this project to add support for sudo operation to [Cork](https://github.com/buresdv/Cork). I was not satisfied with the way dialogs shown by AppleScript looked, and wanted a more native implementation
## Usage
Set the `SUDO_ASKPASS` environment variable in your Swift shell executor to the path of the compiled executable. For example, this is how it is used in Cork:
```swift
let task = Process()
// (Other code)
var finalEnvironment: [String: String] = .init()
// (Other code)
let sudoHelperURL: URL = Bundle.main.resourceURL!.appendingPathComponent("Sudo Helper", conformingTo: .executable)
finalEnvironment["SUDO_ASKPASS"] = sudoHelperURL.path // <-- HERE
// (Other code)
task.environment = finalEnvironment
```
## Customization
This project only supports hardcoded strings. In order to change what the alert says, change these variables in the source code before compiling:
```swift
alert.window.title // Line 17
alert.messageText // Line 18
alert.informativeText // Line 19
```
## System Requirements
This project supports macOS 10.13 and later.
## Technical Details
This project creates a `NSAlert` with a password input field. When the user submits the field, the program returns the submitted password to the caller of the `SUDO_ASKPASS` operation, and the app quits.