diff --git a/README.md b/README.md index b8be6b4..2bcb6f3 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ as well as a *“port”* of the `zenity` command to both Windows and macOS base Lots of things are missing. For now, these are the only implemented dialogs: -* message (error, info, question, warning); and -* file selection. +* message (error, info, question, warning) +* file selection Behavior on Windows, macOS and other UNIXes might differ sliglty. Some of that is intended (reflecting platform differences), @@ -28,11 +28,13 @@ Why reinvent this particular wheel? * no main loop (or other threading requirements) * no initialization * on Windows: - * Explorer shell not required (works in Server Core) - * no other dependencies + * no additional dependencies + * Explorer shell not required + * works in Server Core * Unicode support * on macOS: - * only dependency is `osascript`, JXA + * only dependency is `osascript` (with [JXA](https://developer.apple.com/library/archive/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/Introduction.html)) + * JavaScript is easier to template with `html/template` * on other UNIXes: - * wraps either one of `matedialog`, `qarma`, `zenity` (in that order of preference) - * no command line support + * wraps either one of `matedialog`, `qarma`, `zenity` + * in that order of preference, most to least specific diff --git a/file_darwin.go b/file_darwin.go index f7ba02a..67d90e5 100644 --- a/file_darwin.go +++ b/file_darwin.go @@ -10,11 +10,12 @@ import ( func SelectFile(options ...Option) (string, error) { opts := optsParse(options) + dir, _ := splitDirAndName(opts.filename) out, err := osa.Run("file", osa.File{ Operation: "chooseFile", Prompt: opts.title, - Location: opts.filename, Type: appleFilters(opts.filters), + Location: dir, }) if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { return "", nil @@ -30,13 +31,14 @@ func SelectFile(options ...Option) (string, error) { func SelectFileMutiple(options ...Option) ([]string, error) { opts := optsParse(options) + dir, _ := splitDirAndName(opts.filename) out, err := osa.Run("file", osa.File{ Operation: "chooseFile", Multiple: true, Prompt: opts.title, - Location: opts.filename, Separator: cmd.Separator, Type: appleFilters(opts.filters), + Location: dir, }) if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { return nil, nil @@ -55,10 +57,12 @@ func SelectFileMutiple(options ...Option) ([]string, error) { func SelectFileSave(options ...Option) (string, error) { opts := optsParse(options) + dir, name := splitDirAndName(opts.filename) out, err := osa.Run("file", osa.File{ Operation: "chooseFileName", Prompt: opts.title, - Location: opts.filename, + Location: dir, + Name: name, }) if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { return "", nil @@ -74,10 +78,11 @@ func SelectFileSave(options ...Option) (string, error) { func SelectDirectory(options ...Option) (string, error) { opts := optsParse(options) + dir, _ := splitDirAndName(opts.filename) out, err := osa.Run("file", osa.File{ Operation: "chooseFolder", Prompt: opts.title, - Location: opts.filename, + Location: dir, }) if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { return "", nil