Show Desktop Shortcuts using AutoHotkey

Have you ever wanted to be able to open a shortcut on your Windows desktop without minimizing the programs you have running. Well, with AutoHotkey it's easy. Here is a script that allows you to do just that. You don't even need AutoHotkey to run it; here is the executable compiled from that script.

Desktop Shortcuts screenshot

If you have AutoHotkey installed (come on, all the cool kids are doing it), then just right click on the script and select "Run Script"; otherwise, double click on the executable. When the script is running an icon will appear in your system tray. Then, all you need to do to bring up the "Show Desktop Shortcuts" window is press "Windows Key-Space Bar". This will show you a list of your desktop shortcuts. Either double clicking on a selection, or pressing Enter when your desired shortcut is highlighted will launch the shortcut. You can navigate with the arrow keys or by pressing the first letter of the shortcut (repeated pressing of the letter will cycle through all the shortcuts with that first letter). You can right-click on the icon in your system tray and select "Exit" if you no longer want the script to be running. Additionally, if you want the script to run every time Windows starts, just copy it to the Startup folder. It's as easy as that!

AutoHotkey can do a lot more than this. The script that I have in my Startup folder keeps growing in size as I find more and more ways to make Windows more efficient with AutoHotkey.

Below is the source code of the AutoHotkey script:

; AutoHotkey Version: 1.x
; Author: Scott Updike scottupdike@gamesbyageek.com http://www.gamesbyageek.com

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#space::
  LoopNum := 0
  Loop, %A_Desktop%\*.lnk
  {
    ; check extension length
    if StrLen(A_LoopFileName) + 1 - InStr(A_LoopFileName, "lnk", StartingPos = 0) = 3
    {
      LoopNum++
    }
  }
  Loop, %A_DesktopCommon%\*.lnk
  {
    ; check extension length
    if StrLen(A_LoopFileName) + 1 - InStr(A_LoopFileName, "lnk", StartingPos = 0) = 3
    {
      LoopNum++
    }
  }
  LoopNum++
  if LoopNum > 40
  {
    LoopNum := 40
  }
  Gui, Add, ListView, List r%LoopNum% w200 gMyListView, shortcut|hidden
  Gui, Add, Button, Hidden Default, OK

  ImageListID := IL_Create(10)
  LV_SetImageList(ImageListID)  ; Assign the above ImageList to the current ListView.
  Loop, %A_Desktop%\*.lnk
  {
    ; check extension length
    if StrLen(A_LoopFileName) + 1 - InStr(A_LoopFileName, "lnk", StartingPos = 0) = 3
    {
      LNKFile := A_Desktop . "\" . A_LoopFileName
      FileGetShortcut, %LNKFile%, OutTarget, OutDir, OutArgs, OutDesc, OutIcon, OutIconNum, OutRunState
      ILOut := IL_Add(ImageListID, OutIcon, OutIconNum)
      if ILOut = 0
      {
        ILOut := IL_Add(ImageListID, OutTarget)
      }
      if ILOut = 0
      {
          if OutTarget =
            ILOut := IL_Add(ImageListID, "SHELL32.dll", 1)
      }
      if ILOut = 0
      {
        StringGetPos, CharPos, OutTarget, \, R1
        StringRight, FileName, OutTarget, StrLen(OutTarget) - CharPos - 1
        IfInString, FileName, .
        {
          ; period found so use generic icon
          IL_Add(ImageListID, "SHELL32.dll", 1)
        }
        else
        {
          ; no period so use folder icon
          IL_Add(ImageListID, "SHELL32.dll", 4)
        }
      }
    }
  }
  Loop, %A_DesktopCommon%\*.lnk
  {
    ; check extension length
    if StrLen(A_LoopFileName) + 1 - InStr(A_LoopFileName, "lnk", StartingPos = 0) = 3
    {
      LNKFile := A_DesktopCommon . "\" . A_LoopFileName
      FileGetShortcut, %LNKFile%, OutTarget, OutDir, OutArgs, OutDesc, OutIcon, OutIconNum, OutRunState
      ILOut := IL_Add(ImageListID, OutIcon, OutIconNum)
      if ILOut = 0
      {
        ILOut := IL_Add(ImageListID, OutTarget)
      }
      if ILOut = 0
      {
          if OutTarget =
            ILOut := IL_Add(ImageListID, "SHELL32.dll", 1)
      }
      if ILOut = 0
      {
        StringGetPos, CharPos, OutTarget, \, R1
        StringRight, FileName, OutTarget, StrLen(OutTarget) - CharPos - 1
        IfInString, FileName, .
        {
          ; period found so use generic icon
          IL_Add(ImageListID, "SHELL32.dll", 1)
        }
        else
        {
          ; no period so use folder icon
          IL_Add(ImageListID, "SHELL32.dll", 4)
        }
      }
    }
  }
  LoopNum := 0
  Loop, %A_Desktop%\*.lnk
  {
    ; check extension length
    if StrLen(A_LoopFileName) + 1 - InStr(A_LoopFileName, "lnk", StartingPos = 0) = 3
    {
      LoopNum++
      LV_Add("Icon" . LoopNum, SubStr(A_LoopFileName, 1, InStr(A_LoopFileName, ".lnk", StartingPos = 0) - 1), 1)
    }
  }
  Loop, %A_DesktopCommon%\*.lnk
  {
    ; check extension length
    if StrLen(A_LoopFileName) + 1 - InStr(A_LoopFileName, "lnk", StartingPos = 0) = 3
    {
      LoopNum++
      LV_Add("Icon" . LoopNum, SubStr(A_LoopFileName, 1, InStr(A_LoopFileName, ".lnk", StartingPos = 0) - 1), 2)
    }
  }

  LV_ModifyCol(1, "Sort")
  ; Display the window and return. The script will be notified whenever the user double clicks a row.
  Gui, Show,, Desktop Shortcuts
  return

  MyListView:
  if A_GuiEvent = DoubleClick
  {
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
    LV_GetText(RowText2, A_EventInfo, 2)
    if RowText2 = 1
      Run "%A_Desktop%\%RowText%.lnk"
    else
      Run "%A_DesktopCommon%\%RowText%.lnk"
    Gui, Destroy
  }
  return

  ButtonOK:
  RowNum := LV_GetNext(0, "Focused")
  if RowNum = 0
    return
  LV_GetText(RowText, RowNum)  ; Get the text from the row's first field.
  LV_GetText(RowText2, RowNum, 2)
  if RowText2 = 1
    Run "%A_Desktop%\%RowText%.lnk"
  else
    Run "%A_DesktopCommon%\%RowText%.lnk"
  Gui, Destroy
  return
