PrintToVeraeTimeStamp/cmd/verae-print/saveas_darwin.go
Grok Bot (for George) 13ebc351f5 0.3.2: Save As filename prompt per print (Windows + macOS)
- promptForFilename setting (default true; env VERAE_PROMPT_FOR_FILENAME),
  'verae-print config --prompt-for-filename', last Save As folder in
  ~/.verae/state.json
- Windows helper: common file dialog (PDF filter, overwrite prompt, topmost
  owner) before stamping; macOS printer path: choose file name (NSSavePanel)
  via 'stamp -prompt-name -title'; cancel discards the job (no stamp/credit)
- job.Options.OutPath: original saved at the chosen path, certificate and
  .verae.json next to it with the chosen base name (never overwritten)
- held jobs keep the chosen path (pendingMeta.OutPath)
- installer: 'Ask for a file name for each print' checkbox; removed the
  'Open the user guide' finish-page checkbox; mac-key-setup asks too
- auth test no longer touches the real macOS keychain (VERAE_SKIP_KEYCHAIN)
- version 0.3.2
2026-10-03 20:00:56 -04:00

37 lines
1 KiB
Go

//go:build darwin
package main
import (
"bytes"
"fmt"
"os/exec"
"strings"
)
// "choose file name" is the standard NSSavePanel; it asks before replacing an
// existing file. Text is passed via argv (no AppleScript string quoting).
const saveDialogAS = `on run argv
set nm to item 1 of argv
set dir to item 2 of argv
activate
set f to choose file name with prompt "Save timestamped print as" default name nm default location (POSIX file dir)
return POSIX path of f
end run`
func nativeSaveDialog(name, dir string) (string, bool, error) {
cmd := exec.Command("/usr/bin/osascript", "-e", saveDialogAS, name, dir)
var out, errb bytes.Buffer
cmd.Stdout, cmd.Stderr = &out, &errb
if err := cmd.Run(); err != nil {
if strings.Contains(errb.String(), "-128") { // User canceled.
return "", false, nil
}
return "", false, fmt.Errorf("%v: %s", err, strings.TrimSpace(errb.String()))
}
p := strings.TrimSpace(out.String())
if p == "" {
return "", false, fmt.Errorf("empty path from dialog")
}
return p, true, nil
}