centos 刷新启动器的图标而不重启xfce 4-panel

rmbxnbpk  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(189)

我有一个shell脚本,它可以替换用作xfce 4面板启动器图像的favicon。我正在寻找一个解决方案来刷新启动器的图标,而无需重新启动xfce 4面板。
以root身份重新启动xfce 4-panel可能会导致各种问题,例如当尝试通过CentOS UI重新启动服务器时出错,因为会话是由另一个用户启动的。我试图使用命令“sudo -uUSER xfce 4-panel --replace”重新启动xfce 4-panel,但问题仍然存在。

2guxujil

2guxujil1#

经过几天的搜索,我发现了一个解决方案,强制xfce 4面板刷新图标而不重新启动它。解决方案涉及编辑xfce 4面板启动器的配置文件。通过修改文件,xfce 4-panel识别出已经进行了更改,并刷新启动器,包括相关的图标。
所以我在脚本中集成的代码如下:

# path that includes directories of launchers and their corresponding configuration files

launchers_path="/home/USERNAME/.config/xfce4/panel"

# name of the launcher that you want to update

launcher_name="MyLauncher"

# loop over each launcher configuration file that contains the name of the launcher to update

for launcher in $(grep -rl $launcher_name $launchers_path); do

    # using sed to replace "favicon.ico" by the same name in order to edit the file and force xfce4-panel to refresh the launcher

    sed -i 's/favicon.ico/favicon.ico/g' $launchers_path/$launcher

done

在阅读这个解决方案时,很自然地发现自己会问一些问题:

  • 我为什么要用一个循环?

原因是启动器的文件夹被命名为“启动器-N”,其中“N”表示启动器的编号,可能指示每个启动器的创建顺序。为了确保准确性,我选择遍历包含我想要更新的启动器名称的每个配置文件,以便找到相应的配置文件。

  • 为什么我用同样的名字替换“favicon.ico”?

在我的特殊情况下,文件“favicon.ico”在第一个脚本中被替换。因此,我采用的解决方法是简单地编辑文件并通过xfce 4-panel触发启动器图像的刷新。在您的示例中,您可以使用新映像的路径或名称。
其他信息:
在此解决方案之前,我尝试使用touch configuration_file命令更新文件的日期并强制刷新,但没有成功。

相关问题