AlexanderWillner / deepl-alfred-workflow2

DeepL Alfred Workflow
228 stars 8 forks source link

Script with argv '(null)' finished #29

Closed gmdelisle closed 6 months ago

gmdelisle commented 8 months ago

Hi! Thank you for this workflow. My problem. Fresh install. Only copied the DeepL API key. If I type "nein" just to test, nothing comes up. Same with all words. I get this error in the debugger.

Deepl-Translate[Script Filter] Queuing argument 'nein'
Deepl-Translate[Script Filter] Script with argv '(null)' finished

Thanks in advance.

Odaeus commented 8 months ago

Came here to report that I have the same error in the debugger except instead of nothing, it shows the word I entered back to me without translation.

AlexanderWillner commented 7 months ago
[13:43:41.581] Deepl-Translate[Script Filter] Queuing argument 'Nein.'
[13:43:41.936] Deepl-Translate[Script Filter] Script with argv '(null)' finished
[13:43:41.947] Deepl-Translate[Script Filter] {
  "items": [
    {
      "uid": null,
      "arg": "No",
      "valid": "yes",
      "autocomplete": "autocomplete",
      "title": "No"
    }
  ]
}
image
gmdelisle commented 7 months ago

Yes I have all that configured on the workflow's configuration complete with my Deepl Key.

SCR-20231203-lvek

If I add these values as Environment variables as well I get a warning from Alfred. SCR-20231203-lwaa

I tried erasing everything in the Configuration builder and use only Environment variables to no avail. Using Alfred 5.1.4, Alfred 5 workflow v1.11.

AlexanderWillner commented 7 months ago

Got it, workflow v1.9 was working, v1.11 is not...I've to check the underlying issue.

AlexanderWillner commented 7 months ago

Ok, I guess I found it.

  1. What if you press return?
  2. What if you use the keyword dl-to-en instead?
gmdelisle commented 7 months ago

Hi, I really appreciate the follow-up!

I'm sorry to report that I have the same issue. Still get the same Output, but now with added error about jq. Using Alfred 5.1.4, Alfred 5 workflow v1.13.

Deepl-Translate[Script Filter] Queuing argument 'nein' Deepl-Translate[Script Filter] Script with argv '(null)' finished ERROR: Deepl-Translate[Script Filter] Code 1: Binary 'jq' not found. Install it via 'brew install jq'.

Installed Homebrew and JQ just to be sure. Still the same.

AlexanderWillner commented 7 months ago

OK, then the issue is clear. Version 2.0.0 (just released) should fix this.

gmdelisle commented 7 months ago

High-five for a quick response! Wow. šŸ™

Same issue here. FYI not experiencing any other issues with other workflows.

This time getting a slightly different error.

[23:57:20.471] Deepl-Translate[Script Filter] Queuing argument 'nein.'
[23:57:21.040] Deepl-Translate[Script Filter] Script with argv '(null)' finished
[23:57:21.050] ERROR: Deepl-Translate[Script Filter] Code 1: execution error: Error: SyntaxError: JSON Parse error: Unexpected EOF (-2700)

Config is default. Have tried removing my DeelL API key to no avail. If ever there are steps you want me to try, let me know. image

Appreciate the help.

AlexanderWillner commented 7 months ago

Ok, let's find the issue:

  1. Go to Alfred settings > Workflows > Deepl-Translate > right click > Open in Terminal
  2. Run bash -x deepl.sh -l EN "nein."
  3. Copy and paste the output here
gmdelisle commented 7 months ago

Here you go! Hope this helps you see what the problem is.

