Wiki Ubuntu-it

Indice
Partecipa
FAQ
Wiki Blog
------------------
Ubuntu-it.org
Forum
Chiedi
Chat
Cerca
Planet
  • Pagina non alterabile
  • Informazioni
  • Allegati

Versione 2 del 01/05/2012 21.44.05

Nascondi questo messaggio

Problemi in questa pagina? Segnalali in questa discussione

Introduzione

I launcher della dash di Unity sono file presenti nel computer, con l'estensione .desktop. Nelle versioni di Ubuntu precedenti a Unity, questi file venivano utilizzati solo per creare un collegamento al programma, ma ora possono fornire anche un menu, accessibile cliccando col tasto destro del mouse sul launcher.

Creare un file .desktop

Attualmente, ci sono due modi per creare un file .desktop:

Creare il file .desktop con l'edior di testo potrebbe risultare più complesso, ma permette una maggiore personalizzazione.

Utilizzare l'editor di testo

Per creare un semplice launcher, è sufficiente aprire un edior di testo e incollare:

[Desktop Entry]
Version=1.6
Name=ProgramName
Comment=This is my comment
Exec=/home/alex/Documents/exec.sh
Icon=/home/alex/Pictures/icon.png
Terminal=false
Type=Application
Categories=Utility;Application;

Il parametro:

  • Version specifica la versione del programma cui il launcher punta;

  • Name specifica il nome dell'applicazione che verrà visualizzato;

  • Comment specifica un commento che descrive le funzionalità dell'applicazione;

  • Exec è il percorso al file da eseguire. Il percorso completo deve essere usato solo nel caso in cui non è specificato nella cariabile $PATH. Si ricorda che tutti i file eseguibili presenti nella cartella /usr/bin sono già inclusi in questa variabile, e pertanto non è necessario specificare il loro percorso completo.

Per vedere tutti i percorsi inclusi nella variabile $PATH aprire il terminale e digitare:

echo $PATH
  • Icon specifica il percorso dell'icona utilizzata dal programma. Per le icone presenti nella cartella /usr/share/pixmaps non è necesario specificare il percorso completo, ma solo il loro nome senza l'estensione. Per esempio, se il file si chiama /usr/share/pixmaps/icon.png, specificare icon.

  • Terminal specifica se il programma debba essere eseguito in una finestra di terminale.

  • Type specifica il tipo del launcher, che può essere Application, Link o Direcory. In questo wiki verranno trattati solo i launcher Application;

  • Categories specifica la categoria in cui l'applicazione verrà inserita.

Infine, è necessario impostare il file .desktop creato eseguibile; dopodichè prenderà automaticamente l'icona e il nome specificati nel suo interno.

Using gnome-panel/alacarte

It is important to install gnome-panel using the following command, so as not to install the recommended not-needed packets along with it. So open a terminal using Ctrl+Alt+T and give the following command:

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

It will ask you for your login password, which you have to fill (nothing will be shown, not even asterisks (*)) and press enter.

Without closing the terminal window, after the installation process is over, you have to type the following command:

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

where '~/Desktop/' is any directory you want your launcher to appear, after its creation process is over. After running this command, a familiar window will pop-up, which lets you fill the Name, the Command and the Comment for your launcher. Also, you can specify an icon for your launcher by clicking on the big icon of the window on the top left of it.

You can also use 'alacarte', which you can execute by searching in the Dash for 'Main Menu' and once the application launches, then you click on "New Item" on the section you want your application to be. Then a window similar to the one being shown using the gnome-panel method will be shown.

Adding a .desktop file to the Unity Launcher

In order to add your launcher to the Unity Launcher on the left, you have to place your .desktop file at /usr/share/applications/ or at ~/.local/share/applications/. After moving your file there, search for it in the Dash (Windows key -> type the name of the application) and drag en drop it to the Unity Launcher. Now your launcher (.desktop file) is locked on the Unity Launcher!

Editing an entry of the Unity Launcher

Editing its main characteristics

If you've added a .desktop file to the Unity Launcher, but you don't like something on it, like its icon, or probably it doesn't execute, then you may need to edit the launcher so as to change what you don't like or to fix any errors.

