[Solved] Taxonomies in Thunar (Labeling for the poor)

Get help with XFCE specific problems
User avatar
M. Eerie
Shogun
Shogun
Posts: 338
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#1 by M. Eerie » 06 Sep 2021, 10:52

One of the most useful things I've seen on Mac's is the ability to classify things quick and comfortably thanks to the color labeling method included in his finder. This adds a lot of flexibility and allows you to keep things in order even if you prefer chaos.

So I've been researching on how to implement this in Thunar and finally got some resources:
https://www.reddit.com/r/kde/comments/8 ... n/dwd6fbc/
https://forums.linuxmint.com/viewtopic.php?t=308032
https://forum.xfce.org/viewtopic.php?id=14796
https://forum.xfce.org/viewtopic.php?id=11478
and specifically
https://forum.xfce.org/viewtopic.php?id=14708

From this on, I've been trying to build my own approach, which admittedly its a bit tricky and dirty, but that's the way it is…

This script will make it for you by:
* Creating color emblems
* Creating companion color folders
* Creating the necessary .desktop actions under Thunar>SendTo menu

Code: Select all

#!/bin/bash

sendto="$HOME/.local/share/Thunar/sendto"
[ -d "$sendto" ] || mkdir -p "$sendto"

[ -d "$HOME"/.icons/hicolor/scalable/emblems ] || mkdir -p "$HOME"/.icons/hicolor/scalable/emblems
cd "$_" || exit

### from here to the end of the script, change Spotlight to your preferred folder name (Favorites, Starred, Scattergories... )
for color in blue green magenta orange purple red skyblue yellow; do 
mkdir -p "$HOME"/Spotlight/$color

cat > emblem-color-$color.svg<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="16" height="16">
 <circle r="8" cx="8" cy="8" style="fill:$color"/>
</svg>
EOF


cat > "$sendto"/label-$color.desktop<<EOF
[Desktop Entry]
Version=1.0
Name=Label $color
Comment=Tag $color
Exec=sh -c "for file in %F; do gio set -t stringv "\$file" metadata::emblems emblem-color-$color; touch -c -r "\$file" "\$file"; ln -sf "\$file" "\$HOME"/Spotlight/$color/%N; done"
Terminal=false
Icon=emblem-color-$color
Type=Application
EOF
done

Then, as advised, is a good idea to have those folders at hand:
4) add a "Directory Menu" plugin/button to the panel and point its "Base Directory" to the new "Spotlight" (Favorites) folder.


*** THINGS LEFT:

* Can't get various color emblems for one file. I.e. setting one color label will reset another.
* Script a full method which allows to (selectively) unlabel too. I.e.:

Code: Select all

[[ $(gio info -a metadata::emblems $file) =~ emblem-color-yellow ]] || gio set $file -t unset metadata::emblems
 
Until a proper labels:/// or tags:/// classifying protocol is included in Thunar, I'll be using this.

*** BONUS TRACK:

Although not related to this tagging method itself, we can even add more control by creating a bookmark to recent files in the side panel. These files are xml-listed in the $HOME/.local/share/recently-used.xbel file.

Just open a terminal and type:

Code: Select all

echo recent:/// >> $HOME/.config/gtk-3.0/bookmarks
Any feedback would be greatly appreciated :)
Last edited by M. Eerie on 20 Sep 2021, 09:26, edited 17 times in total.
Cheers!

User avatar
M. Eerie
Shogun
Shogun
Posts: 338
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

Taxonomies in Thunar (Labeling for the poor)

Post#2 by M. Eerie » 09 Sep 2021, 11:39

Created a script to automate the process.

:)
Cheers!

User avatar
M. Eerie
Shogun
Shogun
Posts: 338
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

Taxonomies in Thunar (Labeling for the poor)

Post#3 by M. Eerie » 18 Sep 2021, 09:55

Since the Desktop Entry Specifications implies escaping some especial/reserved chars, I had to make some changes. This fixes a bug when the filename contains spaces. Added a white icon for use in a later version, when the option to Unlabel is available..

Code: Select all

#!/bin/bash
# Tag by colors in Thunar
#

emblems="$HOME/.icons/hicolor/scalable/emblems"
sendto="$HOME/.local/share/Thunar/sendto"
[ ! -d $emblems ] && mkdir -p $emblems
[ ! -d "$sendto" ] && mkdir -p "$sendto"

### from here to the end of the script, change Favorites to your preferred folder name (Spotlight, Starred, Scattergories... )
[ -d "$HOME"/Favorites ] || mkdir -p "$HOME"/Favorites
cd $emblems || exit

