vaa*_*aab 10 menu unity launcher 12.04 .desktop
修改桌面文件后/usr/share/applications
,我需要刷新启动器图标应用程序菜单,以便我的修改显示出来。为清楚起见,应该修改的菜单是当指针位于启动器图标上时右键单击出现的菜单(屏幕左侧充满图标的大栏)。
最佳答案是一个简单的命令行。
我没有使用 ubuntu-2d,也不想注销/登录。
我知道一些部分解决方案:
unity --replace
重新加载所有内容(窗口装饰、通知区域等)killall ubuntu-2d-launcher
仅适用于 ubuntu-2d,但如果存在用于统一的类似单行命令,那将是一个很好的解决方案。有什么建议 ?有没有办法感谢 ccsm ?
最优雅的方式是“重启”图标;将图标从其在启动器中的位置移除并将其替换在相同位置。下面的脚本完成了这项工作。它在 python2 中,因为默认情况下 12.04 不附带 python3。但是,它也可以在 python3 中使用,在这种情况下只更改shebang。例如,该脚本对于立即应用更改的图标也很有用(在以后的 Ubuntu 版本中也是如此)。
您可以通过调用脚本简单地使用它,并将编辑后的桌面文件作为参数(见下文)。
注意:在 12.04 中,如果刷新的图标代表正在运行的应用程序,则相关应用程序将崩溃,如本问题所述,因此如果您使用它,请确保该应用程序未运行。在 14.04 中,如果应用程序正在运行,图标将不会刷新。
剧本
#!/usr/bin/env python
import subprocess
import time
import sys
desktopfile = sys.argv[-1]
def read_currentlauncher():
# reads the current launcher contents
get_launcheritems = subprocess.Popen([
"gsettings", "get", "com.canonical.Unity.Launcher", "favorites"
], stdout=subprocess.PIPE)
return get_launcheritems.communicate()[0].decode("utf-8")
def set_launcher(llist):
# sets a defined unity launcher list
current_launcher = str(llist).replace(", ", ",")
subprocess.Popen([
"gsettings", "set", "com.canonical.Unity.Launcher", "favorites",
current_launcher,
])
def refresh_icon(desktopfile):
current_launcher = read_currentlauncher()
current_launcher_temp = eval(current_launcher)
item = [item for item in current_launcher_temp if desktopfile in item][0]
index = current_launcher_temp.index(item)
current_launcher_temp.pop(index)
set_launcher(current_launcher_temp)
time.sleep(2)
set_launcher(current_launcher)
refresh_icon(desktopfile)
Run Code Online (Sandbox Code Playgroud)
如何使用它
refresh.py
通过命令刷新图标:
/path/to/script/refresh.py name_of_edited_desktopfile (e.g. 'firefox.desktop')
Run Code Online (Sandbox Code Playgroud)如果你真的想让它光滑
使脚本可执行,删除.py
扩展名,将其保存在~/bin
. 注销/登录后,您可以通过以下命令运行它:
refresh firefox.desktop (as an example)
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
8777 次 |
最近记录: |