Xfce Forum

Sub domains
 

You are not logged in.

#1 2024-01-15 10:58:59

chang-zhao
Member
Registered: 2023-11-20
Posts: 42

[SOLVED] How to quickly "highlight" (color) file in Thunar?

In some folders I have many files that I read /process in no particular order (not according to alphabet or modification time).

I'd like to mark them, e.g. with colors (like "unread", "todo first", "do later" etc.)

Modern Thunar allows to "highlight" files in folder views with different colors for foreground and background.

It could be a very useful feature if it could be done fast, like:

  • right-click -> select menu option. Or

  • select file -> press hotkey

But currently it's a long process that partly defies the purpose of facilitating work:

  1. right-click

  2. select Properties

  3. move the mouse to target "Highlight" tab and click it

  4. select color

  5. click Set Foreground or Set Background

  6. click Apply

  7. click Close

It's kinda tedious to perform all these seven operations just to mark a file, if I want to do that a dozen times a day.

So I'm thinking, is there a way to mark a file that way from CLI?

Then I could make a script and use it with a hotkey or two, or with "Thunar's custom actions".

Last edited by chang-zhao (2024-01-16 02:46:39)

Offline

#2 2024-01-15 11:54:55

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: [SOLVED] How to quickly "highlight" (color) file in Thunar?

Thunar uses gio metadata to store this info.

To set a highlight color:

gio set FOLDER metadata::thunar-highlight-color-background "rgb(x,x,x)"

...and to remove the highlight:

gio set -t unset FOLDER metadata::thunar-highlight-color-background

*Important to note that you have manually refresh the thunar screen for the change to happen visually.

Here is a script I wrote a while back as a proof of concept that you may find helpful:

#!/bin/bash
# $1 can be a color or "unset"

COLOR=$1
case $COLOR in
   red)     COL="rgb(255,0,0)" ;;
   green)   COL="rgb(0,255,0)" ;;
   blue)    COL="rgb(0,0,255)" ;;
esac

# shift to next set of parameters - the folders to affect
shift

# if unset was passed, then remove all highlighting
if [ "$COLOR" == "unset" ]
then
   for FOLDER in $@
   do
      gio set -t unset "$FOLDER" metadata::thunar-highlight-color-background
   done

# otherwise highlight the folders
else
   for FOLDER in $@
   do
      gio set "$FOLDER" metadata::thunar-highlight-color-background "$COL"      
   done
fi

# refresh the thunar window
xdotool key F5

For the custom actions, create them like this:
- Name = Highlight Red
- Submenu = Highlight
- Command = /path/to/script red %F
- Appearance = Directories only
...create one for every color you want and make sure you define the color in the case statement at the top of the script.

And to unset the highlight:
- Name = Unset Highlight
- Submenu = Highlight
- Command = /path/to/script unset %F
- Appearance = Directories only


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2024-01-16 04:34:36

chang-zhao
Member
Registered: 2023-11-20
Posts: 42

Re: [SOLVED] How to quickly "highlight" (color) file in Thunar?

Thank you!

I added `"` around arguments, to process file names with spaces; and set colors and their codes to highlight a few "roles":

  • unread,

  • later,

  • todo.

screenshot

Script:

#!/bin/bash
# $1 is a coloring code or "unset"

COLOR="$1"
case "$COLOR" in
   todo)    COL="rgb(255,230,200)" ;;
   later)   COL="rgb(220,220,220)" ;;
   unread)  COL="rgb(220,255,220)" ;;
esac

# shift to next set of parameters - the files to affect
shift

# if unset was passed, then remove all highlighting
if [ "$COLOR" == "unset" ]
then
   for DO_FILE in "$@"
   do
      gio set -t unset "$DO_FILE" metadata::thunar-highlight-color-background
   done

# otherwise highlight the files
else
   for DO_FILE in "$@"
   do
      gio set "$DO_FILE" metadata::thunar-highlight-color-background "$COL"
   done
fi

# refresh the thunar window
xdotool key F5

menu

Last edited by chang-zhao (2024-01-16 04:46:27)

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.008 seconds, 7 queries executed - Memory usage: 534.8 KiB (Peak: 535.64 KiB) ]