cat > emblem-color-white.svg<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="16" height="16">
 <ellipse cx="8" cy="8" rx="7.8" ry="7.8" fill="#f0f0f0" stroke="#000" stroke-width=".4"/>
</svg>
EOF

for color in blue green magenta orange purple red skyblue yellow; do 
mkdir -p "$HOME"/Favorites/$color

cat > emblem-color-$color.svg<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="16" height="16">
 <circle r="8" cx="8" cy="8" style="fill:$color"/>
</svg>
EOF

cat > "$sendto"/label-$color.desktop<<EOF
[Desktop Entry]
Version=1.0
Name=Label $color
Comment=Tag $color
Exec=sh -c "for file in %F; do gio set -t stringv \"\$file\" metadata::emblems emblem-color-\$color; touch -c -r \"\$file\" \"\$file\"; ln -sf \"\$file\" \"\$HOME\"/Favorites/$color/%N; done"
Terminal=false
Icon=emblem-color-$color
Type=Application
EOF
done

echo file://`echo "$HOME"`/Favorites >> $HOME/.config/gtk-3.0/bookmarks

However, I can't find a way to Unlabel from a .desktop file.

Figured it out! :)

Save next code as "untag-color" and put it in your $PATH. (I.e.: /home/guest/.local/bin/untag-color or /usr/local/bin/untag-color). Don't forget to make it executable (chmod +x untag-color).

Code: Select all

#!/bin/sh
for file in "$@"
do
COLOR="$(gio info -a metadata::emblems "${file}" | grep 'metadata::emblems')"; COLOR="${COLOR##*-}"; COLOR="${COLOR%%]*}"
if [ ! -z $COLOR ]; then
    gio set -t unset "${file}" metadata::emblems
    touch -c -r "${file}" "${file}"
    rm "$HOME/Favorites/$COLOR/${file##*/}"
fi
done
And this is the .desktop companion to be placed in "$HOME/.local/share/Thunar/sendto":

*** CHANGE /home/guest in Exec line below to suit your needs.

Code: Select all

[Desktop Entry]
Name=Untag color
Comment=Remove color tag
Exec=/home/guest/.local/bin/untag-color %F
Terminal=false
Icon=emblem-color-white
Type=Application
Cheers!

User avatar
M. Eerie
Shogun
Shogun
Posts: 338
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#4 by M. Eerie » 20 Sep 2021, 09:26

Got it working.
B)
Cheers!

User avatar
Rava
Contributor
Contributor
Posts: 3006
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc + 4.0 i586 XFCe
Location: Forests of Germany
Contact:

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#5 by Rava » 22 Sep 2021, 04:25

Mind sharing some screenshots how it actually looks in Thunar?

The scripts alone are nice, but prior trying it out I would love to see what it results in, especially when using the dark theme.
M. Eerie wrote:
20 Sep 2021, 09:26
Got it working.
Did you change anything in your scripts above? Or is there a certain way one must follow to archive the goal?
Cheers!
Yours Rava

User avatar
M. Eerie
Shogun
Shogun
Posts: 338
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#6 by M. Eerie » 22 Sep 2021, 07:42

Rava wrote:
22 Sep 2021, 04:25
Mind sharing some screenshots how it actually looks in Thunar?
I don't have a dark theme installed, sorry.

See the demo:
Image
Rava wrote:
22 Sep 2021, 04:25
Did you change anything in your scripts above?
As stated in post#3, I've fixed a bug in order to deal with filenames containing spaces and also added a script to untag emblems.

Edit: Hosted gif in another page.
Last edited by M. Eerie on 22 Sep 2021, 14:25, edited 2 times in total.
Cheers!

User avatar
Rava
Contributor
Contributor
Posts: 3006
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc + 4.0 i586 XFCe
Location: Forests of Germany
Contact:

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#7 by Rava » 22 Sep 2021, 10:47

M. Eerie wrote:
22 Sep 2021, 07:42
I don't have a dark theme installed, sorry.
But every XFCE made by fulalas comes with a dark theme.
Did you make your own XFCE or do you use Thunar outside of XFCE?
M. Eerie wrote:
22 Sep 2021, 07:42
Edit: Hosted gif in another page.
Many thanks for that, I do not recall ever having seen https://ibb.co before, but it works like a charm. :friends:
Last edited by Rava on 23 Sep 2021, 12:27, edited 2 times in total.
Reason: removes off-topic parts ^-^;
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 3006
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc + 4.0 i586 XFCe
Location: Forests of Germany
Contact:

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#8 by Rava » 22 Sep 2021, 11:52

I presume Enviar a is in your language the action of highlighting a set of selected files?
I had to guess the used language, I presumed either Spanish or Portuguese. Fortunately my most fav translation site - https://dict.leo.org nowadays has many languages including Portuguese. I recall the times when there was only English French and Italian. Each language is translated to German since leo (Link Everything Online) is a German site. And the largest forum for discussing English to German stuff and vice versa.

