刷新 xfce4-panel 无需重新启动启动器图标。

huangapple go评论57阅读模式
英文:

Refresh launcher's icon without restarting xfce4-panel

问题

我有一个shell脚本,用于替换xfce4-panel启动器的图标。我正在寻找一种在不重新启动xfce4-panel的情况下刷新启动器图标的解决方案。

以root身份重新启动xfce4-panel可能会导致各种问题,比如在尝试通过CentOS UI重新启动服务器时出现错误,因为会话是由另一个用户启动的。我尝试使用命令像"sudo -u USER xfce4-panel --replace"来重新启动xfce4-panel,但问题仍然存在。

英文:

I have a shell script that replaces a favicon used as an image for a xfce4-panel launcher. I'm looking for a solution to refresh the launcher's icon without restarting xfce4-panel.

Restarting xfce4-panel as root could cause various issues, such as errors when trying to restart the server through the CentOS UI, as the session is launched by another user. I attempted to restart xfce4-panel using commands like "sudo -u USER xfce4-panel --replace," but the issue still persists.

答案1

得分: 1

I have translated the non-code portions of your text:

"在经过多天的搜索之后,我发现了一种可以强制xfce4-panel刷新图标而无需重新启动的解决方案。解决方案涉及编辑xfce4-panel启动器的配置文件。通过修改文件,xfce4-panel会识别到已经进行了更改并刷新启动器,包括相关的图标。

因此,我在我的脚本中集成的代码如下:

# 包含启动器及其相应配置文件目录的路径

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

# 您想要更新的启动器的名称

launcher_name="MyLauncher"

# 循环遍历包含要更新的启动器名称的每个启动器配置文件

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

    # 使用sed将"favicon.ico"替换为相同的名称,以编辑文件并强制xfce4-panel刷新启动器

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

done

阅读这个解决方案后,很自然会有一些问题:

  • 为什么我要使用循环?

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

  • 为什么我要用相同的名称替换"favicon.ico"?

在我的情况下,在第一个脚本中刚刚替换了文件"favicon.ico"。因此,我采用的解决方法只是编辑文件并通过xfce4-panel触发刷新启动器的图像。在您的情况下,您可以使用新图像的路径或名称。

其他信息:

在尝试这个解决方案之前,我尝试使用'touch configuration_file'命令来更新文件的日期并强制刷新,但没有成功。"

英文:

After differents days of searching, i have discovered a solution to force xfce4-panel to refresh icons without restarting it. The solution involves editing the configuration file of the xfce4-panel launcher. By modifying the file, xfce4-panel recognizes that changes have been made and refreshes the launcher, including the associated icon.

So the code that i have integrated in my script is the following :

# 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

Upon reading this solution, it's natural to find yourself asking some questions :

  • Why did i use a loop?

The reason is that the folders of the launchers are named "launcher-N" where "N" represents the number of the launcher, possibly indicating the order of creation for each launcher. To ensure accuracy, i chose to iterate over each configuration file that contains the name of the launcher i wanted to update, in order to locate the corresponding configuration file.

  • Why did i replace "favicon.ico" with the same name?

In my particular case, the file "favicon.ico" is replaced just before in the first script. Therefore, the workaround i employed was simply to edit the file and trigger the refreshing of the launcher's image by xfce4-panel. In your case, you can utilize the path or name of the new image.

Other informations :

Before this solution, i attempted to use touch configuration_file command to update the file's date and force a refresh, but it did not work.

huangapple
  • 本文由 发表于 2023年6月12日 16:44:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定