First of all, you have to know the exact name of the .desktop file you will need to edit, and it isn't the same with the application's name (they are usually similar, but still not the same).

So as to find the exact filename of the .desktop file you are interested in, open a terminal using Ctrl+Alt+T and give the following command:

gsettings get com.canonical.Unity.Launcher favorites

This will output a list of all the .desktop files you already have in your launcher, from top to bottom, like this:

['nautilus-home.desktop', 'firefox.desktop', 'filezilla.desktop', 'ubuntu-software-center.desktop', 'qtcreator.desktop', 'ubuntuone-installer.desktop', 'wallch.desktop', 'gnome-terminal.desktop', 'gedit.desktop', 'audacious.desktop', 'gnome-control-center.desktop']

So, by comparing this output to the row of the launchers in your Unity Launcher, you can easily find the name of the .desktop file. For example, if you want to edit the launcher before the last one, in this case it would be 'audacious.desktop'. Copy the name of this launcher by selecting it and giving Ctrl+Shift+C for later use. In order to edit this launcher, open a terminal using Ctrl+Alt+T and give the following:

cd /usr/share/applications/
gksudo gedit [paste here what you have in your clipboard with right click->paste or Ctrl+Shift+V]

where 'gedit' you can use your favourite text editor. The following command will ask you for password. Type in your login password and gedit (or any other text editor) will open with the launcher file you wish to edit. To edit the launcher go to 'Using a text editor' where it says it clearly on how to create a launcher and the same applies on editing it.

Adding shortcuts to a launcher

Some applications become much more usable with a right-click menu. This is an example of shortcuts, being used by the application 'Wallch':

[ALLEGA]

In this example, the program 'audacious', which is a music player available in the Ubuntu Software Center, will be used as an example of adding shortcuts.

After adding the main characteristics of a launcher, such as filling its 'Name' and 'Exec' fields, then you can add to it one or more shortcuts.

After the 'main body' of the .desktop file, you have to specify the 'actions' you want to add in the 'Actions' field and specify each one of them below. Here's a completely working example of the application 'audacious', providing 3 shortcuts, the Play/Pause, Next and Previous. This is a simplified version of the file:

[Desktop Entry]
Version=1.0
Type=Application
Name=Audacious
GenericName=Music Player
Comment=Listen to music
Icon=audacious
Categories=AudioVideo;Audio;Player;GTK;

Exec=audacious %U

TryExec=audacious

Terminal=false

MimeType=application/ogg;application/x-cue;application/x-ogg;application/xspf+xml;audio/midi;audio/mp3;audio/mpeg;audio/mpegurl;audio/ogg;audio/prs.sid;audio/x-flac;audio/x-it;audio/x-mod;audio/x-mp3;audio/x-mpeg;audio/x-mpegurl;audio/x-ms-wma;audio/x-musepack;audio/x-s3m;audio/x-scpls;audio/x-stm;audio/x-vorbis+ogg;audio/x-wav;audio/x-xm;x-content/audio-cdda;

Actions=PlayPause;Next;Previous

[Desktop Action PlayPause]
Name=Play-Pause
Exec=audacious -t
TargetEnvironment=Unity

[Desktop Action Next]
Name=Next
Exec=audacious -f
TargetEnvironment=Unity

[Desktop Action Previous]
Name=Previous
Exec=audacious -r
TargetEnvironment=Unity

The part that has to do with the shortcuts is everything after 'Actions=' including this. Everything specified on the 'Actions' field has its own name, specified on the 'Name' field of each one. For example, action PlayPause has name Play-Pause, and thus Play-Pause will be displayed on the shortcut in the Unity Launcher once you right click the icon of 'audacious'. Clicking on a shortcut will result on the corresponding action, which means it will execute anything specified in the 'Exec' field.

Making such shortcuts for applications is generally very easy, unless the application itself doesn't provide enough command line arguments so as to do a corresponding action you would like to. The arguments and what each one does for every application are available through their man page. For example, the arguments '-t', '-f' and '-r' of 'audacious', used on the above example were found though its manual page, using the command

man audacious

, the arrows so as to browse the manual page and the key 'Q' so as to exit.