Jump to content

Bug using 1password cli


Recommended Posts

Hi I am using a very basic workflow to get 3 variables from keyboard input, after that I execute an script that has a way of how to create a new entry on 1password, but for some reason Alfred is showing errors on the execution with the debugging, but the error is not related to the execution of the script but with something Alfred is trying to do.

 

This is the last step

query=$1

echo -n $query
. $HOME/.zprofile
1p-create -u {var:USER} -p {var:URL} -t {var:TITLE} -v Private

 

Variables are taken by a keyword input asigning a variable the result

 

The run script is with zsh with input as argue sequentially

 

This is the error

 

[13:33:05.891] 1Password tools[Keyword] Processing complete
[13:33:05.899] 1Password tools[Keyword] Passing output '' to Keyword
[13:33:06.472] 1Password tools[Keyword] Processing complete
[13:33:06.476] 1Password tools[Keyword] Passing output 'asdf' to Arg and Vars
[13:33:06.477] 1Password tools[Arg and Vars] Processing complete
[13:33:06.478] 1Password tools[Arg and Vars] Passing output '' to Keyword
[13:33:06.771] 1Password tools[Keyword] Processing complete
[13:33:06.782] 1Password tools[Keyword] Passing output 'adsf' to Arg and Vars
[13:33:06.784] 1Password tools[Arg and Vars] Processing complete
[13:33:06.785] 1Password tools[Arg and Vars] Passing output '' to Keyword
[13:33:07.091] 1Password tools[Keyword] Processing complete
[13:33:07.096] 1Password tools[Keyword] Passing output 'adsf' to Arg and Vars
[13:33:07.097] 1Password tools[Arg and Vars] Processing complete
[13:33:07.098] 1Password tools[Arg and Vars] Passing output '' to Run Script
[13:33:11.022] ERROR: 1Password tools[Run Script] [ERROR] 2024/05/09 13:33:10 invalid JSON in piped input   ===> THIS IS THE ERROR
[13:33:11.026] 1Password tools[Run Script] Processing complete
[13:33:11.028] 1Password tools[Run Script] Passing output '' to Post Notification

 

 

This is the content of the script for 1password

 

$ cat 1p-create.sh

#!/bin/bash

 

mostrar_ayuda() {

    echo "Uso: $0 -u <USER> -v <VAULT> -p <PAGE> -t <TITLE> -o <ATTRIBUTES>"

    echo

    echo "Opciones:"

    echo "  -u <URL>: Especifica la URL"

    echo "  -v <URL>: Especifica el VAULT"

    echo "  -p <PAGE>: Especifica la PAGINA"

    echo "  -t <TITLE>: Especifica la TITULO"

    echo "  -o <OTHER>: Especifica OTROS ATRIBUTOS"

    exit 1

}

 

while getopts ":t:u:v:p:o:" opt; do

  case $opt in

    u) user="$OPTARG";;

    p) page="$OPTARG";;

    t) title="$OPTARG";;

    v) vault="$OPTARG";;

    o) atributos=" $OPTARG";;

    \?) echo "Opcion invalida: -$OPTARG" >&2

        mostrar_ayuda;;

    :)  echo "Opcion -$OPTARG requiere un argumento." >&2

        mostrar_ayuda;;

  esac

done

 

op item create --category=login --title="${title}" --vault="${vault}" --url="${page}" --generate-password=20,letters,digits  "username=${user}${atributos}"

#echo op item create --category=login --title="${title}" --vault="${vault}" --url="${page}" --generate-password=20,letters,digits  "username=${user}${atributos}"

 

Captura de pantalla 2024-05-09 a la(s) 1.42.42 p.m..jpg

Link to comment
  • What you were doing when the issue happened
    The workflow specified 
     
  • Whether you were able to replicate it
    Yes I am.
     
  • Include any screenshots that might help us
    Above
  • Include the version and build number from Alfred's General preferences (Don't say "latest", please be specific)
    5.5[2257]
  • Include the version and build number from macOS and any apps that are relevant to the issue you're seeing

 macOS 14.4.1 (23E224) MacBook M1 serie L1P99JD66D

Link to comment

The "invalid JSON in piped input" error isn't coming from Alfred, this is the error output from running the script.

 