return

GuiClose:
GuiEscape:
  Gui, Destroy
return

This works on my versions of XP and Vista. Let me know if you have any problems.

  1. Tim Bleeds
    June 29th, 2010 at 23:00 | #1

    I have maybe 165 icons on the desktop, about 80 of these are in my popup. Once I press Win key + space it takes 6 seconds or more to show the popup. When I double click a link I get ‘Error failed attempt to launch program or document:’ then ‘Specifically no application is associated with the specified file for this operation’. It dies at line 157, ‘Run,”%A_Desktop%\%RowText%”. Is there a way to speed up the app, I’m on a AMD Turion 64 x2 (dual core) vista 64 box. It’s ok speed wise. I was surprised the popup is slow.

  2. July 1st, 2010 at 13:33 | #2

    @Tim Bleeds
    I’ll see if I can duplicate the error and then work on a fix. Thanks for the feedback.

  3. July 4th, 2010 at 00:53 | #3

    @Tim Bleeds
    Tim,

    The window should display all of the shortcuts on your desktop. There is nothing in the logic that limits it to 80 or so and I have tested it with over 100. Keep in mind that it only displays the shortcuts, not anything else on your desktop.

    As far as the error message you are getting, I was able to get a similar error message with shortcuts to files that are opened by another program. Shortcuts to executables seem to work fine. I’ll look into a fix for that bug. Thanks for bringing it to my attention.

  4. July 24th, 2010 at 17:43 | #4

    @Tim Bleeds
    I think I fixed the problem. Thanks again for pointing out the bug.