如何让我的应用程序接受来自 Unity Launcher 的文件夹?

如何让我的应用程序接受来自 Unity Launcher 的文件夹?

拖动文件时,启动器上所有能够打开该文件的条目都会保持亮色,而其他条目则会淡化。据我所知,这是基于每个应用程序的 .desktop 文件中指定的 Mime 类型。

我希望我的申请能够通过 Unity 启动器接受文件夹作为参数。 我已经添加了

MimeType=inode/directory;

到我的.desktop 文件但无济于事。

有任何想法吗?

编辑:

这是我的完整 .desktop 文件:

[Desktop Entry]
Version=4
Name=Wallch
Comment=Change desktop wallpapers automatically
Exec=/usr/bin/wallch %U
Icon=wallch
Terminal=false
Type=Application
Categories=Utility;Application;
MimeType=inode/directory;

Actions=Start;Change_Wallpaper;

[Desktop Action Start]
Name=Start
Exec=/usr/bin/wallch --start
TargetEnvironment=Unity

[Desktop Action Change_Wallpaper]
Name=Change Wallpaper
Exec=/usr/bin/wallch --change
TargetEnvironmet=Unity

答案1

经过一番研究,我发现如果您希望启动器中的应用程序处于活动状态并且在拖动文件夹时保持变亮,则需要按如下方式命名其.desktop 文件:

应用程序名称-鹦鹉螺。桌面

或者:

应用程序名称-nautilus 文件夹处理程序。桌面

因此,对于你来说,情况将是:

wallch-nautilus.desktop

我不确定这个限制是正常行为(应该是)还是一个错误。如果你认为这是一个错误,你可以报告错误

话虽如此,我创建了以下脚本,它将自动为您完成这项工作(我将其命名为wallch_on_launcher):

#!/bin/bash

#wallch_on_launcher - script to create a .desktop file for wallch application and set its icon on the launcher
#the icon from the launcher will stay lightened when a folder is dragged

#Licensed under the standard MIT license:
#Copyright 2013 Radu Rădeanu (https://askubuntu.com/users/147044/).
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

desktop_file="wallch-nautilus.desktop"
desktop_file_path="$HOME/.local/share/applications/$desktop_file"

launcher_icons=$(gsettings get com.canonical.Unity.Launcher favorites)
new_launcher_icons=$(echo $launcher_icons | sed "s/]/, 'application:\/\/$desktop_file']/g")

touch $desktop_file_path

cat << EOF > $desktop_file_path 
[Desktop Entry]
Version=4
Name=Wallch
Comment=Change desktop wallpapers automatically
Exec=/usr/bin/wallch %U
Icon=wallch
Terminal=false
Type=Application
Categories=Utility;Application;
MimeType=inode/directory;

Actions=Start;Change_Wallpaper;

[Desktop Action Start]
Name=Start
Exec=/usr/bin/wallch --start
TargetEnvironment=Unity

[Desktop Action Change_Wallpaper]
Name=Change Wallpaper
Exec=/usr/bin/wallch --change
TargetEnvironmet=Unity
EOF

gsettings set com.canonical.Unity.Launcher favorites "$new_launcher_icons"

不要忘记使脚本可执行:

chmod +x wallch_on_launcher

结果可以在下面的屏幕截图中看到:

wallch 桌面文件


请注意,Wallch(3.01-0ubuntu2)的当前版本不知道如何处理作为参数给出的文件夹:

$ wallch ~/图片
无效选项:'/home/radu/Pictures'
输入 wallch -h 或 --help 查看所有可用选项

因此,当您将文件夹拖放到 Unity Launcher 上的 Wallch 图标上时,不会发生任何事情。

相关内容