swiftDialog / swiftDialog

Create user-notifications on macOS with swiftDialog
MIT License
546 stars 53 forks source link

Custom Command File with spaces generates error #369

Open trice81384 opened 3 months ago

trice81384 commented 3 months ago

Describe the bug When using a custom command file with spaces in the path, in bash, it looks like swift dialog tries to create/verify the existence of the file before it writes any updates to it. If the path contains a space the shell will display the following error messages: touch: /Path up until first space: Permission denied -and- "ERROR: Failed to get file creation date: The file “FILE NAME” couldn’t be opened because there is no such file. Echoing out the path to the command

When the space is removed from the path to the command file these errors do not appear. This does not affect the command file being written to and dialog updates being processed appropriately. This happens if the path is quoted or the space in the path is escaped.

To Reproduce Steps to reproduce the behavior:

  1. In bash (script or in the shell window) create a path to a custom command file with a space in its path and assign it to a variable (the folder /tmp/swift dialog folder already exists and is world writeable) eg: CSVCommandFile=$(mkdir "/tmp/swift dialog/swiftdialog.log") -or- CSVCommandFile=$(mkdir /tmp/swift\ dialog/swiftdialog.log)

  2. Run a dialog window from a bash shell/script specifying this command file via a quoted variable eg dialog --commandfile "$CSVCommandFile" --jsonfile /path to file

  3. The error "touch: /tmp/swift : Permission denied" is displayed in the shell

  4. Send an update to the command file via the quoted variable. eg echo "button1: enable" >> "$CSVCommandFile"

  5. The error "ERROR: Failed to get file creation date: The file “swiftdialog.log” couldn’t be opened because there is no such file." is displayed in the shell

  6. The dialog window is updated successfully

Expected behavior A command file with a valid and accessible path should generate no errors.

Desktop (please complete the following information):

BigMacAdmin commented 3 months ago

I can recreate this in both 2.4.2.4755 and 2.5.0.4757

Does not appear to affect functionality, just results in errors being generated.

#!/bin/zsh --no-rcs
# shellcheck shell=bash

dialogCommandFile=$(mktemp "/var/tmp/Command File With Space.XXXXXXXX")

# execute a dialog command
function dialog_command(){
    /bin/echo "$@"  >> "$dialogCommandFile"
    sleep .1
}

dialog --title "Testing Whitespace" --message "This is a test" --button1disabled --button1text "disabled" --commandfile "$dialogCommandFile" &

sleep 3

dialog_command "button1: enable"

Results:

ERROR: Failed to get file creation date: The file “Command%20File%20With%20Space.lcVKLsV0” couldn’t be opened because there is no such file.