Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I tend to find myself opening terminal sessions to run Sudo commands and was wanting to make something more useful as an application.

Using some information from various online sources https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles I came up with my little desktop application.

app right click

Start by installing desktop shortcuts

sudo apt-get install --no-install-recommends gnome-panel 

then run

gnome-desktop-item-edit --create-new ~/Desktop

Create a basic launcher desktop shortcut.

Basic Launcher

Now create a new Terminal Profile called StayOpen

Open Terminal, Select FILE - New Profile, Create New call the new Profile "StayOpen". Then Under Properties Select the tab for Title and Command. At the bottom of this tab select when command exits - Hold the terminal open

Hold Terminal Open

Once your default Desktop file is created you will want to edit it. Example Below:

gedit <Your File name>

Example:

My below desktop file script is named "Sudo Run". If you are copy/pasting the script below, you will want to account for that with my file below or it will not run properly.

[Desktop Entry]
Version=1.0
Type=Application
Name=Sudo Run
Icon=gdm-xnest.png
Exec=gnome-terminal
Terminal=false
Actions=Terminal;TerminalRoot;Files;TextEdit;Update

[Desktop Action Terminal]
Name=Terminal
Exec=gnome-terminal --window-with-profile=StayOpen
OnlyShowIn=Unity;

[Desktop Action TerminalRoot]
Name=Terminal Root
Exec=gnome-terminal --window-with-profile=StayOpen -x bash -l -c "sudo su;bash"
OnlyShowIn=Unity;

[Desktop Action Files]
Name=Sudo Files
Exec=gnome-terminal --window-with-profile=StayOpen --geometry=40x2+1+1 -x bash -l -c "sudo nautilus;bash"
OnlyShowIn=Unity;

[Desktop Action TextEdit]
Name=Sudo Text Edit
Exec=gnome-terminal --window-with-profile=StayOpen --geometry=40x2+1+1 -x bash -l -c "sudo gedit;bash"
OnlyShowIn=Unity;

[Desktop Action Update]
Name=Sudo Apt-Get Update
Exec=gnome-terminal --window-with-profile=StayOpen -x bash -l -c "sudo apt-get update && sudo apt-get upgrade;bash"
OnlyShowIn=Unity;

Once complete move file to applications folder, and can be treated as an application.

sudo nautilus

move file to usr/share/applications

Then drag drop to unity launcher if desired. Here is where the bash script becomes useful.

Once the desktop link is on the unity launcher you will have several right click options as listed below in Actions. Note the corresponding actions at the bottom of the file. Several of the bash scripts open a small terminal window just large enough to type in your sudo password. Modify the "geometry=" to your preference or remove if desired. Once the password is typed in you get your application running, etc.

You can change the Actions to sort in your preference and set the default "Exec=" to your left click preference as well

One of the great features of this as a shortcut on your unity launcher is the Right Click "Quit" function which will close all open windows.

-mb: edited to improve readability

share|improve this question
    
Great script. Thanks for sharing. –  SimplySimon Jun 4 '13 at 4:24
    
After recreating your script, I find that the icon changes with the script icon. I'm using 13.04 –  SimplySimon Jun 4 '13 at 4:57
    
added a new picture for the first image, but the second image has an invalid url! –  SimplySimon Jun 4 '13 at 10:57
2  
This is NOT a question. If you want to share your learnings, then please ask a question and answer it yourself. –  don.joey Jun 4 '13 at 13:05
2  
Hi MB-. Thank you for sharing this piece of info. However, our format works slightly different from a blog post. Can you phrase your question like you are in jeopardy and then move the question content to the answer section? That would be clearer for everyone who are accustomed with our site. Thank you very much. –  jokerdino Jun 4 '13 at 18:25
show 2 more comments

1 Answer 1

You can change the icon using the Icon option. I guess you knew that already but I'm noticing that you have declared it only on the first entry. Also it is declared twice there which might be conflicting. Remove one of them and see if it works.

Also your icons are given as relative path. I don't know in what folder unity is looking for icons but you have to copy the file there or use an absolute path (e.g. Icon=/home/myuser/myicon.png).

share|improve this answer
    
" Also it is declared twice there which might be conflicting. Remove one of them and see if it works." ---PERFECT. Thanks for the tip. I removed the line Icon=gnome-panel-launcher –  MB- Jun 4 '13 at 10:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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