Converting a Linux script to a desktop launcher
2018-12-21
I wish to convert the following alias 'tel' or its associated script to a desktop launcher. When I run this alias from the terminal, it always works. I find that most terminal commands would work in a launcher file but not 'bash'. If I write Command=bash ~/info1.sh and try to run this .desktop file, I get a runtime error 'There was an error launching this application.' I feel that I am not going about this matter the right way. Any help will be much appreciated. Julianvb 1. File info1.txt consists of just the following lines. Quote:
Quote:
|
you probably ask for something like:
xterm -e script_name if you want to add a desktop-launcher for a script. Other terminals have a simimilar solution. do "man your_terminal" and search for -e. I am not that sure if an alias will work with that, it usually is used for the shell, and doesn't do that much(functions might work instead, not sure either, but: ). Just put the script in ~/bin and use that., make the desktop-launcher use "whichever-terminal -e scriptname" to launch it. A few things, just saying them, nothing is written in stone: info1.text is used for both, the scriptname and the file you grep. (?). There is no need to add an extension to a shell script., like .txt. Call it grep_fones or such, without extension. Quote the expansion of variables, so "$name", not $name. No need for "exit". #!/bin/sh is not bash, so if you want bash make the shebang use bash, probably #!/bin/bash in your case. uhm. i think the terminal will exit as soon the script finishes. You will need a solution to not close before you have seen the output. Ask the user for further input via read before the script "exits", or such. |
A couple of minor general points.
Note that you said that you used the command Code:
Command=bash ~/info1.sh Also, it may be better to use full path names in scripts rather than using the ~ shortcut. Finally, if the script is to be interpreted by bash then it should have Code:
#!/bin/bash Code:
#! /bin/sh |
Quote:
|
Quote:
Thanks for making it more clear. most of what i said after "not written in stone" is just a sidenote. he will get away with it, as far i can see. |
Code:
#!/bin/bash Code:
xterm -geometry 85x30 -bg black -fg orange -T "Phone Numbers" -e scriptName |
Quote:
|
nodir, hydrurga, BW-userx and Mechanikx,
Honestly I wasn't aware of the fine points about Bash. I copied the old shebang from some place long ago when I first started writing scripts. Since they all seemed to work, I moved on ignorantly. My info1 file normally appears as info1.txt in my .bash_aliases file and in my 'tel' alias. I renamed it only tonight but it still works as far my alias 'tel' or the execution of the info1 script goes. Thank you all very much for your suggestions and sharing your extensive knowledge with me. My Linux Mint system has both xterm and uxterm. When I run the following, the script quits prematurely after I enter an input to it. Code:
xterm -e info1.sh Code:
bash info1.sh Julianvb |
Quote:
|
Quote:
I am kind of dense. I read Reply #6 and still fail to grasp its gist. Please help me. Clearly you folks are much younger and sharper than I'm. I regret to admit it; time has a way of pushing me toward 90. Julianvb |
Quote:
'read' holds the terminal open until something is entered. Everything after xterm is just telling xterm what size, font color -fg and background color -bg , T is for title, -e is command to execute. this is just another methoid of doing what you're asking to do. |
Quote:
Thank you so much for your great help. I've just implemented your much better version of my info1 script and it works just like my original one. Of course, your is more elegant. You may regard my primitive script a quick and dirty one even though it always works OK. My basic question is 'How does one write a desktop launcher version of a Bash script step by step ?" I hope you'll bear with my slow wit. Julianvb |
Quote:
In order to make my script info1.sh work with the Desktop instead of the terminal only, I simply replaced 'exit' with 'read' as the final command in the file to keep the screen open. Linux Mint does not care whether $name is double-quoted or not and accepts the shebanq #! /bin/sh and #! /bin/bash for bash scripts according to my experience. You may call me dumb-lucky or a lucky dummy. The following is my working desktop launcher file: Quote:
Julianvb |
Quote:
if you are just issuing commands in a electronic piece of paper, or e-paper as I call it sometimes. You don't need a shebang because it is not bash it is just a file made executable to issue commands in what is called a wrapper. I've got one that inside the file it is just simply Code:
/media/data1/scripts/resamplemp3s and it is placed in my /usr/local/bin. So all I have to do is open a terminal and type, resamplemp3. That cuts down on typing. Removing the need to type in the absolute path and script name, or changing in to the dir then typing ./resamplemp3s just remember to make it executable Code:
chmod +x filename all of this works wihtout a shebang Code:
|
Quote:
you neither have been outstanding sloppy nor inelegant, and sure not outstanding slow. I hardly add scripts as desktop-launchers, but when i did, it sure confused the heck out of me and took me longer to get it sorted (as said: you might say i am slow and got no talent ... :-) ). to give one example: many people don't quote variable expansion, some as they don't know any better, some as it is not always strictly needed. Perhaps i didn't say it clear enough, but my main info was "termina-emulator -e", and the rest was just "into the bargain" (as i see now: perhaps confusing, superfluous). I hesitated quite a bit, as you didn't ask for it, none of it was standing in your way to solve the question you have stated very clearly in your first post. Short version: to me you are doing fine. Solving the stuff as you run in them. To add something useful too: For the future you might want to sure https://shellcheck.net (assuming you will run in problems which might relate to those fine details as the used shebang. They might not relate to it, but at least you can exclude it with shellcheck). I guess i always prefer asking in a forum or irc channel, as i get better explanations and extra-info ... but it is a good tool. |
All times are GMT -5. The time now is 02:56 AM. |