Is your script running as expected when you run it from outside of Alfred? Also, perhaps put a debug object before the Run Script to ensure that all the variables are correctly set.

 

[Moving to Workflow Help as you'll get more eyes on your topic there]

Link to comment
14 hours ago, luartx said:

1p-create -u {var:USER} -p {var:URL} -t {var:TITLE} -v Private

 

{var:} doesn’t expand inside a script, you have to use the rules of the language. In this case "${url}", "${title}", so forth. Note the quotes. Always quote variables inside shell scripts unless you have a strong reason to not do it (which will happen very rarely and only on specialised cases). This is true even when running scripts outside of Alfred.


Additionally, avoid USER because that’s an environment variable set by the system which maps to the account name on your Mac. Overwriting it could have adverse unpredictable consequences on that script’s run. This also applies to running scripts no matter the environment.

 

Finally, the screenshot shows the script isn’t being found. You have to make it accessible in a place Alfred sees.

Link to comment

Hi, the file is there and is executed OK. I test it even with just the script without any parameter and the error is from Alfred.

 

Check this. This is the script without any parameters on the home user, I don't even use any json or python. This is the output directly on terminal.

$ sh -xv test.sh

op item create --category=login --title=test --vault=Private --url=test --generate-password=20,letters,digits username=test

+ op item create --category=login --title=test --vault=Private --url=test --generate-password=20,letters,digits username=test

ID:          hjqz7yapsb6jttbo6z6dusuafa

Title:       test

Vault:       Private (2m6e3inp663d7cbt6p5u4idxoa)

Created:     now

Updated:     now

Favorite:    false

Version:     1

Category:    LOGIN

Fields:

  username:    test

  password:    e3dnCG6YUFGXzKTk3Uz3

URLs:

:    test (primary)
 

This is the debug on alfred and the screenshot of how I am placing the run script, is just the script without anything else. I don't use json anywhere. If I use terminal in the workflow, it works. tell me if you need a zoom to see it directly. I have experience working on scripting and Alfred, this is not normal behavior.


[13:33:11.026] 1Password tools[Run Script] Processing complete
[13:33:11.028] 1Password tools[Run Script] Passing output '' to Post Notification
[13:30:08.649] 1Password tools[Keyword] Processing complete
[13:30:08.662] 1Password tools[Keyword] Passing output '' to Keyword
[13:30:09.574] 1Password tools[Keyword] Processing complete
[13:30:09.589] 1Password tools[Keyword] Passing output 'adsf' to Arg and Vars
[13:30:09.591] 1Password tools[Arg and Vars] Processing complete
[13:30:09.593] 1Password tools[Arg and Vars] Passing output '' to Keyword
[13:30:09.883] 1Password tools[Keyword] Processing complete
[13:30:09.892] 1Password tools[Keyword] Passing output 'adf' to Arg and Vars
[13:30:09.893] 1Password tools[Arg and Vars] Processing complete
[13:30:09.894] 1Password tools[Arg and Vars] Passing output '' to Keyword
[13:30:10.316] 1Password tools[Keyword] Processing complete
[13:30:10.319] 1Password tools[Keyword] Passing output 'adsf' to Arg and Vars
[13:30:10.321] 1Password tools[Arg and Vars] Processing complete
[13:30:10.322] 1Password tools[Arg and Vars] Passing output '' to Run Script
[13:30:13.722] ERROR: 1Password tools[Run Script] [ERROR] 2024/05/10 13:30:13 invalid JSON in piped input
[13:30:13.735] 1Password tools[Run Script] Processing complete
[13:30:13.737] 1Password tools[Run Script] Passing output '' to Post Notification

 


Thanks for your help.

 

 

Captura de pantalla 2024-05-09 a la(s) 1.42.42 p.m..jpg

Link to comment

I have changed all my variable to 1PUSER, 1PURL, 1PTITLE but is the same behavior even if I don't use them, as is on the screenshot.

 

This is what I have in my run script /Users/lsdjfnekhjsmnfkg/test.sh without using the script

Link to comment

you know what, I changed the script to other and is very specific with the execution of 1password cli. I don't know why is showing that message through Alfred and directly on terminal is not showing any error. I have to talk with someone of 1password cli I think to know why is not letting execute oc from Alfred. Thanks.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...