Page 1 of 1

Create Menu Entry for Application designed to Run in Console (Solved)

Posted: Wed Jan 22, 2025 11:05 pm
by mikeslr

Edit: the title has been changed from "Create Menu Entry for Application designed to Run in Console" to reflect the actual solution. Edit: Changed back to original title per objection by MochiMoppel who also provided solution to origimal request, viewtopic.php?p=141111#p141111. While what I wanted was solved in a different manner, being able to initiate a terminal with arguments is, itself, very useful. Recipes for doing that will be easier to find under the original title.

Desiring a simple password generator, I found this post, https://itsfoss.com/password-generators-linux/. AFAICT, Revelation is no longer supported; and as it says "Now in Keepassx, there is no easy way to get to the password generator." The others all expect to be run via a terminal. Both Diceware and xkcdpass at least allow me to first open Lxterminal so that i can copy the 'passphrase' generated befor closing the terminal. But pwgen uses some terminal which doesn't enable copying its contents.

I also found a nice 'one-liner' using urandom I can run under lxterminal (or any terminal):

for i in $(seq 1 10); do echo $(tr -dc 'A-Za-z0-9!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~' < /dev/urandom | head -c 16); done

Changing the argument following -c determines the length of the password.
I use lxterminal because, like geany, there are menu entries for 'cutting and pasteing'. My mind understand's 'Middle-Click'; but my fingers do not. :cry: Maybe I'm using in wrong, but Middle-Click under urxvt enables me to copy selected content into urxvt itself, but no where else.

I am of an age where 'out-of-sight'='doesn't exist', and as I've written many times, I have the memory of a sieve. So I wanted to create an applications with a menu entry which would open lxterminal and have it call any of the following: the above script, diceware or xkcdpass. I usually don't have problems writing simple scripts to call applications; nor providing the argument in a /usr/share/...desktop's Exec= line to initiate a script or start an application. But how do you write either (a) a script which will first open Lxterminal and have it run a script; or (b) have the Exec line open Lxterminal and open another application or script? AND KEEP IT OPEN? Some of my efforts resulted in something momentarily on display, then closing too soon to figure out what.
IIRC, having the desktop's Terminal= argument be true either didn't work at all, or opened in Urxvt but closed immediately.
Or alternatively, how to pass the output of the passwords/passphrase generated to a text file?


Re: Create Menu Entry for Application designed to Run in Consol

Posted: Wed Jan 22, 2025 11:39 pm
by d-pupp

IRC, having the desktop's Terminal= argument be true either didn't work at all, or opened in Urxvt but closed immediately.

Try adding

Code: Select all

read -p "Press any key to continue"

to the end of your script. It maybe crude but it works.


Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 12:46 am
by mikeslr

Let me "simplify" the request since I will need to use lxterminal. What /usr/share/Applications...desktop arguments &/or bash-script(s) will I need to start lxterminal via a menu entry and have it run this command:

for i in $(seq 1 10); do echo $(tr -dc 'A-Za-z0-9!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~' < /dev/urandom | head -c 16); done

___
FWIW, RIght-Clicking a bash-script with that command and selecting Run-in-terminal opens in urxvt and remains opened until Enter/Return is pressed; but won't let me copy any or all of the 10 passwords displayed.

Examination of diceware and xkcdpass reveals they are applications build upon python. So I guess to create a menu entry the executable would have to be python something. [Way beyond my paygrade].


Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 12:58 am
by Trapster

Is urxvt in /usr/local/bin/defaultterminal? If so, can you change it to lxterminal?

another option (probably not the correct way):
rename urxvt to urxvt-orig and symkink lxterminal to urxvt.


Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 1:30 am
by wizard

@mikeslr

Perhaps this might help. When using URXVT terminal:

copy = highlight (highlighting any text automatically copies it to the clipboard)
paste = ctrl alt v or middle mouse button

wizard


Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 1:36 am
by MochiMoppel
mikeslr wrote: Thu Jan 23, 2025 12:46 am

Let me "simplify" the request since I will need to use lxterminal.

Let me further simplify your request because methinks you don't "need" lxterminal. In fact you don't need any terminal.
All you are asking for is to have the resulting passwords display so that you can copy them, right?
So why no use good old leafpad instead of a terminal?

Code: Select all

#! /bin/sh
for i in $(seq 1 10); do echo $(tr -dc 'A-Za-z0-9!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~' < /dev/urandom | head -c 16); done | leafpad

Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 1:37 am
by williams2

Code: Select all

