Adicionando meu lançador ao Unity Launcher automaticamente. Como?

2

Com base na documentação oficial:

In order to add your launcher to the Unity Launcher on the left, you select and drag it onto the Launcher panel. Alternatively, you can 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 and drop it to the Unity Launcher. Now your launcher (.desktop file) is locked on the Unity Launcher!

Isso significa que você pode adicionar um lançador manualmente por meio de "arrastar e soltar". Mas, é possível fazer isso programaticamente?

Eu posso explicar por que estou perguntando:

Eu tenho meu próprio scpirt, ele faz o download da versão mais recente do Eclipse IDE, cria o arquivo eclipse.desktop sem interação com o usuário.

E na última etapa, quero adicionar o arquivo Eclipse.desktop ao Unity Launcher e não quero perguntar ao usuário para fazer isso.

Analisei a spesification dos arquivos * .desktop e obtive uma resposta.

Por favor, forneça conselhos.

    
por user471011 11.09.2014 / 22:02

1 resposta

4

Eu realmente fiz um script para isso. Ele coloca o ícone no lançador, mas com uma pequena alteração, você pode colocá-lo no topo (ou em qualquer outra posição) também.

Como está, ele está em python2, mas simplesmente mude o shebang para #!/usr/bin/env python3 se você quiser usá-lo como python3. O código é idêntico.

Para usá-lo, o arquivo .desktop precisa estar em /usr/share/applications ou em ~/.local/share/applications , mas geralmente é esse o caso.

Como usar

  • copie o script abaixo, salve-o como launcher_add.py
  • torne-o executável

Execute-o pelo comando:

/path/to/launcher_add.py name_of_desktopfile.desktop 

você tem que usar o filename do arquivo .desktop, sem o caminho.

O script

#!/usr/bin/env python

import subprocess
import sys

desktopfile = sys.argv[1]

def current_launcher():
    get_current = subprocess.check_output(["gsettings", "get", "com.canonical.Unity.Launcher", "favorites"]).decode("utf-8")
    return eval(get_current)

def add_new(desktopfile):
    curr_launcher = current_launcher()
    last = [i for i, x in enumerate(curr_launcher) if x.startswith("application://")][-1]
    new_icon = "application://"+desktopfile
    if not new_icon in curr_launcher:
        curr_launcher.insert(last, new_icon)
        subprocess.Popen(["gsettings", "set", "com.canonical.Unity.Launcher","favorites",str(curr_launcher)])
    else:
        pass

add_new(desktopfile)

O script evita várias ocasiões na lista de iniciadores do mesmo aplicativo, o que causaria corrupção da lista.

    
por Jacob Vlijm 11.09.2014 / 22:59