Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use the config variable when running the script using i3-msg -q exec myscript #470

Closed
shivankgarg98 opened this issue Apr 11, 2023 · 4 comments

Comments

@shivankgarg98
Copy link

I have created an easy-to-take screenshot script (https://github.com/shivankgarg98/i3blocks-contrib/tree/master/screenshot) which saves the screenshot in clipboard and also pop a notifcation using dunst to allow user to save in a file (when clicked on notification).
As noted in #354, there will be a problem until current instance of dunstify (notification) is closed. To overcome this, I'm using command=i3-msg -q exec myscript. It solve my problem but it's not reading the variable set in config (like IS_SAVE=true or SAVE_DIR=).
Is this expected? how to overcome this.

@gportay
Copy link
Contributor

gportay commented Apr 12, 2023

I am no expert, but I do think i3-msg spawns a new process from a different process.

As a consequence, the environment is different and you have no access to the variables specified my i3blocks and your config. I guess your process is spawned by i3 thanks to i3-msg, but not spawned by i3blocks.

If this is true, you should update your script to pass arguments via the command line i3-msg exec "/path/to/script arg1 arg2...".

Or maybe, a simpler solution i3-msg exec "VAR1=$VAR1 VAR2=$VAR2 /path/to/script" if this works.

However, this is a workaround to solve your issue. But I think the clean solution is certainly elsewhere.

@shivankgarg98
Copy link
Author

shivankgarg98 commented Apr 12, 2023

It makes sense I think.
The workaround solved the issue. I'm able to set the desired variable and even the $BLOCK_BUTTON input from mouse.
Not elegant but works
Thanks :)

@gportay
Copy link
Contributor

gportay commented Apr 12, 2023

Could you post here the solution that has solved your issue described above; to satisfy my curiosity and for the users that would read this later.

Also, you may close the issue, unless you have something else to add or ask

@shivankgarg98
Copy link
Author

[screenshot]
command=i3-msg -q exec -- SAVE_DIR="/path/to/dir/screenshots" IS_SAVE="true" BLOCK_BUTTON="$BLOCK_BUTTON" /path/to/script/screenshot/screenshot

for more details and usecase, please refer to:
https://github.com/shivankgarg98/i3blocks-contrib/blob/master/screenshot/README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants