使用 gsettings:
gsettings get com.canonical.Unity.Launcher favorites
Run Code Online (Sandbox Code Playgroud)
为您提供启动器上的内容列表:
['nautilus-home.desktop', '/opt/google/chrome/google-chrome.desktop', 'apps.desktop', 'geany.desktop', 'libreoffice-startcenter.desktop', 'gnome-terminal.desktop', 'gcalctool.desktop', 'Science.desktop', 'gimp.desktop', 'inkscape.desktop', 'ubuntu-software-center.desktop', 'alarm-clock-applet.desktop']
Run Code Online (Sandbox Code Playgroud)
所以你可以在 bash 中做这样的事情:
#!/bin/bash
myfile='firefox.desktop'
list=`gsettings get com.canonical.Unity.Launcher favorites`
newlist=`echo $list | sed s/]/", '${myfile}']"/`
gsettings set com.canonical.Unity.Launcher favorites "$newlist"
Run Code Online (Sandbox Code Playgroud)
我测试过,它可以将 firefox 添加到启动器,但是图标不会立即显示。您必须注销/登录或执行unity --replace命令。