0

I made a small bash-script. it works fine so far on Windows WSL and Linux.

Now i would like a to have a graphical pop-up window to let the user choose from a list of settings. I learned you can do that with VBS, which i know none about. Is it possible to return the choice to my bash script? How does the .vbs have to look like?

Or maybe there is a simpler way to do this?

My Script opens some files and I would like to let the user choose their editor for this.

for example sublime and vim on linux. or notepad++ and sublime on windows.

I would like to avoid having the windows user have to install all the x11-libraries, thats why i dont want to do it with zenity, which i will use for linux. And the first thing i found about it was a .vbs script on windows.

0

If you want a graphical UI within the Linux environment, you'll need X11 for sure. But if you just want to interface with a Windows GUI, then yes, you can do that. Basically, it is now possible to run Windows tools from WSL. This means that if you have a Windows script that you can run, for example, from CMD or WScript, you can just do:

cmd.exe /c "path to script"
vbscript.exe /b "path to script"  :: where /b = batch mode

Then comes the return value part. In bash, $? is always the exit status of the previous command. So once you run the above line and it closes and returns1, then you can use $? to figure out what the script returned. (This is abusing exit statuses a little bit, but if it works...)2 This of course means that you will need a unique int for every possible return value of your Windows script, and both scripts will need to know what each value corresponds to.

(Writing the script to present the GUI is a whole other issue, of course, but you can ask about that on Super User.)

1 This part is really important - you can test it yourself by running explorer.exe right after a command that raised an error. If you don't close the Explorer window that bash opened, $? will show the non-zero exit status of the command before explorer.exe, but once you close Explorer, $? will be 0 (assuming nothing went wrong with Explorer).

2 Caveat: I haven't actually tried this process myself. Some tweaking may be required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.