QuickLinks (Menu by folder)

Post your working scripts, libraries and tools
AHK_user
Posts: 406
Joined: 04 Dec 2015, 14:52
Location: Belgium

QuickLinks (Menu by folder)

23 Oct 2019, 15:32

This code is my second adaptation of QuickLinks.ahk, by Jack Dunning.
http://www.computoredge.com/AutoHotkey/AutoHotkey_Quicklinks_Menu_App.html
It is a usefull script, it takes a directory and uses it to make a menu of shortcuts.
This makes it easy to add and remove links in the menu, just change the links in the directory, even a user that does not understands ahk can use and modify the menu.

My first adaptation is made because the original script did not handled subfolders within subfolders by looping inside the directory and searching the first file that contained "\%A_ThisMenu%\%A_ThisMenuItem%" .

Recently it became possible to call functions with parameters with a menuitem.
This makes the handling of subfolders within subfolders even more simple, so the code is short and usefull.
(BoundRun := Func("Run").Bind(A_Loopfilefullpath))

When no %A_ScriptDir%\Links folder is found, it will create it with a shortcut to itself, so you get a menu of one item.

Previous limitation is fixed, the subfolders may not have the same name now

Special thanks to swagfag, who taught me how to use a BoundFunc Object for menus.

Updates 2019-10-24:
- Added name of menu as variable
- Changed functions to V2 compatible
- Submenu's with the same name are allowed now

Updates 2019-12-9:
- Changed Icon_Add function to check if icon is present.
- Changed Icon_Add function to be more flexible.

Version for ahk V2:
viewtopic.php?f=83&t=96573&hilit=quicklinks

Code: Select all

;
; This code is an adaptation of QuickLinks.ahk, by Jack Dunning.
; http://www.computoredge.com/AutoHotkey/AutoHotkey_Quicklinks_Menu_App.html
; Update 2019-10-24:
;- Added name of menu as variable 
;- Changed functions to V2 compatible
;- Submenu's with the same name are allowed now

#NoEnv
#SingleInstance, Force

QL_CreateMenu()

Space::
QL_Show()
return

