Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to give your scripts unique icons in the windows tray!


  • Please log in to reply
4 replies to this topic
KraZe_EyE
  • Members
  • 85 posts
  • Last active: Nov 12 2015 02:35 PM
  • Joined: 13 Nov 2014

Update: 3/25/15

Includes more information about changing icons.

Code to change a compiled scripts icon. This eliminates the need to use the GUI compiler to choose an icon. Just right click your script and hit compile!

Warning that the linked icon pack is for non commercial use and the colors and sizes included.

Info on how to use windows default icons, see striked out text section below code. (Sorry, can't figure out how to link to specific AHK help section explaining this, help?)

 

 

 

Backstory:

 

So I have 6 to 8 scripts running at any given time and couldn't easily identify them without doing a mouse over hover. After "installing" the quick folder change script (DirMenu.ahk SUPER useful script, see link below) I saw it had a different icon, looking at the code revealed a section that changed the tray icon!

Link to QuickFolderChange / DriMenu
 
I decided to incorporate this into all of my scripts in order to tell them apart.
 
I downloaded this icon pack that had every letter of the alphabet in ten different colors(BLACK, BLUE, GOLD, GREY, ORANGE, PINK, RED, VIOLET, LIGHTGREEN, and DARKGREEN)
It has all of the various sizes an icon can be (16, 24, 32, 48, 64, 128) So it will display correctly in any setting(windows tray, GUI, folder icon, etc).
Please note that this icon pack is not available for commercial use!
 
Its in a .rar archive that you have to unzip into a file directory. Each letter has its own folder, with the various colors of that letter icon contained within. Use winrar or 7-zip http://www.7-zip.org/ to unpack the archive.  (unpacked size is 28MB)
 
I created a folder within the AHK install directory called 'Letter Icons' and then put all the letter folders within that folder. This gives you a consistent file path structure(You can choose any location to store the icon files.) to use when choosing an icon and color. More on this in a moment.
 
Insert the code below code into your script at the beginning before your actual code but after any special modifiers such as:
 
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
 
CODE! V
 
 
; iconx: Change the tray icon displayed for each of your scripts so you can keep track of which is which.
; Also now changes the icon of a compiled script (.exe)  < ICON [I_Icon] >
; Write up by KraZe_EyE Inspired by code seen in DirMenu.ahk (highly recommended)
; -http://www.autohotkey.com/board/topic/91109-favorite-folders-popup-menu-with-gui/

;- http://www.autohotkey.com/board/topic/121982-how-to-give-your-scripts-unique-icons-in-the-windows-tray/
;- http://www.iconarchive.com/show/multipurpose-alphabet-icons-by-hydrattz.html
;  Please note that this icon pack is not available for commercial use!

; If you wish to have a different icon for this script to distinguish it from other scripts in the tray.
; Provide the filepath/name below (leave blank to have it default to the usual 'H' all AHK scripts have).

; COLOR LISTING FILENAMES: BLACK, BLUE, GOLD, GREY, ORANGE, PINK, RED, VIOLET, LIGHTGREEN==lg, DARKGREEN==dg
;							File Directory\*LETTER DESIRED*\COLOR.ico

I_Icon = C:\Program Files\AutoHotkey\Letter Icons\K\grey.ico
ICON [I_Icon]                        ;Changes a compiled script's icon (.exe)
if I_Icon <>
IfExist, %I_Icon%
	Menu, Tray, Icon, %I_Icon%   ;Changes menu tray icon 
 
 

So I_Icon = is the file path we use to select the letter and then color.ico

Assuming you have installed AHK into the default directory AND created a 'Letter Icons' folder the above file path will work as is.

The only thing that will need to be changed is the letter K to your desired letter and the grey.ico into the color you want. The colors are explained in the comments written above, notice the light/dark green icon files are filenamed as 'lg' and 'dg' respectively.

 

IF you do not want the icon to change from the default H that AHK uses, you either don't use this code OR just leave the I_Icon file path blank and it will default to the AHK 'H' icon.

 

If you find you want more unique icons such as shapes or ones you create yourself the process is the same. I would recommend creating a 'Misc Icons' folder within the AHK directory or within the 'Letter Icon' folder. As long as your file path is correct (and the filename is as well) you can use any .ico file as an icon for your scripts.

 

Note: Windows default icons are not necessarily accessible for this purpose(search the help file for 'icon' and read the section relating to A_IconNumber / A_IconFile. You just have to know which number is the icon you want to use!). Download an icon pack with your desired icon and follow the above instructions to use that.

I have run into a letter, I forget which, that didn't have a certain color, in this case the script will again default to AHK's H icon(all letters have all the colors). Double check your I_Icon file path if you default to the AHK 'H'.


Edited by KraZe_EyE, 25 March 2015 - 05:17 PM.


KraZe_EyE
  • Members
  • 85 posts
  • Last active: Nov 12 2015 02:35 PM
  • Joined: 13 Nov 2014

If someone could give this a try and/or comment if my instructions are clear and concise I'd appreciate it!

 

Especially the instructions bit.



garry
  • Spam Officer
  • 3219 posts
  • Last active: Feb 06 2016 09:32 PM
  • Joined: 19 Apr 2005

thank you, works fine ,

made a GUI , needed only  this before show command

;iconx:
;--http://www.autohotkey.com/board/topic/121982-how-to-give-your-scripts-unique-icons-in-the-windows-tray/
;- http://www.iconarchive.com/show/multipurpose-alphabet-icons-by-hydrattz.html
;- https://github.com/JnLlnd/DirMenu-JL   ;- error 404 link broken (?)

I_Icon = C:\M_ICO\Aikawns\K\grey.ico
IfExist, %I_Icon%
  Menu, Tray, Icon, %I_Icon%
;return



KraZe_EyE
  • Members
  • 85 posts
  • Last active: Nov 12 2015 02:35 PM
  • Joined: 13 Nov 2014

 

thank you, works fine ,

made a GUI , needed only  this before show command

;iconx:
;--http://www.autohotkey.com/board/topic/121982-how-to-give-your-scripts-unique-icons-in-the-windows-tray/
;- http://www.iconarchive.com/show/multipurpose-alphabet-icons-by-hydrattz.html
;- https://github.com/JnLlnd/DirMenu-JL   ;- error 404 link broken (?)

I_Icon = C:\M_ICO\Aikawns\K\grey.ico
IfExist, %I_Icon%
  Menu, Tray, Icon, %I_Icon%
;return

Thank you for testing. Did you make a literal GUI? Your code doesn't reflect that..

 

I edited my post and made some changes. I like the iconx name, I'm stealing it :)

Edits included readability as well as changing the code to have a link to this post, the icon pack I used, as well as the DirMenu post that I was inspired from to do this.



garry
  • Spam Officer
  • 3219 posts
  • Last active: Feb 06 2016 09:32 PM
  • Joined: 19 Apr 2005

a small gui example , shows changed icon  ( label iconx )

modified=20150303
;-- show IP-ADDRESS urldownloadtovarx iconx ipaddressx -------------------------------
url=http://www.netikus.net/show_ip.html   ;- to show public IP-address
Adr:= UrlDownloadToVar( URL )             ;- desactivate this when no internetconnection
gosub,iconx
gui,2:color,black
Gui,2:Font,,Fixedsys
Gui,2:add,text,x20 y40 w100 cYellow,IP-ADDRESS
Gui,2:Show,x10 y10 w165 h70
Gui,2:add,Edit,x5 y10 h25 w150 right,%adr%
return
;------------------------------------------
2Guiclose:
exitapp
;------------------------------------------
iconx:
;--http://www.autohotkey.com/board/topic/121982-how-to-give-your-scripts-unique-icons-in-the-windows-tray/
;- http://www.iconarchive.com/show/multipurpose-alphabet-icons-by-hydrattz.html
I_Icon = C:\M_ICO\Aikawns\K\grey.ico
IfExist, %I_Icon%
  Menu, Tray, Icon, %I_Icon%
return
;------------------------------------------
UrlDownloadToVar(URL) {
 WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 WebRequest.Open("GET", URL)
 WebRequest.Send()
 Return WebRequest.ResponseText
}
;=========================================================