How to make my application accept folders from Unity Launcher?

Solution 1:

After some research I discovered that if you want an application from the launcher to be active and to stay lightened when you drag a folder, you need to name its .desktop file as follows:

app_name-nautilus.desktop

or:

app_name-nautilus-folder-handler.desktop

So, in your case it will be:

wallch-nautilus.desktop

I'm not sure if this restriction is a normal behavior (as it should be) or if it is a bug. If you consider that this is a bug, you can report it as a bug.

This being said, I created the following script which will make this job automatically for you (I named it 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"

Don't forget to make the script executable:

chmod +x wallch_on_launcher

The result can be seen in the below screen cast:

wallch desktop file


Note that the current version of Wallch (3.01-0ubuntu2) doesn't know how to handle a folder which is given as argument:

$ wallch ~/Pictures
Invalid option: '/home/radu/Pictures'
Type wallch -h or --help for all available options

So, because of this nothing will happen when you drag and drop a folder on the Wallch icon on the Unity Launcher.