Guest User

Set Folder Icon rightclick

a guest
May 20th, 2017
536
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import subprocess
  3. import os
  4.  
  5. # --- set the list of valid extensions below (lowercase)
  6. # --- use quotes, *don't* include the dot!
  7. ext = ["jpg", "jpeg", "png", "gif", "icns", "ico"]
  8. # ---
  9.  
  10. # retrieve the path of the targeted folder
  11. current = os.getenv("NAUTILUS_SCRIPT_CURRENT_URI").replace("file://", "").replace("%20", " ")
  12. dr = os.path.realpath(current)
  13.  
  14. for root, dirs, files in os.walk(dr):
  15.     for directory in dirs:
  16.         folder = os.path.join(root, directory)
  17.         try:
  18.             first = min(p for p in os.listdir(folder)
  19.                         if p.split(".")[-1].lower() in ext)
  20.         except ValueError:
  21.             pass
  22.         else:
  23.               subprocess.Popen([
  24.                   "gvfs-set-attribute", "-t", "string",
  25.                   os.path.abspath(folder), "metadata::custom-icon",
  26.                   "file://"+os.path.abspath(os.path.join(folder, first))
  27.                   ])
Comments
  • 3946rjking
    100 days
    # text 0.23 KB | 0 0
    1. This script didn't work for me until I changed "gvfs-set-attribute" to "gio", "set" then it worked great. But I am wondering if it would be possible to ad a section to the script to resize pixels and resolution for the image as well
    2.  
Add Comment
Please, Sign In to add comment