Custom icons script

Discuss and share scripts and script files...
Post Reply
fishgod
Posts: 227
Joined: 03 Feb 2008 00:40
Location: Sankt Augustin (near Bonn), Germany

Custom icons script

Post by fishgod »

I have a new created a new version of this script.
It is now in the
> Mega ScriptsPack <

The new version depends on other scripts also contained in this package.


While tags are fine, but xy-only I needed a way to tag folders system-wide.
My solution are custom-folder-icons, with relative paths in "desktop.ini"-files this works also on network-share if the icon is also on the share.

I use custom-folder-icons for example to distinguish DVDs from 1080p-movies on my net-share. (I don't like to put these informations in the folder-name)
(Another nice place to use this is the "Programme"-folder, i put special icons for opensource-software and other types there :))

This is a small script to give a folder a custom icon, I load it from the catalog and get a nice menu:

Code: Select all

"HD 1080p"
  $path = <curitem>;
  call writefile($path.'\desktop.ini', <<<EOF
[.ShellClassInfo]
IconFile=..\..\.icons\HD 1080p.ico
IconIndex=0
EOF
   );
  run 'attrib +h desktop.ini', $path; //feel free to use system-attribute here for hiding
  run 'attrib +r "'.$path.'"';

"DVD"
  $path = <curitem>;
  call writefile($path.'\desktop.ini', <<<EOF
[.ShellClassInfo]
IconFile=..\..\.icons\DVD.ico
IconIndex=0
EOF
   );
  run 'attrib +h desktop.ini', $path;
  run 'attrib +r "'.$path.'"';
To get this working you need the icons in the appropiate folders, so feel free to add more entries (I have nine).
(it's maybe not perfect, but works fine for me, and I simply wanted to share it with you folks)
Last edited by fishgod on 27 Jan 2010 21:30, edited 1 time in total.
Operating System: Win10 x64 / Win11 x64 / almost allways newest XY-beta
totally XYscripting-addicted

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Custom icons script

Post by TheQwerty »

A couple suggestions...
1) There's no reason to make use of the "call" command, you can just put WriteFile...
2) But really it would be even easier to use SetKey.

I took some liberties and this should work about the same for you:

Code: Select all

 
"DVD"
 	Global($iconFile);
 	$iconFile = "..\..\.icons\DVD.ico";
 	Sub("_customizeFolder");
 
"HD 1080p : _customizeFolder"
	$cnt = GetInfo("CountSelected");
	End($cnt > 1, "This script only supports customizing 1 folder at a time.");
	
	//If 1 item is selected and it is a Drive or Directory: use it's path.
	//Otherwise use the current path.
	$cd = ($cnt == 1) ? Report("{dir <curitem>|<curpath>|<curitem>}", 1) : "<curpath>";
	
	Global($iconFile, $iconIdx);
	$iconFile = $iconFile Like "" ? "..\..\.icons\HD 1080p.ico" : $iconFile;
	$iconIdx = $iconIdx Like "" ? 0 : $iconIdx;
	
	SetKey($iconFile, "IconFile", ".ShellClassInfo", "$cd\desktop.ini");
	SetKey($iconIdx, "IconIndex", ".ShellClassInfo", "$cd\desktop.ini");
	
	Run("attrib +H ""$cd\desktop.ini""");
	Run("attrib +R ""$cd""");
You might even want to include commands $484 (Rebuild the tree) and #1001 (Refresh Tree & List) at the end so that the changes are visible right after running the script.

fishgod
Posts: 227
Joined: 03 Feb 2008 00:40
Location: Sankt Augustin (near Bonn), Germany

Re: Custom icons script

Post by fishgod »

nice optimalization :)
I allready thought about putting things together to not copy the whole script for every entry, but my script was a fast hack in the first place :D posted here to become better and more usable for other users.

But if it is a drive, the "desktop.ini"-method won't work (cause the root is not a really a folder its simply the root).
But you can use an "autorun.inf"-file which has (unfortunately) another format, so it look like this:

Code: Select all

[autorun]
icon="path\to\file.ico"
Don't know how to implement the switch here, but I think, drives do not change (or become created) so often thats would be adequate to spende much time in creating a script for this :D
Operating System: Win10 x64 / Win11 x64 / almost allways newest XY-beta
totally XYscripting-addicted

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Custom icons script

Post by TheQwerty »

fishgod wrote:But if it is a drive, the "desktop.ini"-method won't work (cause the root is not a really a folder its simply the root).
Yeah I realized that but didn't really care. Figured it would be a case that wouldn't actually be used. :P

You could replace the drive value with an empty string and add an end if $cd Like "" right after that line.
Or detect it and change a few more variables/call a separate sub. But as you said it didn't seem worth it.

tryforsure
Posts: 23
Joined: 29 Jun 2009 13:56

Re: Custom icons script

Post by tryforsure »

thanks a lot for this script, its very useful!
now i am busy tagging my folders. :lol:

fishgod
Posts: 227
Joined: 03 Feb 2008 00:40
Location: Sankt Augustin (near Bonn), Germany

Re: Custom icons script

Post by fishgod »

tryforsure wrote:thanks a lot for this script, its very useful!
now i am busy tagging my folders. :lol:
You better should consider using the newest version which I posted here:
http://xyplorer.com/xyfc/viewtopic.php?f=7&t=4619
Operating System: Win10 x64 / Win11 x64 / almost allways newest XY-beta
totally XYscripting-addicted

Post Reply