AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Custom FavIcons

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
jaco0646
Guest





PostPosted: Wed Feb 08, 2006 6:47 am    Post subject: Custom FavIcons Reply with quote

I have a lot of links in my IE favorites, and I really like to have favicons for them instead of the IE default (i.e. blue "e" on a blank page). Programs like "FavOrg" and "FavIconizer" do a good job of updating favicons from websites that provide them, but many of my favorite websites don't have favicons. Instead, I keep a folder of my own icons for these websites. The problem is automating the application of these custom favicons.

So I came up with a script that seems to work. It just requires that the icons' names match the names of their corresponding favorite links. I'd like to know if this works for other people as well.

Code:
IfExist, %TEMP%\URL.txt
   FileDelete, %TEMP%\URL.txt
IfExist, %TEMP%\ICO.txt
   FileDelete, %TEMP%\ICO.txt
IfExist, %TEMP%\SbK.txt
   FileDelete, %TEMP%\SbK.txt
RegRead, FavoritesFolder, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, Favorites
FileSelectFolder, IconsFolder, , 0, Locate favicons folder:
IfEqual, IconsFolder,
   ExitApp
Loop, %IconsFolder%\*.ico
{
   StringTrimRight, TrimmedICO, A_LoopFileName, 4
   FileAppend, %TrimmedICO%`n, %TEMP%\ICO.txt
}
FileRead, SplitICO, %TEMP%\ICO.txt
Loop, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites, 2, 1
{
   SubKey = %A_LoopRegSubKey%\%A_LoopRegName%
   StringTrimLeft, TrimmedDir, SubKey, 70
   FileAppend, %TrimmedDir%`n, %TEMP%\SbK.txt
}
Loop, Read, %TEMP%\SbK.txt
{
   IfNotExist, %FavoritesFolder%%A_LoopReadLine%
      RegDelete, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites%A_LoopReadLine%
}
FileDelete, %TEMP%\SbK.txt
FileAppend, `n, %TEMP%\SbK.txt
Loop, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites, 2, 1
{   
   SubKey = %A_LoopRegSubKey%\%A_LoopRegName%
   StringTrimLeft, TrimmedDir, SubKey, 70
   FileAppend, %TrimmedDir%`n, %TEMP%\SbK.txt
}
Index = 0
BlockInput, Send
Loop, Read, %TEMP%\SbK.txt
{
   SubFolder = %A_LoopReadLine%
   MsgBox, 36, Folder, Search in Favorites%SubFolder%?, 10
      IfMsgBox, No
         continue
   Loop, %FavoritesFolder%%SubFolder%\*.url
   {
      StringTrimRight, TrimmedURL, A_LoopFileName, 4
      FileAppend, %TrimmedURL%`n, %TEMP%\URL.txt
   }
   Loop, Read, %TEMP%\URL.txt
   {
      IfInString, SplitICO, %A_LoopReadLine%
      {
         EnvAdd, Index, 1
         Run, properties "%FavoritesFolder%%SubFolder%\%A_LoopReadLine%.url"
         WinWaitActive, %A_LoopReadLine% Properties
         ControlClick, Button2, ahk_class #32770
         WinWaitActive, Change Icon
         SendRaw, %IconsFolder%\%A_LoopReadLine%.ico
         ControlClick, Button3, ahk_class #32770
         Sleep, 500
         IfWinExist, Change Icon
         {
            ControlClick, Button3, ahk_class #32770
            WinWaitClose, Change Icon
         }
         ControlClick, Button4, ahk_class #32770
         WinWaitClose, %A_LoopReadLine% Properties
      }
      Else continue
   }
   FileDelete, %TEMP%\URL.txt
}
FileDelete, %TEMP%\ICO.txt
FileDelete, %TEMP%\SbK.txt
MsgBox, 64, Done, The number of favicons updated is %Index%.


The first message box command was mainly for testing purposes, and can be remarked out to speed up the process. On my computer, it seemed to take a little time for each updated icon to be assimilated by windows, thus the "Sleep, 500." Other machines may need more or less time.

P.S. I know it's messy because it opens the properties page for each favorite. I couldn't think of another way to do this. My main concern is just that it works.
Back to top
JSLover



Joined: 20 Dec 2004
Posts: 541
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Wed Feb 08, 2006 7:19 am    Post subject: Re: Custom FavIcons Reply with quote

jaco0646 wrote:
I know it's messy because it opens the properties page for each favorite. I couldn't think of another way to do this.

...a .url file is just an .ini file that acts different when run...

This should write to the file...(making windows refresh is another matter)...

Code:
IniWrite, %IconsFolder%\%A_LoopReadLine%.ico
        , %FavoritesFolder%%SubFolder%\%A_LoopReadLine%.url
        , InternetShortcut, IconFile

...use Winspector to watch messages & find out what message gets sent when you open a .url file's properties (manually) & click OK or Apply...

Code:
IfEqual, IconsFolder,
   ExitApp

...should be...

Code:
if IconsFolder=
   ExitApp

...(yes it will work either way, but the 2nd looks better {I hate the "IfEqual/Less/Greater/etc" versions})...

Code:
EnvAdd, Index, 1

...should be...

Code:
i++

...I wasn't going to...but here's my optimized code...UNTESTED...I didn't run your version or my version, but my edits appear that they would do the same thing yours does, but more efficiently...

Code:
;*removed* Temp files not needed (other one could probably be written around too)
;IfExist, %TEMP%\URL.txt
;   fileexists=1
;IfExist, %TEMP%\ICO.txt
;   fileexists=1
IfExist, %TEMP%\SbK.txt
   fileexists=1
if fileexists
{
   msgbox, 20, , Error: Needed temp files already exist...Overwrite?
   IfMsgBox, No
      ExitApp
}
;FileDelete, %TEMP%\URL.txt
;FileDelete, %TEMP%\ICO.txt
FileDelete, %TEMP%\SbK.txt
RegRead, FavoritesFolder, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, Favorites
FileSelectFolder, IconsFolder, , 0, Locate favicons folder:
If IconsFolder=
   ExitApp
Loop, %IconsFolder%\*.ico
{
   ;*note* You should use SplitPath...
   StringTrimRight, TrimmedICO, A_LoopFileName, 4
   ;*removed*
   ;FileAppend, %TrimmedICO%`n, %TEMP%\ICO.txt
   SplitICO:=SplitICO TrimmedICO "`n"
}
;*removed*
;FileRead, SplitICO, %TEMP%\ICO.txt
Loop, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites, 2, 1
{
   SubKey = %A_LoopRegSubKey%\%A_LoopRegName%
   StringTrimLeft, TrimmedDir, SubKey, 70
   ;*removed*
   ;FileAppend, %TrimmedDir%`n, %TEMP%\SbK.txt
   IfNotExist, %FavoritesFolder%%TrimmedDir%
      RegDelete, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites%TrimmedDir%
}
;*removed*
/*
Loop, Read, %TEMP%\SbK.txt
{
   IfNotExist, %FavoritesFolder%%A_LoopReadLine%
      RegDelete, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites%A_LoopReadLine%
}
FileDelete, %TEMP%\SbK.txt
*/
FileAppend, `n, %TEMP%\SbK.txt
Loop, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites, 2, 1
{   
   SubKey = %A_LoopRegSubKey%\%A_LoopRegName%
   StringTrimLeft, TrimmedDir, SubKey, 70
   FileAppend, %TrimmedDir%`n, %TEMP%\SbK.txt
}
BlockInput, Send
Loop, Read, %TEMP%\SbK.txt
{
   SubFolder = %A_LoopReadLine%
   MsgBox, 36, Folder, Search in Favorites%SubFolder%?, 10
      IfMsgBox, No
         continue
   Loop, %FavoritesFolder%%SubFolder%\*.url
   {
      StringTrimRight, TrimmedURL, A_LoopFileName, 4
;*removed*
/*
      FileAppend, %TrimmedURL%`n, %TEMP%\URL.txt
   }
   Loop, Read, %TEMP%\URL.txt
   {
      IfInString, SplitICO, %A_LoopReadLine%
*/
      IfInString, SplitICO, %TrimmedURL%
      {
         i++
         ;*removed*
         /*
         Run, properties "%FavoritesFolder%%SubFolder%\%A_LoopReadLine%.url"
         WinWaitActive, %A_LoopReadLine% Properties
         ControlClick, Button2, ahk_class #32770
         WinWaitActive, Change Icon
         SendRaw, %IconsFolder%\%A_LoopReadLine%.ico
         ControlClick, Button3, ahk_class #32770
         Sleep, 500
         IfWinExist, Change Icon
         {
            ControlClick, Button3, ahk_class #32770
            WinWaitClose, Change Icon
         }
         ControlClick, Button4, ahk_class #32770
         WinWaitClose, %A_LoopReadLine% Properties
         */
         IniWrite, %IconsFolder%\%TrimmedURL%.ico
                 , %FavoritesFolder%%SubFolder%\%TrimmedURL%.url
                 , InternetShortcut, IconFile
      }
      ;*removed* At end of loop continue is redundant...
      ;Else continue
   }
   ;FileDelete, %TEMP%\URL.txt
}
;FileDelete, %TEMP%\ICO.txt
FileDelete, %TEMP%\SbK.txt
MsgBox, 64, Done, The number of favicons updated is %i%.

_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
jaco0646
Guest





PostPosted: Thu Feb 09, 2006 2:29 am    Post subject: Reply with quote

Thank you. That was very helpful (obviously I'm a beginner at this). I tried Winspector once, but found it pretty confusing. If you have time to show me exactly how you got those IniWrite commands, I would appreciate it.

The only line I'm not sure of is:
Code:
SplitICO:=SplitICO TrimmedICO "`n"

Should the second "SplitICO" be there? Also, could a similar line replace the last FileAppend to get rid of the last temp file?

Thanks again for your help.
Back to top
JSLover



Joined: 20 Dec 2004
Posts: 541
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Thu Feb 09, 2006 5:19 am    Post subject: Reply with quote

jaco0646 wrote:
If you have time to show me exactly how you got those IniWrite commands, I would appreciate it.

...I just know they (.url files) are .ini files...open notepad, open IE's favorites menu, click & hold & drag a favorite to notepad (drag down to the notepad taskbar button & hold, then up to notepad {if notepad went behind IE when you 1st clicked the favorite})...that will show you the inside of a .url file...
    [InternetShortcut]
    URL=http://autohotkey.com
    Modified=<string of weird chars>
    IconFile=http://autohotkey.com/favicon.ico
    IconIndex=1
...from there you just treat it like an .ini file...you see what section name it uses (InternetShortcut) & what value name it uses to store the icon (IconFile). The docs on FileCreateShortcut mention how to create a .url file too...so it's the same to modify one, you just modify what needs changed. It helps if you already know about .ini files, cuz they are basically the same (just serve different purposes).

jaco0646 wrote:
Should the second "SplitICO" be there?

...from your code, you loop & write putting everything in the file...then you slurp everything in the file into SplitICO...that's what this attempts to do...keep adding to SplitICO without a temp file...

Code:
TrimmedICO=test
SplitICO:=SplitICO TrimmedICO "`n"
;SplitICO now equals: test`n

TrimmedICO=test2
SplitICO:=SplitICO TrimmedICO "`n"
;SplitICO now equals: test`ntest2`n

...without the 2nd SplitICO...

Code:
TrimmedICO=test
SplitICO:=TrimmedICO "`n"
;SplitICO now equals: test`n

TrimmedICO=test2
SplitICO:=TrimmedICO "`n"
;SplitICO now equals: test2`n

...the := operator only turns on expressions...you may be thinking of a .= operator...in that case you would be right...but AHK don't have that yet.

jaco0646 wrote:
Also, could a similar line replace the last FileAppend to get rid of the last temp file?

...certainly...but after all that editing I got tired...I might post the relevant edits...OK...starting from my last post, replace the section between...

Code:
FileAppend, `n, %TEMP%\SbK.txt
;...&...
   MsgBox, 36, Folder, Search in Favorites%SubFolder%?, 10

...with...

Code:
;*removed*
;FileAppend, `n, %TEMP%\SbK.txt
Loop, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites, 2, 1
{   
   SubKey = %A_LoopRegSubKey%\%A_LoopRegName%
   StringTrimLeft, TrimmedDir, SubKey, 70
;*removed*
/*
   FileAppend, %TrimmedDir%`n, %TEMP%\SbK.txt
}
BlockInput, Send
Loop, Read, %TEMP%\SbK.txt
{
*/
   BlockInput, Send
   SubFolder = %TrimmedDir%
   MsgBox, 36, Folder, Search in Favorites%SubFolder%?, 10

...remember to remove the code at the top that checks for the temp file any other code that mentions/writes/deletes it.
_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
jaco0646
Guest





PostPosted: Fri Feb 10, 2006 1:53 am    Post subject: refresh Reply with quote

OK, I got a chance to redo the script with all the help you've given me. It works well; but as you guessed, the problem now is getting Windows to refresh the favicons after the IniWrite command.

Code:
RegRead, FavoritesFolder, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, Favorites
FileSelectFolder, IconsFolder, , 0, Locate favicons folder:
If IconsFolder=
   ExitApp
Loop, %IconsFolder%\*.ico
{
   SplitPath, A_LoopFileName, , , , TrimmedIco
   SplitICO:=SplitICO TrimmedICO "`n"
}
Loop, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites, 2, 1
{
   SubKey = %A_LoopRegSubKey%\%A_LoopRegName%
   StringTrimLeft, TrimmedDir, SubKey, 70
   SubFolder:=SubFolder TrimmedDir "`n"
   IfNotExist, %FavoritesFolder%%TrimmedDir%
      RegDelete, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Favorites%TrimmedDir%
}
Loop, Parse, SubFolder, `n
{
   Loop, %FavoritesFolder%%A_LoopField%\*.url
   {
      SplitPath, A_LoopFileName, , , , TrimmedURL
      IfInString, SplitICO, %TrimmedURL%
      {
         i++
         IniWrite, 31`,%IconsFolder%\%TrimmedURL%.ico
                 , %FavoritesFolder%%A_LoopField%\%TrimmedURL%.url
                 , {5CBF2787-48CF-4208-B90E-EE5E5D420294}, Prop25
      }
   }
}
MsgBox, 64, Done, The number of favicons updated is %i%.


I also changed what's written to the URL files, since I'm running the IE7 beta on this machine, which stores the favicon information a little differently. I've run the program a few times, and sometimes all the icons get refreshed, sometimes none, and sometimes part of them.

P.S. How simple did this script turn out to be after the mess I started with?! Sheesh.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group