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

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
mikeslr
Posts: 3015
Joined: Mon Jul 13, 2020 11:08 pm
Has thanked: 174 times
Been thanked: 952 times

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

Post 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?

Last edited by mikeslr on Fri Jan 24, 2025 3:36 pm, edited 5 times in total.
d-pupp
Posts: 394
Joined: Tue Nov 22, 2022 9:11 pm
Location: Canada
Has thanked: 232 times
Been thanked: 69 times

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

Post 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.

User avatar
mikeslr
Posts: 3015
Joined: Mon Jul 13, 2020 11:08 pm
Has thanked: 174 times
Been thanked: 952 times

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

Post 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].

Last edited by mikeslr on Thu Jan 23, 2025 1:02 am, edited 1 time in total.
User avatar
Trapster
Posts: 201
Joined: Sat Aug 01, 2020 7:44 pm
Location: Texas
Has thanked: 1 time
Been thanked: 61 times

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

Post 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.

User avatar
wizard
Posts: 2084
Joined: Sun Aug 09, 2020 7:50 pm
Location: Oklahoma, USA
Has thanked: 2833 times
Been thanked: 753 times

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

Post 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

Big pile of OLD computers

User avatar
MochiMoppel
Posts: 1294
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 480 times

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

Post 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
williams2
Posts: 1066
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 306 times

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

Post 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
User avatar
Trapster
Posts: 201
Joined: Sat Aug 01, 2020 7:44 pm
Location: Texas
Has thanked: 1 time
Been thanked: 61 times

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

Post 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

williwaw
Posts: 2039
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 183 times
Been thanked: 389 times

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

Post 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

Geek3579
Posts: 286
Joined: Sat Jul 18, 2020 1:07 pm
Has thanked: 82 times
Been thanked: 74 times

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

Post 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

User avatar
mikeslr
Posts: 3015
Joined: Mon Jul 13, 2020 11:08 pm
Has thanked: 174 times
Been thanked: 952 times

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

Post 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.

User avatar
MochiMoppel
Posts: 1294
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 480 times

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

Post 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
Post Reply

Return to “Programming”