for i in $(seq 1 10); do echo $(tr -dc 'A-Za-z0-9!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~' < /dev/urandom | head -c 16); done > /tmp/passwords.txt
geany /tmp/passwords.txt

Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 1:45 am
by Trapster

For future ref to open script in lxterminal

Put your script in an exectable file, ie /usr/local/bin/random-passwords:

Code: Select all

#!/bin/bash

for i in $(seq 1 10); do echo $(tr -dc 'A-Za-z0-9!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~' < /dev/urandom | head -c 16) ;done

Create another executable file in /usr/local/bin/run-passwords:

Code: Select all

#!/bin/bash

lxterminal --command="/bin/bash -c '/usr/local/bin/random-passwords; read'"

Clicking on the file "run-passwords" should now open lxterminal with your random passwords


Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 3:21 am
by williwaw
mikeslr wrote: Wed Jan 22, 2025 11:05 pm

(a) a script which will first open Lxterminal and have it run a script; or (b) have the Exec line open Lxterminal and open another application or script? AND KEEP IT OPEN?

Code: Select all

#!/bin/sh
urxvt -hold -e myscript

https://passwords-generator.org/
is a nice html password generator that you can save to disk and will work offline. It has some useful filters


Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 5:26 am
by Geek3579

I use the following in a keybinding situation to run a script but it can work elsewhere (in the case below, the script is on the Desktop)
lxterminal --working-directory=/root/Desktop ./yourscript


Re: Create Menu Entry for Application designed to Run in Consol

Posted: Thu Jan 23, 2025 5:32 pm
by mikeslr

Thanks, guys. Lots of choices. :D Will try them out.

Thanks, wizard. "Perhaps this might help. When using URXVT terminal:
copy = highlight (highlighting any text automatically copies it to the clipboard) [Emphasis supplied].
paste = ctrl alt v or middle mouse button.
Thought I had to do a ctr-c to copy to the clip-board. :oops: Which is why it didn't work. :roll:

Thanks, MochiMoppel and williams2 for providing the "| leafpad" and "> /tmp/passwords.txt" alternative concluding arguments. Nice, efficient ways to export the product without further manual effort.

Thanks, Trapster, for "lxterminal --command="/bin/bash -c '/usr/local/bin/random-passwords; read'" " showing how to use lxterminal's command argument. Somethinkg like that was what I had in mind but didn't know 'the grammar'.

And thanks, williwaw, for the link to the on-line password and passphrase generator.

MochiMoppel's solution worked. But I decided to go with a slight variation to williams2's solution. I liked that it wrote the text file to /tmp as that folder is not preserved accross reboots or the execution of a Save. I changed 'geany' to 'defaulttexteditor'. As geany is my defaulttexteditor the result is the same; but the script is more 'universal' and will open the file in whatever texteditor the User chose as default. So the script now reads:

Code: Select all

for i in $(seq 1 10); do echo $(tr -dc 'A-Za-z0-9!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~' < /dev/urandom | head -c 16); done > /tmp/passwords.txt
defaulttexteditor /tmp/passwords.txt

To share your work with others I've published a pet, viewtopic.php?p=141089#p141089.


Re: Create Menu Entry for Application designed to Run in Console

Posted: Fri Jan 24, 2025 2:17 am
by MochiMoppel
mikeslr wrote: Wed Jan 22, 2025 11:05 pm

But how do you write either (a) a script which will first open Lxterminal and have it run a script; or (b) have the Exec line open Lxterminal and open another application or script? AND KEEP IT OPEN?

OK, back to your original question. Let's try a truly simple but slightly crazy solution: A single .desktop file, nothing else :o
You never mentioned the Puppy you are using, so this works in BookwormPup64:
Give the following .desktop file a name, e.g. pg.desktop, and copy it to /usr/share/applications. That's it!
BW64 will automatically add it to the menu in the "Personal" category. In other Puppies you may have to run the usual fixmenus; jwm -reload in a console.

As you can see it is possible to add a complete script after Exec: , without running an external file or application. The icon is "borrowed" from the installed Figaro's password manager.
I also made the code simpler, mainly to avoid escaping "problematic" characters. The lxterminal will stay open and can be used normally, accepting more shell commands.

Code: Select all

[Desktop Entry]
Name=Poor man's password generator
Comment=Create 16 digit passwords
Icon=fpm2
Exec=lxterminal -t lxterminal -e 'for i in $(seq 1 10); do cat /dev/urandom | tr -dc [[:graph:]] | head -c 16 ; echo ; done ; sh'
Type=Application
Categories=X-Personal