4

Pantheon-Files has a feature of assigning color to file/directory names displayed. I want to make a script in Bash/Python to do the same automatically.

4

Low-level sqlite approach

The file-color associations are stored in the ~/.config/marlin/marlin.db sqlite database. You can try to reverse-engineer the format, as far as I have seen, there is one table tags, as seen in the dump:

CREATE TABLE tags (id INTEGER PRIMARY KEY,
                   uri TEXT UNIQUE NOT NULL,
                   color INTEGER DEFAULT 0,
                   tags TEXT NULL,
                   content_type TEXT,
                   modified_time INTEGER DEFAULT 0,
                   dir TEXT );

Update/delete file color

So basically you need to either the color already in the base as in

UPDATE tags set color=1 WHERE uri = 'file:///home/user/test'

changed the color of the file ~/test to yellow (1). Colors seem to be 0 (no color) and 1…9 (yellow, orange, etc. as shown in the file Properties dialog).

If you want to delete the color, you only have to set color=0.

Set file color

If there is no entry for the file specified, you should create it with some housekeeping:

  • id might be NULL as in auto-assigned,
  • uri is the URI of the file of which you want to change the color
  • tags = NULL as in nothing special for now,
  • content_type you might find this with the file utility,
  • modified_time seems to be a simple Unix time stamp,
  • dir I don't really know but the parent directory seems to be a safe bet.

This line seems to work and has set the color of ~/new_file not present in the database before to green (4):

INSERT INTO tags VALUES (NULL, 'file:///home/user/new_file', 4, NULL, 'text/plain', 1481148148, 'file:///home/user');

However, be careful and double-check this with the source code of pantheon-files as this might render your database inconsistent. The relevant source file seems to be pantheon-files-daemon/marlind-tagging.vala.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.