用于向 Unity 启动器添加/删除桌面启动器的 Bash 脚本?

HDa*_*ave 5 bash scripts unity launcher

我正在尝试编写一个脚本来在全新安装后设置我的桌面环境。我无法弄清楚的一件事是如何从 bash 脚本将项目固定/取消固定到 Unity Launcher。有任何想法吗?

Ian*_* B. 8

使用 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命令。