Code: Select all

enviar a.c. a alg. 	jmdm. etw. zusenden  | sendete zu/sandte zu, zugesendet/zugesandt 
jmdm. etw. zusenden in English means to send s.th to someone. Or as most English speaking GUIs would call it Send to - but that is already usually used for copying files to local storage devices or sending files over a network.

What is your English phrase you choose for the Send To for Colour Highlighting action? Simple Colour Highlighting?
Last edited by Rava on 23 Sep 2021, 12:22, edited 1 time in total.
Reason: removes off-topic parts ^-^;
Cheers!
Yours Rava

User avatar
M. Eerie
Shogun
Shogun
Posts: 338
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#9 by M. Eerie » 22 Sep 2021, 12:41

Rava wrote:
22 Sep 2021, 10:47
Did you make your own XFCE or do you use Thunar outside of XFCE?
I use Nemesis and I don't use a dark theme.
Rava wrote:
22 Sep 2021, 11:52
I presume Enviar a is in your language
"Enviar a" (spanish) is "Send To" (english).

Seems you've missed the introduction:
M. Eerie wrote:
06 Sep 2021, 10:52
This script will make it for you by:
* Creating color emblems
* Creating companion color folders
* Creating the necessary .desktop actions under Thunar>SendTo menu
Explained in more detail:
  • Emblems will be saved in standard $HOME/.icons/hicolor/scalable/emblems to make them available for any theme.
  • Companion folders wiill be saved in $HOME/Favorites/$COLOR by default
  • .desktop action files, will be saved in $HOME/.local/share/Thunar/sendto
  • And finally, a link to $HOME/Favorites will be created in Thunar's side panel
Edit:
Forgot to mention the "untag-color" script which needs to be in your $PATH
Cheers!

User avatar
Rava
Contributor
Contributor
Posts: 3006
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc + 4.0 i586 XFCe
Location: Forests of Germany
Contact:

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#10 by Rava » 22 Sep 2021, 18:13

^

Okay, are your integration into thusar scripts then multi-lingual, or must the integration into thunar be made manually?
Because the mentioned "Enviar a" (spanish) is, well, Spanish.
Cheers!
Yours Rava

User avatar
M. Eerie
Shogun
Shogun
Posts: 338
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#11 by M. Eerie » 23 Sep 2021, 07:38

Rava wrote:
22 Sep 2021, 18:13
Because the mentioned "Enviar a" (spanish) is, well, Spanish.
I can't believe you are telling me in what language I should set my system to. Are you kidding me?
Have you checked the script? Have you seen any words in it in, well, Spanish?

Other than that and setting a dark theme, what else do I need to do to contribute something I consider useful?

I beg you not turning this into an endless list of complaints about imgur's problems with Palemoon or my language settings when capturing a video or anything else, which have nothing to do with the subject. And that, without even having tested the script.
Cheers!

User avatar
Rava
Contributor
Contributor
Posts: 3006
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc + 4.0 i586 XFCe
Location: Forests of Germany
Contact:

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#12 by Rava » 23 Sep 2021, 10:08

M. Eerie wrote:
23 Sep 2021, 07:38
I can't believe you are telling me in what language I should set my system to. Are you kidding me?
Have you checked the script? Have you seen any words in it in, well, Spanish?
I think you misunderstood me.

I was just asking what needs to be done to create the entry in Thunar that was visible in your GIF.

I realized that the Spanish phrase is not part of any of your scripts, therefore my question.

This has nothing to do with anyone and least me telling you what language to use in your OS, and the same which theme - dark or light - you want.
I was just confused since it is about Thunar so I initially presumed you used XFCE since Thunar and XFCE usually go together, and deducted you must have a dark theme available since Porteus XFCE ships with a dark theme. That was not meant as a way of telling you which theme to use or not to use,just a faulty deduction on my part. My bad. Of course you can also use a different DE and still have Thunar as your file browser.
_____________________________________

About me not yet having tested your script: Sorry for having questions I wanted clarified prior using your scripts.

Since you not told me how to do the integration into Thunar, I presume that is explained in the scripts itself, and again I am not judging you for using Spanish for the integration menu, I just wondered where the Spanish came from when the scripts are complete English.

That triggered my question how the integration in Thunar works since without the integration your scripts are quite meaningless, since the idea is having a different-colours highlighting hack for Thunar.

