从命令行解锁启动器中的应用程序

为了自动配置全新安装,我需要一种从启动栏中解锁默认应用程序的方法。 不知道这些信息的存储位置,可能是编辑/替换文件将是最简单的方法。

获取当前启动器图标的命令是:

gsettings get com.canonical.Unity.Launcher favorites 

这将为您提供如下列表:

 ['item_1', 'item_2', 'application://application_to_remove.desktop', 'etc'] 

如果从列表中删除项目并通过命令设置列表的更改版本:

 gsettings set com.canonical.Unity.Launcher favorites "['item_1', 'item_2', 'etc']" (mind the double quotes) 

您的应用程序已从启动器解锁。

示例脚本

作为如何通过(python)脚本完成工作的示例:

 #!/usr/bin/env python3 import subprocess import sys key = "com.canonical.Unity.Launcher" desktopfile = sys.argv[1] curr_launcher = eval(subprocess.check_output([ "gsettings", "get", key, "favorites" ]).decode("utf-8")) new_launcher = [item for item in curr_launcher if not desktopfile in item] subprocess.Popen(["gsettings", "set", key,"favorites",str(new_launcher)]) 

如何使用

  • 将脚本粘贴到空文件中,将其另存为remove_fromlauncher.py
  • 通过命令运行它

     python3 /path/to/remove_fromlauncher.py  

    或更短:

     python3 /path/to/remove_fromlauncher.py  

    示例删除Virtualbox:

     python3 /path/to/remove_fromlauncher.py virtualbox.desktop 

注意

请记住,您不能简单地从列表中删除所有项目; 它还包括不是应用程序的项目。


编辑

用于一次删除多个图标的脚本版本:

 #!/usr/bin/env python3 import subprocess import sys key = "com.canonical.Unity.Launcher" desktopfiles = sys.argv[1:] for desktopfile in desktopfiles: curr_launcher = eval(subprocess.check_output([ "gsettings", "get", key, "favorites" ]).decode("utf-8")) new_launcher = [item for item in curr_launcher if not desktopfile in item] subprocess.Popen(["gsettings", "set", key,"favorites",str(new_launcher)]) 

用法几乎相同,但现在您可以同时使用多个argumnents,例如:

 python3 /path/to/remove_fromlauncher.py gedit thunderbird 

将从发射器中删除ThunderbirdGedit