+ LANGUAGE=EN
+ LANGUAGE_SOURCE=auto
+ LANGUAGE_PREFERRED='["DE","EN"]'
+ KEY=
+ PRO=
+ POSTFIX=.
+ VERSION=2.0
+ PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/bin/
+++ dirname deepl.sh
++ cd .
++ pwd
+ DIR='/Users/macos/Library/CloudStorage/Dropbox/PreĢfeĢrences Alfred/Alfred.alfredpreferences/workflows/user.workflow.8E688CE1-8565-45D9-944F-7C43DF4CD1E2'
+ POSITIONAL=()
+ [[ 3 -gt 0 ]]
+ key=-l
+ case "$key" in
+ LANGUAGE=EN
+ shift
+ shift
+ [[ 1 -gt 0 ]]
+ key=nein.
+ case "$key" in
+ POSITIONAL+=("$1")
+ shift
+ [[ 0 -gt 0 ]]
+ set -- nein.
+ '[' -z nein. ']'
+ query=nein.
++ echo nein.
++ sed 's/\"/\\\"/g'
+ query=nein.
++ echo nein.
++ sed 's/'\''/\\'\''/g'
+ query=nein.
++ echo nein.
++ iconv -f utf-8-mac -t utf-8
++ xargs
+ query=nein.
+ [[ '' = '' ]]
+ [[ nein. != *\. ]]
++ echo nein.
++ sed 's/\.$//'
+ query=nein
+ data='{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"nein","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["DE","EN"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"timestamp":1557063997314},"id":79120002}'
+ HEADER=(--compressed -H 'authority: www2.deepl.com' -H 'Origin: https://www.deepl.com' -H 'Referer: https://www.deepl.com/translator' -H 'Accept: */*' -H 'Content-Type: application/json' -H 'Accept-Language: en-us' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15')
+ '[' -n '' ']'
++ curl -s https://www2.deepl.com/jsonrpc --compressed -H 'authority: www2.deepl.com' -H 'Origin: https://www.deepl.com' -H 'Referer: https://www.deepl.com/translator' -H 'Accept: */*' -H 'Content-Type: application/json' -H 'Accept-Language: en-us' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15' --data-binary '{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"nein","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["DE","EN"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"timestamp":1557063997314},"id":79120002}'
+ result='{"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"nein","num_symbols":3}],"quality":"normal"}],"target_lang":"EN","source_lang":"EN","source_lang_is_confident":false,"detectedLanguages":{"EN":0.020787,"DE":0.040136,"FR":0.011696999999999999,"ES":0.01813,"PT":0.010837,"IT":0.011158,"NL":0.028071,"PL":0.011411,"RU":0.012218,"ZH":0.010069999999999999,"JA":0.011035999999999999,"BG":0.009132999999999999,"CS":0.020419,"DA":0.020047,"EL":0.008643,"ET":0.007956999999999999,"FI":0.026715,"HU":0.014846999999999999,"LT":0.014365,"LV":0.012298,"RO":0.016255,"SK":0.013446999999999999,"SL":0.015749,"SV":0.01452,"TR":0.008945999999999999,"ID":0.013646,"UK":0.01048,"KO":0.0'883,"NB":0.019434,"unsupported":0.5587179999999999}}}
+ [[ {"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"nein","num_symbols":3}],"quality":"normal"}],"target_lang":"EN","source_lang":"EN","source_lang_is_confident":false,"detectedLanguages":{"EN":0.020787,"DE":0.040136,"FR":0.011696999999999999,"ES":0.01813,"PT":0.010837,"IT":0.011158,"NL":0.028071,"PL":0.011411,"RU":0.012218,"ZH":0.010069999999999999,"JA":0.011035999999999999,"BG":0.009132999999999999,"CS":0.020419,"DA":0.020047,"EL":0.008643,"ET":0.007956999999999999,"FI":0.026715,"HU":0.014846999999999999,"LT":0.014365,"LV":0.012298,"RO":0.016255,"SK":0.013446999999999999,"SL":0.015749,"SV":0.01452,"TR":0.008945999999999999,"ID":0.013646,"UK":0.01048,"KO":0.00883, == *\"\e\r\r\o\r\"\:\{\"\c\o\d\e\"\:* ]]99999}}}
+ osascript -l JavaScript -e 'function run(argv) {
      const translations = JSON.parse(argv[0])["result"]["translations"][0]["beams"].map(item => ({
        title: item["postprocessed_sentence"],
        arg: item["postprocessed_sentence"]
      }))

      return JSON.stringify({ items: translations }, null, 2)
    }' '{"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"nein","num_symbols":3}],"quality":"normal"}],"target_lang":"EN","source_lang":"EN","source_lang_is_confident":false,"detectedLanguages":{"EN":0.020787,"DE":0.040136,"FR":0.011696999999999999,"ES":0.01813,"PT":0.010837,"IT":0.011158,"NL":0.028071,"PL":0.011411,"RU":0.012218,"ZH":0.010069999999999999,"JA":0.011035999999999999,"BG":0.009132999999999999,"CS":0.020419,"DA":0.020047,"EL":0.008643,"ET":0.007956999999999999,"FI":0.026715,"HU":0.014846999999999999,"LT":0.014365,"LV":0.012298,"RO":0.016255,"SK":0.013446999999999999,"SL":0.015749,"SV":0.01452,"TR":0.008945999999999999,"ID":0.013646,"UK":0.01048,"KO":0.008'3,"NB":0.019434,"unsupported":0.5587179999999999}}}
{
  "items": [
    {
      "title": "nein",
      "arg": "nein"
    }
  ]
}
AlexanderWillner commented 7 months ago
gmdelisle commented 7 months ago

Yep, I have tried translating "Ich spiele gerne Musik."

Here is the output. I do see the translation in the output below, however is does not work with Alfred directly. image

+ LANGUAGE=EN
+ LANGUAGE_SOURCE=auto
+ LANGUAGE_PREFERRED='["DE","EN"]'
+ KEY=
+ PRO=
+ POSTFIX=.
+ VERSION=2.0
+ PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/bin/
+++ dirname deepl.sh
++ cd .
++ pwd
+ DIR='/Users/macos/Library/CloudStorage/Dropbox/PreĢfeĢrences Alfred/Alfred.alfredpreferences/workflows/user.workflow.8E688CE1-8565-45D9-944F-7C43DF4CD1E2'
+ POSITIONAL=()
+ [[ 3 -gt 0 ]]
+ key=-l
+ case "$key" in
+ LANGUAGE=EN
+ shift
+ shift
+ [[ 1 -gt 0 ]]
+ key='Ich spiele gerne Musik.'
+ case "$key" in
+ POSITIONAL+=("$1")
+ shift
+ [[ 0 -gt 0 ]]
+ set -- 'Ich spiele gerne Musik.'
+ '[' -z 'Ich spiele gerne Musik.' ']'
+ query='Ich spiele gerne Musik.'
++ echo 'Ich spiele gerne Musik.'
++ sed 's/\"/\\\"/g'
+ query='Ich spiele gerne Musik.'
++ echo 'Ich spiele gerne Musik.'
++ sed 's/'\''/\\'\''/g'
+ query='Ich spiele gerne Musik.'
++ echo 'Ich spiele gerne Musik.'
++ iconv -f utf-8-mac -t utf-8
++ xargs
+ query='Ich spiele gerne Musik.'
+ [[ '' = '' ]]
+ [[ Ich spiele gerne Musik. != *\. ]]
++ echo 'Ich spiele gerne Musik.'
++ sed 's/\.$//'
+ query='Ich spiele gerne Musik'
+ data='{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"Ich spiele gerne Musik","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["DE","EN"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"timestamp":1557063997314},"id":79120002}'
+ HEADER=(--compressed -H 'authority: www2.deepl.com' -H 'Origin: https://www.deepl.com' -H 'Referer: https://www.deepl.com/translator' -H 'Accept: */*' -H 'Content-Type: application/json' -H 'Accept-Language: en-us' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15')
+ '[' -n '' ']'
++ curl -s https://www2.deepl.com/jsonrpc --compressed -H 'authority: www2.deepl.com' -H 'Origin: https://www.deepl.com' -H 'Referer: https://www.deepl.com/translator' -H 'Accept: */*' -H 'Content-Type: application/json' -H 'Accept-Language: en-us' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Safari/605.1.15' --data-binary '{"jsonrpc":"2.0","method": "LMT_handle_jobs","params":{"jobs":[{"kind":"default","raw_en_sentence":"Ich spiele gerne Musik","preferred_num_beams":4,"raw_en_context_before":[],"raw_en_context_after":[],"quality":"fast"}],"lang":{"user_preferred_langs":["DE","EN"],"source_lang_user_selected":"auto","target_lang":"EN"},"priority":-1,"timestamp":1557063997314},"id":79120002}'
+ result='{"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"I like to play music","num_symbols":6},{"postprocessed_sentence":"I like playing music","num_symbols":5},{"postprocessed_sentence":"I enjoy playing music","num_symbols":5},{"postprocessed_sentence":"I love playing music","num_symbols":5}],"quality":"normal"}],"target_lang":"EN","source_lang":"DE","source_lang_is_confident":false,"detectedLanguages":{"EN":0.00035299999999999996,"DE":0.9164049999999999,"FR":0.000056999999999999999,"PT":0.000014999999999999999,"IT":0.00037999999999999997,"NL":0.0075899999999999999,"PL":0.002718,"CS":0.000129,"DA":0.021681,"ET":0.000147,"FI":0.000018999999999999999,"LT":0.000009999999999999999,"RO":0.00018999999999999998,"SK":0.00098,"SL":0.000024999999999999999,"SV":0.0011669999999999999,"TR":0.000165,"ID":0.000032999999999999999,"NB":'.005026,"unsupported":0.042893999999999998}}}
+ [[ {"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"I like to play music","num_symbols":6},{"postprocessed_sentence":"I like playing music","num_symbols":5},{"postprocessed_sentence":"I enjoy playing music","num_symbols":5},{"postprocessed_sentence":"I love playing music","num_symbols":5}],"quality":"normal"}],"target_lang":"EN","source_lang":"DE","source_lang_is_confident":false,"detectedLanguages":{"EN":0.00035299999999999996,"DE":0.9164049999999999,"FR":0.000056999999999999999,"PT":0.000014999999999999999,"IT":0.00037999999999999997,"NL":0.0075899999999999999,"PL":0.002718,"CS":0.000129,"DA":0.021681,"ET":0.000147,"FI":0.000018999999999999999,"LT":0.000009999999999999999,"RO":0.00018999999999999998,"SK":0.00098,"SL":0.000024999999999999999,"SV":0.0011669999999999999,"TR":0.000165,"ID":0.000032999999999999999,"NB":0.005 == *\"\e\r\r\o\r\"\:\{\"\c\o\d\e\"\:* ]]
+ osascript -l JavaScript -e 'function run(argv) {
      const translations = JSON.parse(argv[0])["result"]["translations"][0]["beams"].map(item => ({
        title: item["postprocessed_sentence"],
        arg: item["postprocessed_sentence"]
      }))

      return JSON.stringify({ items: translations }, null, 2)
    }' '{"jsonrpc":"2.0","id":79120002,"result":{"translations":[{"beams":[{"postprocessed_sentence":"I like to play music","num_symbols":6},{"postprocessed_sentence":"I like playing music","num_symbols":5},{"postprocessed_sentence":"I enjoy playing music","num_symbols":5},{"postprocessed_sentence":"I love playing music","num_symbols":5}],"quality":"normal"}],"target_lang":"EN","source_lang":"DE","source_lang_is_confident":false,"detectedLanguages":{"EN":0.00035299999999999996,"DE":0.9164049999999999,"FR":0.000056999999999999999,"PT":0.000014999999999999999,"IT":0.00037999999999999997,"NL":0.0075899999999999999,"PL":0.002718,"CS":0.000129,"DA":0.021681,"ET":0.000147,"FI":0.000018999999999999999,"LT":0.000009999999999999999,"RO":0.00018999999999999998,"SK":0.00098,"SL":0.000024999999999999999,"SV":0.0011669999999999999,"TR":0.000165,"ID":0.000032999999999999999,"NB":0.'05026,"unsupported":0.042893999999999998}}}
{
  "items": [
    {
      "title": "I like to play music",
      "arg": "I like to play music"
    },
    {
      "title": "I like playing music",
      "arg": "I like playing music"
    },
    {
      "title": "I enjoy playing music",
      "arg": "I enjoy playing music"
    },
    {
      "title": "I love playing music",
      "arg": "I love playing music"
    }
  ]
}
gmdelisle commented 7 months ago

Just wanted to add that I have 2 Macs.

AlexanderWillner commented 7 months ago
gmdelisle commented 7 months ago

Sure thing, but I've tried it on my Mac I couldn't find deepl.sh.

I do see this file exists in your source code, but I just installed the workflow directly. How would I replace this bash script on my Mac?

AlexanderWillner commented 7 months ago
gmdelisle commented 7 months ago

Yes it's spitting out a bit more info but not much as far as I can judge. Hope this helps!

[11:33:23.052] Logging Started...
[11:33:26.723] Deepl-Translate[Script Filter] Queuing argument 'Ich mag Klassik'
[11:33:28.318] Deepl-Translate[Script Filter] Script with argv '(null)' finished
[11:33:28.324] STDERR: Deepl-Translate[Script Filter] execution error: Error: SyntaxError: JSON Parse error: Unexpected EOF (-2700)
ERROR: Input ''
AlexanderWillner commented 6 months ago

Mh, getting closer, still not sure why it's not working for you. I created a version 2.0.2 with even more debugging information. Would you mind updating it or replace the deepl.sh file with https://raw.githubusercontent.com/AlexanderWillner/deepl-alfred-workflow2/master/deepl.sh ?

gmdelisle commented 6 months ago

Hi!

Thanks for the update. There is a lot more information this time around.

This script shows my Deepl API key, so I've replaced it with below as to not paste it here in Github.

[01:22:47.400] Logging Started...
[01:22:51.421] Deepl-Translate[Script Filter] Queuing argument 'nein'
[01:22:52.204] Deepl-Translate[Script Filter] Script with argv '(null)' finished
[01:22:52.210] STDERR: Deepl-Translate[Script Filter] curl -s -X POST 'https://api-free.deepl.com/v2/translate' -H 'Authorization: DeepL-Auth-Key <keyid>' -d 'text=nein' -d 'target_lang=en'

execution error: Error: SyntaxError: JSON Parse error: Unexpected EOF (-2700)
ERROR w/ key: result '', query 'nein'
AlexanderWillner commented 6 months ago
gmdelisle commented 6 months ago

Hey I can confirm this is fixed! Indeed it does seem like the API key was the issue. It seems like DeepL was making changes to their API's SLA in the past weeks. When I logged in today, my API key had disappeared from my account and I had to register for a new one with a new workflow.

New API key works now.

šŸ™ Many thanks for the help.