2/09/2011

RecentRun - Shows the most recently run programs

RecentRun shows the most recently run programs on the Start menu and in the tray. 

Features:
- Sort alphabetically or by date and time.
- Lock individual shortcuts.  


;RecentRun.ahk
; Shows a list of the most recently run programs on the Start menu and in the tray
;Skrommel @2005

#SingleInstance,Force
AutoTrim,Off
BatchLines=-1

Gosub,READINI
RegRead,recentmenu,HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders,Start Menu


recentmenu=%recentmenu%\%shortcutdir%
FileCreateDir,%shortcutdir%
Gosub,UPDATEMENUS
Gosub,GETPROGRAMS


LOOP:
Sleep,100
oldprograms=%programs%
Gosub,GETPROGRAMS
If programs<>%oldprograms%
{
  Gosub,CREATESHORTCUTS
  Gosub,UPDATEMENUS
}
Goto,LOOP


GETPROGRAMS:
programs=
WinGet,winids,List,,,Program Manager
Loop,%winids%
{
  StringTrimRight,winid,winids%a_index%,0
  WinGet,program,ProcessName,ahk_id %winid%
  Loop,HKEY_CURRENT_USER,Software\Microsoft\Windows\ShellNoRoam\MUICache,0,0
  {
    IfInString,A_LoopRegName,%program%
    {
      RegRead,info
      path=%A_LoopRegName%
      programs=%programs%%program%%A_Tab%%path%%A_Tab%%info%`n
      Break
    }
  }
}
Sort,programs,U
Return


CREATESHORTCUTS:
Loop,Parse,programs,`n
{
  IfNotInString,oldprograms,%A_LoopField%
  { 
    StringSplit,split,A_LoopField,%A_Tab%
    StringSplit,name,split1,`.
    program=%name1%
    path=%split2%
    info=%split3%
    StringGetPos,pos,path,@
    If pos>=0
      StringTrimLeft,path,path,1
    StringGetPos,pos,path,`,
    If pos>=0
      StringMid,path,path,0,%pos%
    StringGetPos,pos,path,`"
    If pos>=0
    {
      StringTrimLeft,path,path,1
      StringTrimRight,path,path,1
    }
    StringLower,program,program,T
    StringRight,ext,path,3
    FileGetAttrib,attributes,%shortcutdir%\%program% - %info%.lnk
    IfNotInString,attributes,R
    IfInString,extensions,%ext%
      FileCreateShortcut,"%path%",%shortcutdir%\%program% - %info%.lnk
  }
}
Return


UPDATEMENUS:
RegDelete,HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\%shortcutdir%,Order
FileRemoveDir,%recentmenu%,1
FileCreateDir,%recentmenu%
FileDelete,%recentmenu%\*.lnk
Menu,Tray,NoStandard
Menu,Tray,DeleteAll
Menu,Tray,Add,RecentRun,REPEATLASTRUN
Menu,Tray,Add,

files=
Loop,%shortcutdir%\*.lnk
{
  If sortbydate=1
    files=%files%%A_LoopFileTimeModified%`t%A_LoopFileName%`n
  Else
    files=%files%%A_LoopFileName%`t%A_LoopFileName%`n
}
If sortbydate=1
  Sort,files,R
Else
  Sort,files

counter=0
Loop,parse,files,`n
{
  If A_LoopField=
    Continue
  StringSplit,filearray,A_LoopField,%A_Tab%
  FileGetShortcut,%shortcutdir%\%filearray2%,Target,Dir,,Description,Icon,IconNumber,RunState
  FileGetAttrib,attributes,%shortcutdir%\%filearray2%
  StringTrimRight,filename,filearray2,4
  IfInString,attributes,R
  {
    FileCreateShortcut,%Target%,%recentmenu%\%filearray2%,%Dir%,,%Description%,%Icon%,,%IconNumber%,%RunState%
    Menu,Tray,Add,%filename%,RUN
  }
  Else
  If counter<%numberofshortcuts%
  {
    Menu,Tray,Add,%filename%,RUN
    counter+=1
    If sortbydate=1
    {
      FileCreateShortcut,%Target%,%recentmenu%\%counter% - %filearray2%,%Dir%,%Args%,%Description%,%Icon%,,%IconNumber%,%RunState%
    }
    Else
    {
      FileCreateShortcut,%Target%,%recentmenu%\%filearray2%,%Dir%,%Args%,%Description%,%Icon%,,%IconNumber%,%RunState%
;      Menu,Tray,Add,%filename%,RUN
    }
  }
}
Menu,Tray,Add,
Menu,Tray,Add,&Settings,SETTINGS
Menu,Tray,Add,&Edit shortcuts,EDITSHORTCUTS
Menu,Tray,Add,&Delete shortcuts,DELETESHORTCUTS
Menu,Tray,Add,&Help,HELP
Menu,Tray,Add,&Quit,QUIT
Menu,Tray,Default,RecentRun
Return


RUN:
  Run,%recentmenu%\%A_ThisMenuItem%.lnk
Return


REPEATLASTRUN:
Return


EDITSHORTCUTS:
Run,Explorer.exe %A_ScriptDir%\%shortcutdir%
Return


DELETESHORTCUTS:
FileRemoveDir,%recentmenu%,1
FileCreateDir,%recentmenu%
FileDelete,%recentmenu%\*.lnk
FileDelete,%shortcutdir%\*.lnk
Gosub,UPDATEMENUS
Return


SETTINGS:
Gosub,READINI
Run,RecentRun.ini
Return


HELP:
help=Shows a list of the most recently run programs on the Start menu and in the tray.
help=%help%`n
help=%help%`nThe tray menu:
help=%help%`n- Settings
help=%help%`n  Opens the RecentRun.ini-file.
help=%help%`n  Edit it to change the sort order, the number of shortcuts,
help=%help%`n  and the name of the Start-menu folder.
help=%help%`n- Edit shortcuts
help=%help%`n  Opens the folder containing the shortcuts.
help=%help%`n  To make a shortcut permanent, write protect it.
help=%help%`n  Right click on the shortcut, click the last menu item,
help=%help%`n  click the first tab, tick the first check box, click OK.
help=%help%`n- Delete shortcuts
help=%help%`n  Deletes the shortcut history.
help=%help%`n
help=%help%`nSkrommel @2005
MsgBox,0,RecentRun,%help%
help=
Return


READINI:
IfNotExist,RecentRun.ini
{
  inifile=[Settings]
  inifile=%inifile%`nsortbydate=1
  inifile=%inifile%`nnumberofshortcuts=30
  inifile=%inifile%`nshortcutdir=Recent
  inifile=%inifile%`nextensions=.exe.com.cmd.bat.pif
  FileAppend,%inifile%,RecentRun.ini
  inifile=
}
IniRead,sortbydate,RecentRun.ini,Settings,sortbydate
IniRead,numberofshortcuts,RecentRun.ini,Settings,numberofshortcuts
IniRead,shortcutdir,RecentRun.ini,Settings,shortcutdir
IniRead,extensions,RecentRun.ini,Settings,extensions
Return


QUIT:
ExitApp 

No comments:

Post a Comment