Sum*_*ukh 11 icons nautilus nautilus-script
上面链接的问题有一个答案,其中包含一个对我有用的脚本。它只需要一点点改进。
它查找具有.jpg、.jpeg、.png、.gif、.icns、.ico扩展名的文件,并将它们设置为找到该文件的文件夹的文件夹图标。它递归地作用于多个文件夹。基本上它会尝试在文件夹内找到一个图像文件,并且它找到的第一个图像被设置为文件夹图标。它适用于许多场景,并且设置此脚本通常是我全新安装后要做的第一件事(因为它很棒)。
可能有几个目录包含大量图像文件,并且该目录中的第一个图像文件可能不太适合作为文件夹图标。
如果它不是基于扩展名,而是基于文件名并针对一个(例如,folder.png)或多个(例如albumart.png cover.png)文件名,那么这个问题就可以解决。
或者更好的是让这两种方法在一个脚本中工作
filenamesJac*_*ijm 10
I might still "elegant it up a bit" but below are the edited versions of the linked ones.
I added a predefined list to the head section:
specs = ["folder.png", "cover.png", "monkey.png"]
Run Code Online (Sandbox Code Playgroud)
and I replaced:
try:
first = min(p for p in os.listdir(folder)
if p.split(".")[-1].lower() in ext)
except ValueError:
pass
Run Code Online (Sandbox Code Playgroud)
by:
fls = os.listdir(folder)
try:
first = [p for p in fls if p in specs]
first = first[0] if first else min(
p for p in fls if p.split(".")[-1].lower() in ext
)
except ValueError:
pass
Run Code Online (Sandbox Code Playgroud)
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.
To be used with the targeted directory as argument:
#!/usr/bin/env python3
import subprocess
import os
import sys
# --- set the list of valid extensions below (lowercase)
# --- use quotes, *don't* include the dot!
ext = ["jpg", "jpeg", "png", "gif", "icns", "ico"]
# --- set the list of preferred filenames
# --- use quotes
specs = ["folder.png", "cover.png", "monkey.png"]
# ---
# retrieve the path of the targeted folder
dr = sys.argv[1]
for root, dirs, files in os.walk(dr):
for directory in dirs:
folder = os.path.join(root, directory)
try:
fls = os.listdir(folder)
first = [p for p in fls if p in specs]
first = first[0] if first else min(
p for p in fls if p.split(".")[-1].lower() in ext
)
except (ValueError, PermissionError):
pass
else:
subprocess.Popen([
"gvfs-set-attribute", "-t", "string",
os.path.abspath(folder), "metadata::custom-icon",
"file://"+os.path.abspath(os.path.join(folder, first))
])
Run Code Online (Sandbox Code Playgroud)
change_icon.pyRun it with the targeted directory as an argument:
python3 /path/to/change_icon.py <targeted_directory>
Run Code Online (Sandbox Code Playgroud)That's it!
python3 /path/to/change_icon.py <targeted_directory>
Run Code Online (Sandbox Code Playgroud)
Create, if it doesn't exist yet, the directory
~/.local/share/nautilus/scripts
Run Code Online (Sandbox Code Playgroud)Copy the script into an empty file, save it in ~/.local/share/nautilus/scripts as set_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
| 归档时间: |
|
| 查看次数: |
1368 次 |
| 最近记录: |