Like I said, there have been some unanswered questions therefore I wanted to clarify these prior using your scripts. Asking these questions prior using your scripts means I trust you enough that all your scripts do is just as you wrote or as your GIF shows, and my questions are just things I either do not yet know (like how to integrate it all into Thunar) or did misunderstood (all explained above)
Last edited by Rava on 23 Sep 2021, 12:35, edited 1 time in total.
Reason: removed off-topic parts ^-^;
Cheers!
Yours Rava

User avatar
M. Eerie
Shogun
Shogun
Posts: 338
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#13 by M. Eerie » 23 Sep 2021, 10:55

As explained from the beginning, I've just been gathering info from here and there and implemented a solution that works for me and I wanted to share. Still incomplete as stated, but I will be investigate how to get the job done if it is possible.

There's no hack here. Maybe dirty and tricky as I said, but it integrates with Thunar as easily as you create a custom action from the menu. It's just the same, but only using a documented and existing SendTo menu folder.

Whether the use of "send to --> tag color" is not quite semantically correct and led you to confusion, I don't know, but I think Thunar's "sendto" is an appropriate place, as there are existing actions involving creation of links to the desktop, the side panel, or even custom actions such as "move to parent directory". So, colormarking concept fits in the intended use as is not restricted to copy files to storage devices or send to mail recipients.The reason for using this menu is to avoid polluting the main menu with a lot of distracting colors.

And yes, I'd certainly prefer to remove from the thread what is not on topic.
Cheers!

User avatar
Rava
Contributor
Contributor
Posts: 3006
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc + 4.0 i586 XFCe
Location: Forests of Germany
Contact:

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#14 by Rava » 23 Sep 2021, 12:13

M. Eerie wrote:
23 Sep 2021, 10:55
Whether the use of "send to --> tag color" is not quite semantically correct and led you to confusion, I don't know, but I think Thunar's "sendto" is an appropriate place, as there are existing actions involving creation of links to the desktop, the side panel, or even custom actions such as "move to parent directory". So, colormarking concept fits in the intended use as is not restricted to copy files to storage devices or send to mail recipients.The reason for using this menu is to avoid polluting the main menu with a lot of distracting colors.
Good to know. You are correct that strictly semantically speaking it is wrong, but we Porteus folks all follow the KISS principles, and therefore "send to --> tag color" is the only correct place.
There are other stuff in many "send to" subfolders that are also strictly semantically speaking wrong, but still the correct choice for a nice and clean GUI under the KISS.
Last edited by Rava on 23 Sep 2021, 12:36, edited 1 time in total.
Reason: removed off-topic parts ^-^;
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 3006
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 5.0rc + 4.0 i586 XFCe
Location: Forests of Germany
Contact:

[Solved] Taxonomies in Thunar (Labeling for the poor)

Post#15 by Rava » 23 Sep 2021, 13:47

Finally first saved all your scripts and explanations (with some of the external info you provided in the actual posts, but the ones in your initial post)
I will go through that one large file first to understand all there is about what you created.
I also will save the scripts by themselves of course.

Just one minor suggestion, and it is only a suggestion reflecting my way of coding when one wants to share stuff. (With very small scripts or even one-liners or aliases or bash functions I do not adhere to these rules myself)

But as I can see it for now, what you created it not a mere "small helpful script" but a complex system that needed quite the research to pull it off.

Therefore my 2 suggestions:

Just below the !#/bin/bash or !#/bin/sh put in your name, and e.g the info that under that name you can be found on the Porteus forum. By doing so you not need to share an email address.
Add a version number.

When sharing a more complex software both these things have good reasons for doing so.

Your name shows who was the initial creator. Even when its free (as in freedom and beer) software, the only correct way of forking and / or enhancing software others started is to keep the original creators info in the forks.

And why a version number?
People could just use md5sum to see if a script differs from another, or do a literal

Code: Select all

# diff script1 script2
But neither of these approaches show the user which of these two or several scripts has the higest version number.

One could just use the date as a version number when using the YYYY-MM-DD syntax.
When one would give out more than one version per single day that can be enhanced ito YYYY-MM-DD.1 and YYYY-MM-DD.2

Like I wrote, these are just my suggestions. They make sense to me and help users using scripts and software.

Still it is up to you how you handle your scripts, and it is up to you which coding style you want to adhere to.

Best part of using V2021-09-23 as the version number is that not even you have to look it up which correct version number the script version whatever you currently finished is the correct one.
You only have to remember adding a .1 , .2 et cetera when you would release more than one version of a script a day.
When it is not so you just use the currect date as version number, and it matters not if the one prior version was yesterday, 7 days ago or a months ago.
Even when you would forget about intermediate versions it would not matter, the version number you assigned is still correct.

[/too long a rant about just
Add your username
Add version number
Oh well]
Cheers!
Yours Rava

Post Reply