How to set the first picture of every folder as its folder icon?
The question linked above has an answer consisting a script which has been working for me. It just needs a little improvement.
What does it do?
It finds files with .jpg, .jpeg, .png, .gif, .icns, .ico extensions and sets them as the folder icon of the folder in which the file was found. It works on multiple folders, recursively. Basically it tries to find an image file inside the folder, and the first image that it finds is set as a folder icon. It works great for many scenarios, and setting up this script is usually the first thing I do after fresh install (because it's amazing).
What's the problem?
There might be a few directories which contain a of lot of image files and the first image file in that directory might not be well suited to being the folder icon.
What should it do?
Instead of being extension based, if it became filename based and targeted one (for example, folder.png
) or multiple (eg albumart.png
cover.png
) filenames then this problem could be solved.
or better yet make both approaches work in a single script
- Find predefined
filenames
- If found set it as folder icon and move to next folder
- If NOT found then find predefined extension and set it as folder icon and move to next folder
I might still "elegant it up a bit" but below are the edited versions of the linked ones.
What is the difference?
I added a predefined list to the head section:
and I replaced:
by:
so that the script first tries to find (file) matches in the list
specs
, (only) if there are no, it jumps to searching for matching extension, and does the trick if it finds a suitable image.1. The basic version
To be used with the targeted directory as argument:
How to use
change_icon.py
Run it with the targeted directory as an argument:
That's it!
2. The edited right-click option, to be used as a nautilus (right-click) script
To use
Create, if it doesn't exist yet, the directory
Copy the script into an empty file, save it in
~/.local/share/nautilus/scripts
asset_foldericons
(no extension!), and make it executable.If, for some reason you'd like to reset the icons inside a folder to their default icon(s), use the script here