QL_CreateMenu(QL_Link_Dir := "Links") { ; Just run it one time at the start.
	If !InStr(QL_Link_Dir, "\"){
		QL_Link_Dir := A_ScriptDir "\" QL_Link_Dir 
	}
	
	SplitPath, QL_Link_Dir,QL_Menu
	
	If !FileExist(QL_Link_Dir){
		FileCreateDir, %QL_Link_Dir%
	}
	FileCreateShortcut, %QL_Link_Dir%, %QL_Link_Dir%\%QL_Menu%.lnk
	
	Loop, %QL_Link_Dir%\*.*, 1 , 1
	{	
		if InStr(A_LoopFileAttrib, "H") or InStr(A_LoopFileAttrib, "R"),  or InStr(A_LoopFileAttrib, "S") ;Skip any file that is H, R, or S (System).
			continue
		
		Folder1  := RegExReplace(A_Loopfilefullpath, "(.*\\[^\\]*)\\([^\\]*)\\([^\\]*)", "$2")
		Folder1Menu  := QL_Menu StrReplace(StrReplace(RegExReplace(A_Loopfilefullpath, "(.*\\[^\\]*\\[^\\]*)\\([^\\]*)", "$1"), QL_Link_Dir), "\")
		Folder2Menu  := QL_Menu StrReplace(StrReplace(RegExReplace(A_Loopfilefullpath, "(.*\\[^\\]*)\\([^\\]*)\\([^\\]*)", "$1"), QL_Link_Dir), "\")
		
		BoundRun := Func("Run").Bind(A_Loopfilefullpath)
		Linkname := StrReplace(A_LoopFileName, ".lnk")
		
		Menu, %Folder1Menu%, Add, %Linkname% , %BoundRun%
		Icon_Add(Folder1Menu,Linkname,A_LoopFileFullPath) ; icon
		Menu , %Folder2Menu%, Add, %Folder1%, :%Folder1Menu% ; Create submenu
		Menu , %Folder2Menu% , Icon , %Folder1% , C:\Windows\syswow64\SHELL32.dll , 5 ; icon for folder
	}
	return
}

QL_Show(Link_Name:= "Links") {
	Menu, %Link_Name%, Show
}

Run( a) {
	run, %a%
}

Icon_Add(menuitem,submenu,LoopFileFullPath){ ; add icon based on extention or name
	If InStr(LoopFileFullPath, ".lnk"){
		FileGetShortcut,%LoopFileFullPath% ,File, , , , OutIcon, OutIconNum
		if (OutIcon!=""){
			Menu, %menuitem%, Icon, %submenu%, %OutIcon%,%OutIconNum%
			return
		}
	}
	Else{
		File := LoopFileFullPath
	}
	
	RegExReplace(File,"\.", "",Number_Dots) ;counts the dots
	Extension  := RegExReplace(File, "([^\.]*)(\.[^\.]*).*", "$2")
	Extension2  := RegExReplace(LoopFileFullPath, "([^\.]*)(\..*)", "$2")
	Icon_nr = 0
	If (Extension = ".exe"){
		Menu, %menuitem%, Icon, %submenu%, %file%,1
		return
	}
	
	IconFile := StrSplit(getExtIcon(StrReplace(Extension, ".")), ",")
	
	If InStr(Extension, "\"){
		Menu, %menuitem%, Icon, %submenu%, C:\Windows\syswow64\SHELL32.dll , 5
	}
	Else If (Extension = ".ahk")
		Menu, %menuitem%, Icon, %submenu%, autohotkey.exe,2
	Else If (Extension = ".jpg")
		Menu, %menuitem%, Icon, %submenu%, %A_Windir%\system32\SHELL32.dll, 140,
	Else If (Extension = ".pdf" and FileExist(A_ScriptDir "\Icons\PDF.ico"))
		Menu, %menuitem%, Icon, %submenu%, %A_ScriptDir%\Icons\PDF.ico
	Else If InStr(Extension,  ".xls") and FileExist(A_ScriptDir "\Icons\xlicons.exe")
		Menu, %menuitem%, Icon, %submenu%, %A_ScriptDir%\Icons\xlicons.exe, 0
	Else If InStr(Extension,  ".doc") and FileExist(A_ScriptDir "\Icons\wordicon.exe")
		Menu, %menuitem%, Icon, %submenu%, %A_ScriptDir%\Icons\wordicon.exe, 0
	Else If InStr(Extension,  ".ppt") and FileExist(A_ScriptDir "\Icons\ppticon.exe")
		Menu, %menuitem%, Icon, %submenu%, %A_ScriptDir%\Icons\ppticon.exe, 0
	Else If InStr(A_LoopFileFullPath, ".website") and FileExist(A_ScriptDir "\Icons\ielowutil.exe")
		Menu, %menuitem%, Icon, %submenu%, %A_ScriptDir%\Icons\ielowutil.exe, 0
	Else If (Extension = ".txt")
		Menu, %menuitem%, Icon, %submenu%, C:\Windows\syswow64\Notepad.exe , 0
	Else If (Extension = ".pro")
		Menu, %menuitem%, Icon, %submenu%, C:\Windows\syswow64\Notepad.exe , 0
	Else If (Extension2 = ".url") and InStr(A_LoopFileLongPath,"Windchill") and FileExist(A_ScriptDir "\Icons\Windchill.ico"){
		Menu, %menuitem%, Icon, %submenu%, %A_ScriptDir%\Icons\Windchill.ico	
	}
	Else If (IconFile[1]!=""){
		Menu, %menuitem%, Icon, %submenu%, % IconFile[1] ,  % IconFile[2] 
		return
	}
    ; Find hidden icons in the following directory: C:\Windows\Installer
	Return
}

getExtIcon(Ext) {
   I1 := I2:= ""
   RegRead, from, HKEY_CLASSES_ROOT, .%Ext%
   RegRead, DefaultIcon, HKEY_CLASSES_ROOT, %from%\DefaultIcon
   StringReplace, DefaultIcon, DefaultIcon, `",,all
   StringReplace, DefaultIcon, DefaultIcon, `%SystemRoot`%, %A_WinDir%,all
   StringReplace, DefaultIcon, DefaultIcon, `%ProgramFiles`%, %A_ProgramFiles%,all
   StringReplace, DefaultIcon, DefaultIcon, `%windir`%, %A_WinDir%,all
   StringSplit, I, DefaultIcon, `,
Return I1 "," IndexOfIconResource( I1, RegExReplace(I2, "[^\d]+")  )
}

IndexOfIconResource(Filename, ID){
    hmod := DllCall("GetModuleHandle", "str", Filename, "PTR")
    ; If the DLL isn't already loaded, load it as a data file.
    loaded := !hmod
        && hmod := DllCall("LoadLibraryEx", "str", Filename, "PTR", 0, "uint", 0x2)
    
    enumproc := RegisterCallback("IndexOfIconResource_EnumIconResources","F")
    VarSetCapacity(param,12,0)
    NumPut(ID,param,0)
    ; Enumerate the icon group resources. (RT_GROUP_ICON=14)
    DllCall("EnumResourceNames", "uint", hmod, "uint", 14, "uint", enumproc, "PTR", &param)
    DllCall("GlobalFree", "PTR", enumproc)
    
    ; If we loaded the DLL, free it now.
    if loaded
        DllCall("FreeLibrary", "PTR", hmod)
    
    return NumGet(param,8) ? NumGet(param,4) : 0
}

ResourceIdOfIcon_EnumIconResources(hModule, lpszType, lpszName, lParam){
    index := NumGet(lParam+4)
    if (index = NumGet(lParam+0))
    {   ; for named resources, lpszName might not be valid once we return (?)
        ; if (lpszName >> 16 == 0), lpszName is an integer resource ID.
        NumPut(lpszName, lParam+4)
        NumPut(1, lParam+8)
        return false    ; break
    }
    NumPut(index+1, lParam+4)
    return true
}
QuickLinks.png
QuickLinks.png (39.99 KiB) Viewed 9806 times
Last edited by AHK_user on 17 Aug 2022, 14:19, edited 6 times in total.
User avatar
sumon
Posts: 32
Joined: 01 Oct 2013, 14:05
Location: Stockholm, Sweden

Re: QuickLinks (Menu by folder)

24 Oct 2019, 09:54

Very cool! I think this can be useful.

One thing I noticed though, is that I would want to be able to pass an input parameter (the folder for which to create a menu) and return the menu name as an output of that function. That way, the QL_Show can be called using that parameter (right now, the menu name is always "Links").
AHK_user
Posts: 406
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: QuickLinks (Menu by folder)

24 Oct 2019, 14:56

sumon wrote:
24 Oct 2019, 09:54
Very cool! I think this can be useful.

One thing I noticed though, is that I would want to be able to pass an input parameter (the folder for which to create a menu) and return the menu name as an output of that function. That way, the QL_Show can be called using that parameter (right now, the menu name is always "Links").
Thanks :D

I have added as parameter the linkfolder, this gives you even more flexibility, the name of the menu is the same as the name of the folder so the return is not necessary.
I also cleaned up the legacy syntax so it should also work in AHK V2.

I use it a lot, I actually like to identify one key as a "script key" (XButton1 is preferred), that is used to display a menu to access usefull scripts based on the active program and selection.
This Link menu displays when I press this key on the taskbar.
AHK_user
Posts: 406
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: QuickLinks (Menu by folder)

24 Oct 2019, 15:20

New update, I fixed the problem of not allowing subfolders with the same name.

One thing I am still wondering, would it be possible to remove the Run(a) function and directy create a Boundobject with the standard Run function?
godofOOF
Posts: 27
Joined: 22 Dec 2018, 06:03

Re: QuickLinks (Menu by folder)

07 Dec 2019, 10:03

i keep getting a cant load icon error
burque505
Posts: 1660
Joined: 22 Jan 2017, 19:37

Re: QuickLinks (Menu by folder)

07 Dec 2019, 17:25

@AHK_user , this is great stuff. Definitely a startup script for me from now on. This will save me a lot of time every single day.

(Thanks to @jack dunning as well, of course!)

I just noticed you can add accelerator keys.

The menu itself with shortcuts added:
example.PNG
example.PNG (7.11 KiB) Viewed 9285 times
The "Links" folder showing shortcuts:
example 2.PNG
example 2.PNG (8.78 KiB) Viewed 9285 times
Adding accelerator to Amazon link:
example3.PNG
example3.PNG (35.93 KiB) Viewed 9285 times
Je wordt hartstikke bedankt!!!!

Best regards,
burque505
AHK_user
Posts: 406
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: QuickLinks (Menu by folder)

09 Dec 2019, 06:41

godofOOF wrote:
07 Dec 2019, 10:03
i keep getting a cant load icon error
If you read the code, you can see that I use a subfolder that holds some icons for me.
(You can normally find them in C:\Windows\Installer)

I modified the code a little bit, normally you would not recieve an error anymore, it will just not show the icon if not found.

If somebody knows a nice code to directly use the icon of the file, feel free to share it.
User avatar
jackdunning
Posts: 126
Joined: 01 Aug 2016, 18:17
Facebook: https://www.facebook.com/ComputorEdgeEBooks/posts
Contact:

Re: QuickLinks (Menu by folder)

09 Dec 2019, 15:07

If you check out the script QuickLinks.ahk script at the ComputorEdge Free AutoHotkey Scripts page, you'll find a number of different techniques for adding icons to the menu items. It's been a while but the line:

Code: Select all

IfInString, QL_OutTarget, exe, Menu, %QL_MainMenu%, Icon, %QL_NewName%, %QL_OutTarget%, 1
takes the icon from the Windows shortcut for EXE targets.

The blog "Using Unique Icons for Specific Windows Shortcuts" might help.
AHK_user
Posts: 406
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: QuickLinks (Menu by folder)

09 Dec 2019, 17:13

jackdunning wrote:
09 Dec 2019, 15:07
If you check out the script QuickLinks.ahk script at the ComputorEdge Free AutoHotkey Scripts page, you'll find a number of different techniques for adding icons to the menu items. It's been a while but the line:

Code: Select all

IfInString, QL_OutTarget, exe, Menu, %QL_MainMenu%, Icon, %QL_NewName%, %QL_OutTarget%, 1
takes the icon from the Windows shortcut for EXE targets.

The blog "Using Unique Icons for Specific Windows Shortcuts" might help.
Thanks for the tips, Jack, I feel honoured to get a reply from you, I learned a lot of your examples.

I added 3 extra icon retrieval methods as improvements:
- Retrieval of the icons with the function FileGetShortcut, It appears only to work when you changed the icon of the link, but can be usefull in that way.
- Using the exe file, also seems to works quite well.
- I have also added another function that should try to retrieve the icons, this should eliminate the need to retrieve the icons manually in a subfolder. This works well, except for txt files, probably the iconnumber is wrong in that case... (source: https://autohotkey.com/board/topic/87161-path-icon/)
User avatar
jackdunning
Posts: 126
Joined: 01 Aug 2016, 18:17
Facebook: https://www.facebook.com/ComputorEdgeEBooks/posts
Contact:

Windows Trick for Adding Embedded Folder/Shortcut Icons to QuickLinks Menus

26 Feb 2020, 16:35

I've dropped the IfInString command in favor of the Switch command for adding icons to the menu items. It uses the embedded folder/shortcut icons, when available, and eventually defaults to a single option. You can find the code at "Windows Trick for Adding Embedded Folder Icons to QuickLinks Menus."

Image

It adds icons to menu items according to the following priorities:

  1. Check the Desktop.ini file for embedded folder icons.
  2. Check Windows shortcuts for embedded icons.
  3. If the shortcut targets a program, use the program icon.
  4. If it is an Internet .lnk file (likely created by QuickLinks), set the globe-with-mouse icon.
  5. If it is a .url type shortcut file (likely created manually in Windows File Explorer), set the globe icon. (AutoHotkey cannot detect icons embedded in .url shortcuts).
  6. If found, set the special Windows Tools folder (God Mode) shortcut icon to a Tool Folder icon.
  7. If the shortcut opens a folder (D), use the Folder icon.
  8. Read the target file extension (e.g. .pgn, .jpg, .doc, etc.) to set the default icon for that extension—if any. Add extensions and icon paths to this section to include more file types. If not found (Default:), the GoTo command jumps AutoHotkey to the Label subroutine tag LastWord: found in the Switch ⇒ Default: statement.
  9. The final Default: statement adds a default QuickLinks icon.
While you do need to add special icons to folders and shortcuts for the best result, you only need to do it once for each folder/shortcut.
jetrotal
Posts: 2
Joined: 29 Nov 2020, 12:45

Re: QuickLinks (Menu by folder)

29 Nov 2020, 13:07

Hi! I managed to edit OPs code to make it work as multiples taskbar companions, as in the Images bellow:
image.png
image.png (36.06 KiB) Viewed 5866 times
image.png
image.png (44.05 KiB) Viewed 5866 times

To do that, i hardcoded some global options to change the icons size and gave a fixed position based on the screen coords to he menu:
image.png
image.png (11.04 KiB) Viewed 5866 times
All the shortcuts are ahk files that calls QuickLink through #Include. So I only need to edit a single file to update every other shortcut.

The [Close] shortcut, is just an ahk file with exitApp.
It tries to solve a bug that happens if you click the start icon, before clicking on a Quicklink shortcut.
In this bug, the start Menu steals the focus and breaks any quicklink that should appear over it.


Maybe tJack's updates could also have a dynamic setup like this. That allows to hide/show the quickLink option and customize colors too.

I saw a lot of posts here looking for something like this,
they always lead to an app called "ShortPopUp", wich is slow, old and annoying to configure.
AHK_user
Posts: 406
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: QuickLinks (Menu by folder)

19 Feb 2021, 06:20

@jetrotal: Seems interesting, can you give me an example how you can change the size of the icon of the menu? I have never done that. Personally I prefer my menu's compact, but there are some situations where a big image can be helpfull.

I am also interested in a way to add a tooltip if you hover a specific time over a menu item, but for what I found on the forum, it seems quite difficult.
SolihullRog
Posts: 7
Joined: 29 Jun 2018, 11:48

Re: QuickLinks (Menu by folder)

25 Jun 2021, 06:47

This page is bloody brilliant.
I don't care about the comments - the original post surpasses my wildest dreams.
:bravo: :bravo: :bravo:
benlimanto
Posts: 1
Joined: 17 Aug 2022, 11:50
GitHub: benyaminl

Re: QuickLinks (Menu by folder)

17 Aug 2022, 11:56

Just want to add, I improve Jason code to make it able using .lnk and .url on root folder, like the code above, just I don't put the recursive folder sub menu, as I'm in rush, and I already tidy up so the file extension doesn't show (prettier I guess? for me)

Thank you for bringing such invention!

Code: Select all

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         Jack Dunning <[email protected]>
; Author:         Benyamin Limanto <[email protected]>
;
; Script Function:
;  Create a menu for quick launching program shortcuts and links by categories (folders).
; Date: January 14, 2013
; Updated: August 8, 2017 This version is the most recent version including a function for adding icons to the menu items.
/*
September 26, 2017

Win+Z, Alt+, (comma), and CTRL+right-click all open the QuickLinks menu. I personally use
XButton1 (left extra mouse button) to activate the menu, but I needed to override the built-in
setting in the software for my mouse by adding one of the other hotkey combinations.

This updated verson of QuickLinks includes a number of new features.

1. Icons are added to the menu in different ways.

First, you find the function, AddIcon(TopMenu,SubMenu), for adding icons to the top-level
folders and specific shortcuts on the second level.

Second, specific IfInString command lines change/insert specific types of icons.

Third, program icons are drawn directly from EXE files.

Fourth, you can manually change shortcut icon (.lnk) in Windows (File) Explorer which
then automatically appear in the menu. This does not work for Web links (.url).

Caution: If you have previously setup personalized icon statements in your version of QuickLinks,
be sure to copy and transfer that icon setting code to this version. Otherwise, they may be
overwritten. (In other words, backup your old copy of QuickLinks.ahk before overwriting it.)

2. QuickLinks now includes the secret Windows Tools (God Mode) link in the Tools folder for quick access
to over 200 Windows settings and features. This feature automatic renews if deleted. If you don't 
want it then delete the code which adds it.

Note: When editing shortcuts in Windows (File) Explorer, the name of the Windows Tools shortcut
appear blanks. Do not edit or add a different name. That process will disable the shortcut.

3. With the exception of the above Windows Tools folder, QuickLinks only launches .lnk and .url shortcuts.

4. You can now directly add new links to the menu by selecting a file in Windows (File) Explorer or the 
address bar (URL) of a Web page and selecting Add Links with the appropriate submenu from your QuickLinks
menu. You may want to later edit the shortcut in Windows (File) Explorer to change the name and possibly
add a shortcut icon. Select Edit Quicklinks to open the QuickLinks folder.

October 4, 2017 

I encapsulated the QuickLinks.ahk auto-execute section by adding the Labels QuickLinksSetup:
and QuickLinksReset: for adding the app to any AutoHotkey script. By adding GoSub, QuickLinksSetup
to the auto-execute section (in top or file) of the compilation file and including 
(#Include [path]\QuickLinks.ahk) in the target script anywhere after the end of the auto-execute
section (probably toward the end of the file). You can continue to run the script as an independent app. 

May 24, 2018

The most recent version of QuickLinks implements code generated by Khanh Ngo which adds another 
dimension to the app. You can now highlight a file in Windows File Explorer and open it with a compatible 
shortcut in your QuickLinks menu. For example, if you include Windows Notepad in your QuickLinks 
menu, selecting any text file in Windows File Explorer and activating that Notepad menu item loads the 
file into a Notepad window.

This new capability also allow you to use print parameters to send files to your printer (e.g. Notepad /P). 
Just add the print parameter to the Target field in the Shortcut Properties window in the appropriate QuickLinks
folder.

January 18, 2020 

This version of the script adds a dynamic TimeDate submenu that updates each time you show the
QuickLinks menu.

January 22, 2020

I change all of the deprecated IfInString commands used for loading icons to the new Switch/Case statements.
This gives a number of advantages such as reading icons from shortcuts if available and stopping after successful 
evaluation. Added Menu, MenuName, UseErrorLevel to prevent script abort when icon not found. Need the latest 
version of AutoHotkey (November 2019 or later) for the Switch/Case command to work.

Tip: To automatically add icons to Web page menu items, use the "Add Links" feature in the main QuickLinks menu. This creates an Internet shortcut with the "lnk" extension in which icons can be read by AutoHotkey. Then manually add the desired icon to the shortcut in Windows. The "url" extension shortcuts created via Windows cannot provide
icon information.

February 6, 2020

Replaced deprecated code for adding icons with the QL_GetIcon() function.

August 18, 2022
(By Benyamin Limanto)
Adding Link File for URL and LNK only, on Root Directory, with Icons

*/

QuickLinksSetup:

Menu, MenuName, UseErrorLevel

IfNotExist, C:\Users\%A_UserName%\QuickLinks\
    FileCreateDir, C:\Users\%A_UserName%\QuickLinks\

IfNotExist, C:\Users\%A_UserName%\QuickLinks\Tools\
   FileCreateDir, C:\Users\%A_UserName%\QuickLinks\Tools\

; These two lines add the Windows Tools menu item (God Mode) if missing. Delete if you don't want it.

IfNotExist, C:\Users\%A_UserName%\QuickLinks\Tools\Windows Tools.{ED7BA470-8E54-465E-825C-99712043E01C}
   FileCreateDir, C:\Users\%A_UserName%\QuickLinks\Tools\Windows Tools.{ED7BA470-8E54-465E-825C-99712043E01C}

Menu, Tray, Add, Reload QuickLinks, QL_ReloadHandler
Menu, Tray, Icon, Reload QuickLinks, Shell32.dll, 85  ; Change icon to a menu tree
Menu, Tray, Icon, Shell32.dll, 85  ; Change icon to a menu tree


QuickLinksReset:

Loop, C:\Users\%A_UserName%\QuickLinks\*.*, 1 ,0  
{
    If (InStr(A_LoopFileName,".lnk") or InStr(A_LoopFileName,".url"))
    {
      QL_MainMenuLnk := A_LoopFileName
      StringReplace, QL_MainMenuLnk,QL_MainMenuLnk, .%A_LoopFileExt%
      ;MsgBox %QL_MainMenuLnk%
      Menu, QuickLinks, Add, %QL_MainMenuLnk%, QL_MenuHandler
      QL_GetIcon("QuickLinks",A_LoopFileName)
    }
    Else 
    {
      QL_MainMenu := A_LoopFileName
      Menu, QuickLinks, Add,%A_LoopFileName%, QL_MenuHandler
      QL_GetIcon("QuickLinks",QL_MainMenu)


      ; This creates the menu for automatically adding new menu items
      Menu, QL_AddLinksMenu, Add, %A_LoopFileName%, QL_LinksHandler
      QL_GetIcon("QL_AddLinksMenu",QL_MainMenu)
    }

    CountLoop := 0
    Loop, %A_LoopFileFullPath%\*.*, 1 , 0
    {
     If A_LoopFileAttrib contains H,R,S  ;Skip any file that is 
       continue         ; H, R, or S (System).
    QL_NewName := A_LoopFileName
    StringReplace, QL_NewName,QL_NewName, .%A_LoopFileExt%
    Menu, %QL_MainMenu%, Add, %QL_NewName%, QL_MenuHandler
    QL_GetIcon(QL_MainMenu,QL_NewName)

      CountLoop := 1
    }

    

    If (CountLoop = 1)
    {
      Menu, QuickLinks, Add, %QL_MainMenu%, :%QL_MainMenu%
    }
    Else If(CountLoop > 1)
    {
      Menu, QuickLinks, Add, %QL_MainMenu%, QL_FolderHandler
    }
}

; Add Time/Date submenu

Menu, TimeDate, Add, Time/Date, QuickLinksHandler ; Dummy item
Menu, QuickLinks, Add, Insert Time/Date, :TimeDate
Menu, QuickLinks, Icon, Insert Time/Date, %A_Windir%\system32\SHELL32.dll, 266,


 Menu, QuickLinks, Add ;Add a separator bar

 Menu, QuickLinks, Add, Edit QuickLinks, QuickLinksHandler

; This next menu item creates a submenu for creating new shortcuts (.lnk)
; and adding them directly to the QuickLinks subdirectory. 

 Menu, QuickLinks, Add, Add Links, :QL_AddLinksMenu

 Menu, QuickLinks, Add, Reload QuickLinks, QL_ReloadHandler
 Menu, QuickLinks, Icon, Add Links, C:\WINDOWS\system32\wmploc.DLL, 12

 Menu, QuickLinks, Add, QuickLinks Help, QL_HelpHandler
 Menu, Tray, Add, Reload QuickLinks, QL_ReloadHandler
 Menu, Tray, Icon, Reload QuickLinks, Shell32.dll, 85  ; Change icon to a tree sturcture

Return

QL_MenuHandler:
If A_ThisMenuItem contains Windows Tools
   {
   Run, "C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\Windows Tools.{ED7BA470-8E54-465E-825C-99712043E01C}"
   } 
Else
  {
      IfExist, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\%A_ThisMenuItem%.url
         Run, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\%A_ThisMenuItem%.url
      Else  
        { 
 ; The following snippet added by Khanh Ngo enables the opening of files selected in Windows File Explorer

        Clip0 := ClipboardAll        ; Backup current clipboard's content
        Clipboard :=                      ; Clear clipboard
        SendInput, ^c                    ; copy selected file's path to clipboard
        ClipWait 0

          If Clipboard
            {
              Run, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\%A_ThisMenuItem%.lnk "%clipboard%"
             }
          Else
            {
               IfExist, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenuItem%.lnk
                  Run, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenuItem%.lnk
               Else
                  Run, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenu%\%A_ThisMenuItem%.lnk
            }

  Clipboard := Clip0           ; Restore original ClipBoard
  VarSetCapacity(Clip0, 0)      ; Free memory
        }
    }
Return

QuickLinksHandler:
run, C:\Users\%A_UserName%\QuickLinks\
Return

QL_FolderHandler:
run, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenuItem%
Return

; Subroutine for automatically adding new shortcuts to 

QL_LinksHandler:
  Clipboard :=
  SendInput, ^c  ;text pre-selected
  ClipWait 0
  If ErrorLevel
  {
    MsgBox, Please select a file or URL!
    Return
  }
 SplitPath, Clipboard, Name, Dir, Ext, Name_no_ext, Drive

 
  If (Instr(Clipboard,"http"))
  {
    Name_no_ext := RegExReplace(Clipboard, "https?://(.+?)(/|\?).*" , "$1")
    Icon := A_Windir . "\system32\SHELL32.dll"
    IconNumber := 15
  }
  else
  {
    Icon := ""
    IconNumber := ""
  }
;  MsgBox Clipboard, Name, Dir, Ext, Name_no_ext, Drive`r%Clipboard%, %Name%, %Dir%, %Ext%, %Name_no_ext%, %Drive%

 IfExist, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenuItem%\%Name_no_ext%.lnk
 {
    MsgBox, %Name_no_ext% previously added to the %A_ThisMenuItem% QuickLinks folder.
 }
 Else
 {
   If (Ext ="lnk")
   {
     FileCopy, %Clipboard%, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenuItem%\
     MsgBox, Shortcut %Name_no_ext% copied to the %A_ThisMenuItem% QuickLinks folder.   
   }
   Else
   {
     FileCreateShortcut, %clipboard%, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenuItem%\%Name_no_ext%.lnk,,,,%Icon%,,%IconNumber%
     MsgBox, %Name_no_ext%.lnk Link added to the %A_ThisMenuItem% QuickLinks folder.
;  Run, explorer.exe /select, C:\Users\%A_UserName%\QuickLinks\%A_ThisMenuItem%\%Name_no_ext%.lnk
   }
 }
GoSub, QL_ReloadHandler
Return


;  Recreates the QuickLinks menu

QL_ReloadHandler:
  Menu, QuickLinks, Delete
  Loop, C:\Users\%A_UserName%\QuickLinks\*.*, 2 , 0  
  {  
    Menu, %A_LoopFileName%, Delete
  }
  GoSub, QuickLinksReset
Return

QL_HelpHandler:
  Run, http://www.computoredge.com/AutoHotkey/AutoHotkey_Quicklinks_Menu_App.html
Return

; Assigned Hotkey combinations

^RButton::
#q::
!,::
  Menu, TimeDate, DeleteAll
  List := DateFormats(A_Now)
  TextMenuDate(List,"TimeDate","DateAction")
  Menu, QuickLinks, Show
Return

; Add or delete statement in the QL_GetIcon() function to change icon settings.

QL_GetIcon(menuitem,submenu)
{
If (InStr(submenu, ".lnk") or Instr(submenu, ".url"))
{
;MsgBox, %menuitem% "Hasil" %submenu%
; Probe shortcut data—if available
  FileGetShortcut, C:\Users\%A_UserName%\QuickLinks\%submenu%
     , QL_OutTarget, QL_OutDir, QL_OutArgs, QL_OutDescription, QL_OutIcon
    , QL_OutIconNum, QL_OutRunState
  StringReplace, submenu,submenu, .lnk
  StringReplace, submenu,submenu, .url
  ; Save .url type shortcut file name  
  Webfile := "C:\Users\" A_UserName "\QuickLinks\" submenu ".url"
;MsgBox, %menuitem%, Icon, %submenu% %QL_OutIcon%, %QL_OutIconNum%, %QL_OutDir%, QL_OutTarget
;  Menu, %menuitem%, Icon, %submenu%
;      , %QL_OutIcon%, %QL_OutIconNum%
 
}
else 
{
  ; Probe shortcut data—if available
  FileGetShortcut, C:\Users\%A_UserName%\QuickLinks\%menuitem%\%submenu%.lnk
     , QL_OutTarget, QL_OutDir, QL_OutArgs, QL_OutDescription, QL_OutIcon
    , QL_OutIconNum, QL_OutRunState
  ; Save .url type shortcut file name  
  Webfile := "C:\Users\" A_UserName "\QuickLinks\" menuitem "\" submenu ".url"

}
; Save file attributes    
  FileGetAttrib, QL_FileAttrib , %QL_OutTarget%
; Read embedded folder icon 
  IniRead, OutputVar, C:\Users\%A_UserName%\QuickLinks\%submenu%\desktop.ini, .ShellClassInfo , IconResource                                              

; This conditional Switch/Case command uses icon data stored in the shortcut (if any) to set menu icon.
; To activate and/or change a particular icon manually open the folder/shortcut Properties window in Windows File Explorer
; (right-click on filename and select Properties) and Change icon..., OK, then Apply.

  Switch
  {
  ; Check for embedded folder icon
    Case (menuitem = "QuickLinks" or menuitem = "QL_AddLinksMenu") and (OutputVar != "Error"):
      Array := StrSplit(OutputVar,",")
             Path := Array[1]
             Icon := Array[2] +1    
      Menu, %menuitem%, Icon, %submenu%, %path% , %icon%
  ; Check for embedded shotcut icon
    Case (QL_OutIcon != ""):
      Menu, %menuitem%, Icon, %submenu%
      , %QL_OutIcon%, %QL_OutIconNum%
  ; Set program file icon
    Case Instr(QL_OutTarget,"exe"):
      Menu, %menuitem%, Icon, %submenu%, %QL_OutTarget%, 1
  ; Set Web page icon
    Case Instr(QL_OutDir,"http"), Instr(QL_OutTarget,"http"):
      Menu, %menuitem%, Icon, %submenu%
      , %A_Windir%\system32\SHELL32.dll, 15,
  ; Set Web page icon for .url type shortcuts
    Case FileExist(Webfile):
      Menu, %menuitem%, Icon, %submenu%
      , %A_Windir%\system32\SHELL32.dll, 14,
; Set Windows Tools folder icon
     Case Instr(submenu,"Tools"):
        Menu, %menuitem%, Icon, %submenu%
       ,  C:\WINDOWS\System32\SHELL32.dll,36
 ; Set folder shortcut icon
    Case Instr(QL_FileAttrib,"D"):
       Menu, %menuitem%, Icon, %submenu%
       , %A_Windir%\system32\imageres.dll, 4,
  ; Set icon based on file extension
    Case RegExMatch(QL_OutTarget,"\.\w+$",extension): 
      Switch extension
      {
        Case ".jpg",".png":
          Menu, %menuitem%, Icon, %submenu%, %A_Windir%\system32\SHELL32.dll, 142,
        Case ".epub",".mobi",".pdf":
          Menu, %menuitem%, Icon, %submenu%, C:\AutoHotkey\Icons\Books.ico,0
        Case ".ahk":
          Menu, %menuitem%, Icon, %submenu%
                      , C:\Program Files\AutoHotkey\AutoHotkeyU64.exe, 2
      ; Jump to default
        Default: goto LastWord
      }
    ; Add default icon
      Default:
        LastWord:
        Menu, %menuitem%, Icon, %submenu%
          , %A_Windir%\system32\SHELL32.dll, 85,
    }
}

; Creates string of formatted dates

DateFormats(Date)
{
FormatTime, OutputVar , %Date%, h:mm tt ;12 hour clock
List := OutputVar
FormatTime, OutputVar , %Date%, HH:mm ;24 hour clock
List := List . "|" . OutputVar
FormatTime, OutputVar , %Date%, ShortDate ; 11/5/2015
List := List . "|" . OutputVar
FormatTime, OutputVar , %Date%, MMM. d, yyyy
List := List . "|" . OutputVar
FormatTime, OutputVar , %Date%, MMMM d, yyyy
List := List . "|" . OutputVar
FormatTime, OutputVar , %Date%, LongDate
List := List . "|" . OutputVar
FormatTime, OutputVar, %Date%, h:mm tt, dddd, MMMM d, yyyy
List := List . "|" . OutputVar
FormatTime, OutputVar, %Date%, dddd MMMM d, yyyy hh:mm:ss tt
List := List . "|" . OutputVar
Return List
}

; Creates DateTime Submenu

TextMenuDate(TextOptions,Menu,Action)
{
  StringSplit, MenuItems, TextOptions , |
  Loop %MenuItems0%
  {
    Item := MenuItems%A_Index%
    Menu, %Menu%, add, %Item%, %Action%
    Switch 
    {
    Case (InStr(Item,":") and InStr(Item,"`,")):
      Menu, TimeDate, Icon, %Item%, %A_Windir%\System32\timedate.cpl
    Case (InStr(Item,":")):
      Menu, TimeDate, Icon, %Item%, %A_Windir%\System32\shell32.dll, 240
    Default:
      Menu, TimeDate, Icon, %Item%, %A_Windir%\System32\ieframe.dll, 46
    }
  }
}

; DateTime submenu action

DateAction:
  SendInput %A_ThisMenuItem%{Raw}%A_EndChar%
Return
Update will be on https://gist.github.com/benyaminl/b140524a3a8a2779546149faac6dbf5f (only as backup)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 22 guests