如何从命令行向Unity Launcher添加/删除应用程序?
我正在使用UCK(Ubuntu Customization Kit)定制Ubuntu 14.04 Live CD。 该程序为您提供终端中的chroot环境以进行更改。
我想添加和删除Dock上显示的程序。
我不确定是否可以通过修改.desktop
文件来完成此操作?
如何使用终端完成?
下面的脚本可用于向启动器添加或删除项目,具体取决于参数:
#!/usr/bin/env python3 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 set_launcher(desktopfile): curr_launcher = current_launcher() last = [i for i, x in enumerate(curr_launcher) if x.startswith("application://")][-1] new_icon = "application://"+desktopfile if sys.argv[2] == "a": 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)]) elif sys.argv[2] == "r": curr_launcher.remove(new_icon) subprocess.Popen(["gsettings", "set", "com.canonical.Unity.Launcher","favorites",str(curr_launcher)]) set_launcher(desktopfile)
如何运行它
- 将代码粘贴到空文件中,将其另存为
set_launcher.py
-
通过命令运行它:
python3 /path/to/set_launcher.py
a 添加图标,或:
python3 /path/to/set_launcher.py
r 删除图标
例:
python3 /path/to/set_launcher.py gedit.desktop a
将
gedit
添加到启动器,或python3 /path/to/set_launcher.py gedit.desktop r
从发射器中删除
gedit
说明
启动器图标列表在密钥中定义:
com.canonical.Unity.Launcher favorites
并且可以通过命令获取:
gsettings get com.canonical.Unity.Launcher favorites
设置替代列表(假设您使用正确的格式):
gsettings set com.canonical.Unity.Launcher favorites "[item1, item2, etc]"
你能通过编辑.desktop
文件来实现吗?
不,它与文件本身无关。 重要的是该文件是否在启动器collections夹列表中。
从命令行编辑此列表正是脚本的作用。