i have the following problem: Hazel seems to not properly handle filenames that contain special characters (German: öüä, French: éèàç, etc.) in connection with shell scripts.
I have the following shell script on my Desktop: ~/Desktop/test.sh
- Code: Select all
sourceIn=$1
fileIn=$(basename "$sourceIn")
fileNameIn="${fileIn%.*}"
fileExtIn="${fileIn##*.}"
# Debug output
printf "$sourceIn \n" > ~/Desktop/_debug.txt
printf "$fileIn \n" >> ~/Desktop/_debug.txt
printf "$fileNameIn \n" >> ~/Desktop/_debug.txt
printf "$fileExtIn \n" >> ~/Desktop/_debug.txt
if [ $fileExtIn == "mkv" ]; then
mkvpropedit "$sourceIn" --edit info --set title="$fileNameIn"
fi
It extracts the file name and uses this file name to write it as title to MKV video files. For this i use the tool MKVpropedit.
The script works perfectly if executed directly from the terminal. File names can contain special characters. Try
- sh test.sh "/Users/testuser/Desktop/Test.mkv"
- sh test.sh "/Users/testuser/Desktop/Tüst.mkv"
- sh test.sh "/Users/testuser/Desktop/Tést.mkv"
However, when I call the very same script from Hazel, the script will only work if the file name does not contain a special character.
E.g. I have a folder ~/Desktop/Movies and i have a Hazel rule that is watching this Movies folder
The rule only contains the following embedded shell script
- Code: Select all
#!/bin/zsh
sh ~/Desktop/test.sh "$1"
If i add a MKV movie file with the name Test.mkv to the Movies folder, the Rule/Script will execute without problems. However, filenames like Tüst.mkv or Tést.mkv will fail. In Hazel log i will see the following
- Code: Select all
Shellscript exited with non-successful status code: 2
I guess this corresponds to the exit code 2 from MKVpropedit: "2 -- This exit code is used after an error occurred." Also see MKVpropedit documentation here
Side note 1: Of course I also tried to add the code from the (external) shell script directly into the Hazel rule. But I had the same problem with special characters as described above. I describe the case with an external script here, because the external cases proves that MKVpropedit can actually write special characters to a MKV movie file. It's not MKVpropedit. There seems to be a conversion problem when special characters are handed from Hazel to ZSH.
Side note 2: the shell script also generates a "debug" test file on the desktop. Strangly, the debug files displays the file name correctly (e.g. using the macOS built-in QuickView) in all combinations, Terminal or Hazel script start, with or without special characters.
Side note 3: I use the latest versions of Big Sur and Hazel.
Any help would be appreciated.
Thanks