Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import subprocess
- import os
- # --- set the list of valid extensions below (lowercase)
- # --- use quotes, *don't* include the dot!
- ext = ["jpg", "jpeg", "png", "gif", "icns", "ico"]
- # ---
- # retrieve the path of the targeted folder
- current = os.getenv("NAUTILUS_SCRIPT_CURRENT_URI").replace("file://", "").replace("%20", " ")
- dr = os.path.realpath(current)
- for root, dirs, files in os.walk(dr):
- for directory in dirs:
- folder = os.path.join(root, directory)
- try:
- first = min(p for p in os.listdir(folder)
- if p.split(".")[-1].lower() in ext)
- except ValueError:
- 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))
- ])
Add Comment
Please, Sign In to add comment