Special characters, locales, ENV variable and API calls!

I use macOS BigSur, latest update
If I execute the following two commands in macOS Terminal, I get the desired results.
Note, the commands are looking for the first air date of an episode from the TV show "Tatort"
- first command: Episode name: "Kehraus" --> Result: 2022-02-27
- second command: Episode name: "Saras Geständnis" --> Result: 2022-02-13
Also note, that the name of the second epsiode contains a German special character.
The commands use CURL and JQ, a JSON processor. As mentioned, in macOS Terminal both commands work fine.
If I put the same command in an "Embedded Shell Script" in Hazel and I trigger the scripts with two different files ("Kehraus.mp4" and "Saras Geständnis.mp4"), I only get a result for the first file, the file that does not contain a special character.
The text file _result.txt will contain "2022-02-27" for the file "Kehraus.mp4", but it will be empty for the file "Saras Geständnis.mp4".
In the Hazel log i can't find anything specific about the API calls, but I can see this with a strangely encoded file name.
But I also see this with a correctly encoded file name.
So, the log information sometimes writes the file name correctly, and sometimes with encoded special characters.
Executing the command "locale" in the macOS terminal shows this:
Executing the command "locale" in the Hazel shell environment:
_locale.txt will then show the following
I tried to define the same environment variable as in the macOS Terminal before the script commands
Or I even tried to set the environment variable to German
But it didn't solve the problem. I still don't get a response from the API when the file name contains a special character.
What am I supposed to do so that Hazel sends the correctly encoded values to the API so I get the same results as in macOS Terminal?
Your feedback would be appreciated.
Thanks
AJ
If I execute the following two commands in macOS Terminal, I get the desired results.
Note, the commands are looking for the first air date of an episode from the TV show "Tatort"
- first command: Episode name: "Kehraus" --> Result: 2022-02-27
- second command: Episode name: "Saras Geständnis" --> Result: 2022-02-13
Also note, that the name of the second epsiode contains a German special character.
- Code: Select all
curl -L -G https://api.tvmaze.com/shows/6446/episodes | jq --raw-output --arg strSearch "Kehraus" '.[] | select(.name | test([ $strSearch ])) | [.airdate]'
curl -L -G https://api.tvmaze.com/shows/6446/episodes | jq --raw-output --arg strSearch "Saras Geständnis" '.[] | select(.name | test([ $strSearch ])) | [.airdate]'
The commands use CURL and JQ, a JSON processor. As mentioned, in macOS Terminal both commands work fine.
If I put the same command in an "Embedded Shell Script" in Hazel and I trigger the scripts with two different files ("Kehraus.mp4" and "Saras Geständnis.mp4"), I only get a result for the first file, the file that does not contain a special character.
- Code: Select all
sourceIn="$1" # path and filename/extension of source file
fileIn="$(basename -- $sourceIn)" # filename/extension of source file
fileNameIn="${fileIn%.*}" # filename of source file
tvMazeResult=$(curl -L -G https://api.tvmaze.com/shows/6446/episodes | jq --raw-output --arg strSearch $fileNameIn '.[] | select(.name | test([ $strSearch ])) | [.airdate]')
printf "$tvMazeResult ___ \n" > ~/Desktop/_result.txt
The text file _result.txt will contain "2022-02-27" for the file "Kehraus.mp4", but it will be empty for the file "Saras Geständnis.mp4".
In the Hazel log i can't find anything specific about the API calls, but I can see this with a strangely encoded file name.
- Code: Select all
2022-09-14 21:06:36.148 86Z3GCJ4MF.com.noodlesoft.HazelHelper[617] DEBUG: Thread 0x7fc532b04370: Received events (
{
date = "2022-09-14 19:06:36 +0000";
path = "/Users/...../Desktop/MediaBox/Renaming/Saras Gesta\U0308ndnis.mp4";
shouldDoFullScan = 0;
}
) for stream at path: /Users/...../Desktop/MediaBox/Renaming
But I also see this with a correctly encoded file name.
- Code: Select all
2022-09-14 21:06:36.149 86Z3GCJ4MF.com.noodlesoft.HazelHelper[617] DEBUG: Error resolving symlinks for path /Users/...../Desktop/MediaBox/Renaming/Saras Geständnis.mp4:, No such file or directory
So, the log information sometimes writes the file name correctly, and sometimes with encoded special characters.
Executing the command "locale" in the macOS terminal shows this:
- Code: Select all
LANG=""
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
Executing the command "locale" in the Hazel shell environment:
- Code: Select all
foo=$(locale)
printf "$foo" > ~/Desktop/_locale.txt
_locale.txt will then show the following
- Code: Select all
LANG=""
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL="C"
I tried to define the same environment variable as in the macOS Terminal before the script commands
- Code: Select all
export LANG="C"
export LC_COLLATE="C"
export LC_CTYPE="UTF-8"
export LC_MESSAGES="C"
export LC_MONETARY="C"
export LC_NUMERIC="C"
export LC_TIME="C"
export LC_ALL=""
sourceIn="$1" # path and filename/extension of source file
fileIn="$(basename -- $sourceIn)" # filename/extension of source file
fileNameIn="${fileIn%.*}" # filename of source file
tvMazeResult=$(curl -L -G https://api.tvmaze.com/shows/6446/episodes | jq --raw-output --arg strSearch $fileNameIn '.[] | select(.name | test([ $strSearch ])) | [.airdate]')
printf "$tvMazeResult ___ \n" > ~/Desktop/_result.txt
Or I even tried to set the environment variable to German
- Code: Select all
export LANG="de_DE.UTF-8"
export LC_COLLATE="de_DE.UTF-8"
export LC_CTYPE="de_DE.UTF-8"
export LC_MESSAGES="de_DE.UTF-8"
export LC_MONETARY="de_DE.UTF-8"
export LC_NUMERIC="de_DE.UTF-8"
export LC_TIME="de_DE.UTF-8"
sourceIn="$1" # path and filename/extension of source file
fileIn="$(basename -- $sourceIn)" # filename/extension of source file
fileNameIn="${fileIn%.*}" # filename of source file
tvMazeResult=$(curl -L -G https://api.tvmaze.com/shows/6446/episodes | jq --raw-output --arg strSearch $fileNameIn '.[] | select(.name | test([ $strSearch ])) | [.airdate]')
printf "$tvMazeResult ___ \n" > ~/Desktop/_result.txt
But it didn't solve the problem. I still don't get a response from the API when the file name contains a special character.
What am I supposed to do so that Hazel sends the correctly encoded values to the API so I get the same results as in macOS Terminal?
Your feedback would be appreciated.
Thanks
AJ