Advertisement
Najeebsk

RECEND-SHORTCUT-LAUNCHER.ahk

Apr 10th, 2023 (edited)
991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; <COMPILER: v1.1.34.04>
  2. /*   INFO
  3.    SHOW SHORTCUT LAUNCHER RECENT FILES
  4.    Written by: Najeeb Shah Khan (najeebshahkhan@gmail.com)
  5.    Last Modified: 4-6-2023
  6. */
  7. #NoEnv
  8. ; #Warn
  9. ;#NoTrayIcon
  10. #SingleInstance force
  11. #MaxHotkeysPerInterval 99000000
  12. #HotkeyInterval 99000000
  13. #KeyHistory 0
  14. ListLines Off
  15. Process, Priority, , A
  16. SetBatchLines, -1
  17. SetKeyDelay, -1, -1
  18. SetMouseDelay, -1
  19. SetDefaultMouseSpeed, 0
  20. SetWinDelay, -1
  21. SetControlDelay, -1
  22. SendMode Input
  23. SetWorkingDir, %A_ScriptDir%
  24. FileCreateDir, %A_ScriptDir%\DATA
  25. FileInstall , RECEND-SHORTCUT-LAUNCHER.ahk, %A_ScriptDir%\DATA\RECEND-SHORTCUT-LAUNCHER.ahk, 1
  26. FileInstall , S12.she, %A_ScriptDir%\DATA\S12.she, 1
  27. FileInstall , SkinH_EL.dll, %A_ScriptDir%\DATA\SkinH_EL.dll, 1
  28. FileSetAttrib +HS, %A_ScriptDir%\DATA\RECEND-SHORTCUT-LAUNCHER.ahk, 2
  29. FileSetAttrib +HS, %A_ScriptDir%\DATA\S12.she, 2
  30. FileSetAttrib +HS, %A_ScriptDir%\DATA\SkinH_EL.dll, 2
  31. FileSetAttrib +HS, %A_ScriptDir%\DATA, 2
  32. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  33. SkinForm(Apply, A_ScriptDir . "\DATA\SkinH_EL.dll", A_ScriptDir . "\DATA\S12.she")
  34. OnExit, GetOut
  35. Loop, Files, %A_ScriptDir%\*.lnk
  36. {
  37.     FileName := A_LoopFileFullPath
  38.     FileGetShortcut, %FileName%, ProfilePath
  39.     if (!Instr(FileName, "default-profile.lnk"))
  40.     {
  41.         break
  42.     }
  43. }
  44. IniRead, ProfileName, % ProfilePath . "/config.ini", Config, Name
  45. IniRead, ShowRecent, % ProfilePath . "/config.ini", Config, ShowRecent
  46. IniRead, DeleteDuplicatesInRecent, % ProfilePath . "/config.ini", Config, DeleteDuplicatesInRecent
  47. IniRead, DeleteNonExistingInRecent, % ProfilePath . "/config.ini", Config, DeleteNonExistingInRecent
  48. If (ShowRecent == "ERROR" || ShowRecent == "True")
  49. {
  50.     ShowRecent := True
  51. }
  52. Else
  53. {
  54.     ShowRecent := False
  55. }
  56. If (DeleteDuplicatesInRecent == "ERROR" || DeleteDuplicatesInRecent == "True")
  57. {
  58.     DeleteDuplicatesInRecent := True
  59. }
  60. Else
  61. {
  62.     DeleteDuplicatesInRecent := False
  63. }
  64. If (DeleteNonExistingInRecent == "ERROR" || DeleteNonExistingInRecent == "True")
  65. {
  66.     DeleteNonExistingInRecent := True
  67. }
  68. Else
  69. {
  70.     DeleteNonExistingInRecent := False
  71. }
  72. Shortcuts := []
  73. LastSearchString := ""
  74. Gui, ShortcutLauncher:New, +HwndShortcutsHwnd, Shortcut Launcher
  75. GroupAdd, ShortcutLauncherGroup, ahk_id %ShortcutsHwnd%
  76. Gui, ShortcutLauncher:Color, 091D33, 091D33
  77. Gui, ShortcutLauncher:Font, s10 cDDDDDD, Calibri
  78. Gui, ShortcutLauncher:-Caption -Border
  79. Gui, ShortcutLauncher:Margin, 15, 15
  80. Gui, ShortcutLauncher:Add, Edit, w900 h30 +0x200 -VScroll -wrap -E0x200 vSearchString gIncrementalSearch,
  81. Gui, ShortcutLauncher:Add, ListView, +LV0x10000 r32 w900 -Multi -Hdr -E0x200 Background091D33 cB6C9DE vShortcutsListView, Name|Target|Filename
  82. GuiControl, -Redraw, ShortcutsListView
  83. GoSub, PushShortcutsFromFolder
  84. if ShowRecent {
  85.     GoSub, PushShortcutsFromRecent
  86. }
  87. GoSub, AddAll
  88. LV_Modify(1, "Select Vis") ; Select first and make sure it is in view.
  89. LV_ModifyCol()  ; Auto-size each column to fit its contents.
  90. LV_ModifyCol(3, 0) ; Hide the full filename.
  91. LV_ModifyCol(1, 600) ; Set width of first column.
  92. GuiControl, +Redraw, ShortcutsListView  ; Re-enable redrawing (it was disabled above).
  93. Gui, ShortcutLauncher:Show
  94. Return
  95. PushShortcutsFromFolder:
  96.     Loop, Files, %ProfilePath%\*.lnk
  97.     {
  98.         FileName := A_LoopFileFullPath
  99.         FileGetShortcut, %FileName%, Folder
  100.  
  101.         FileGetAttrib, FolderExists, % Folder
  102.         If (FolderExists = "") {
  103.             Continue
  104.         }
  105.         FilePattern := Folder . "\*"
  106.         Loop, Files, %FilePattern%, R
  107.         {
  108.             If A_LoopFileExt in lnk,url
  109.             {            
  110.                 FileName := A_LoopFileFullPath
  111.                 SplitPath, FileName, Name, Dir, FileExt, FilenameNoExtension
  112.                 If (Dir = Folder)
  113.                 {
  114.                     Dirname := ""
  115.                 }
  116.                 Else
  117.                 {
  118.                     Dirname := StrReplace(Dir, Folder . "\", "")
  119.                     Dirname := StrReplace(Dirname, "\", " > ")
  120.                 }
  121.                 FileGetShortcut, %FileName%, OutTarget, OutDir, OutArgs
  122.                 If (FileExt = "url")
  123.                 {
  124.                     Loop, read, %Filename%
  125.                     {
  126.                         If (SubStr(A_LoopReadLine, 1, 4) = "URL=")
  127.                         {
  128.                             OutTarget := SubStr(A_LoopReadLine, 5)
  129.                             OutTarget := StrReplace(OutTarget, "microsoft-edge:", "(edge) ")
  130.                             break
  131.                         }
  132.                     }
  133.                 }
  134.  
  135.                 If (RegExMatch(OutTarget . OutArgs, "(chrome|firefox|iexplore)\.exe.*(https.?://.*)$", Match) <> 0)
  136.                 {
  137.                     RegExMatch(OutArgs, "")
  138.                     OutTarget := "(" . Match1 . ") " . Match2
  139.                 }
  140.        
  141.                 Shortcuts.Push({dir:Dirname, file:FilenameNoExtension, target:OutTarget, filename:Filename})
  142.             }
  143.         }
  144.     }
  145. Return
  146.  
  147. PushShortcutsFromRecent:
  148.    RecentFiles := []
  149.     Loop, Files, %A_AppData%\Microsoft\Windows\Recent\*.lnk
  150.     {
  151.         FileName := A_LoopFileFullPath
  152.         FileGetShortcut, %FileName%, OutTarget
  153.         If (DeleteNonExistingInRecent) {
  154.             If (InStr(OutTarget, "\")) {
  155.                 FileGetAttrib, FileExists, % OutTarget
  156.                 If (FileExists = "") {
  157.                     FileDelete, %FileName%
  158.                     Continue
  159.                 }
  160.             }
  161.         }
  162.         IsDuplicate := False
  163.         for index, value in RecentFiles
  164.         {
  165.             If (OutTarget == value) {
  166.                 If (DeleteDuplicatesInRecent) {
  167.                     FileDelete, %FileName%
  168.                 }
  169.                 IsDuplicate := True  
  170.             break
  171.             }
  172.         }
  173.  
  174.         If (!IsDuplicate) {
  175.         RecentFiles.Push(OutTarget)
  176.         SplitPath, OutTarget, Fname
  177.             Shortcuts.Push({dir:"Recent", file:Fname, target:OutTarget, filename:Filename})
  178.         }
  179.     }
  180. Return
  181.  
  182. AddEntry:
  183.    If (value.dir = "")
  184.     {
  185.     LV_Add("", value.file, value.target, value.filename)
  186.     }
  187.     Else
  188.     {
  189.     LV_Add("", value.dir . " > " . value.file, value.target, value.filename)
  190.     }
  191. Return
  192.  
  193. AddEntryAtTop:
  194.    If (value.dir = "")
  195.     {
  196.     LV_Insert(VIPRow, "", value.file, value.target, value.filename)
  197.     }
  198.     Else
  199.     {
  200.     LV_Insert(VIPRow, "", value.dir . " > " . value.file, value.target, value.filename)
  201.     }
  202. Return
  203. AddAll:
  204.    For key, value In Shortcuts
  205.     {
  206.         If (ShowRecent || (SubStr(TextToCompare, 1, 6) != "Recent"))
  207.         {
  208.             Gosub, AddEntry
  209.         }
  210.     }
  211. Return
  212. IncrementalSearch:
  213.    Gui, ShortcutLauncher:Default
  214.     Gui, ShortcutLauncher:Submit, NoHide
  215.     If (SearchString != LastSearchString)
  216.     {
  217.         LastSearchString := SearchString
  218.         GuiControl, -Redraw, ShortcutsListView  
  219.         LV_Delete()
  220.         VIPRow := 1
  221.         For key, value In Shortcuts
  222.         {
  223.             TextToCompare := value.dir . " > " . value.file . " " . value.target
  224.             VIPText := value.dir . " > " . value.file
  225.             If (SearchString != "")
  226.             {
  227.                 Regexp := StrReplace(SearchString, " ", ".*")
  228.                 If (! RegExMatch(Regexp, "[A-Z]"))
  229.                 {
  230.                     Regexp := "i)" . Regexp
  231.                 }
  232.                 If (RegExMatch(TextToCompare, Regexp) && (ShowRecent || (SubStr(TextToCompare, 1, 6) != "Recent")))
  233.                 {
  234.                   If (RegExMatch(VIPText, Regexp))
  235.                     {
  236.                         Gosub, AddEntryAtTop
  237.                         VIPRow++
  238.                     }
  239.                     Else
  240.                     {
  241.                         Gosub, AddEntry
  242.                     }
  243.                 }
  244.             }
  245.             Else If (ShowRecent || (SubStr(TextToCompare, 1, 6) != "Recent"))
  246.             {
  247.                 Gosub, AddEntry
  248.             }
  249.         }
  250.         LV_Modify(1, "Select Vis")
  251.         GuiControl, +Redraw, ShortcutsListView
  252.     }
  253. Return
  254. ToggleRecent:
  255.    Gui, ShortcutLauncher:Default
  256.     ShowRecent := !ShowRecent
  257.     LastSearchString := False
  258.     GoSub, IncrementalSearch
  259. Return
  260. Scroll(num)
  261. {
  262.     If (num > 0)
  263.     {
  264.         Gui, ShortcutLauncher:Default
  265.         NewRow := Min(LV_GetNext() + num, LV_GetCount())
  266.         LV_Modify(NewRow, "Select Vis")
  267.         Return num
  268.     }
  269.     Else If (num < 0)
  270.     {
  271.         Gui, ShortcutLauncher:Default
  272.         NewRow := Max(LV_GetNext() + num, 1)
  273.         LV_Modify(NewRow, "Select Vis")
  274.         Return num
  275.     }
  276. }
  277. myGetWindowIDs()
  278. {
  279.     winIDs := []
  280.     WinGet, winID, list
  281.     Loop %winID%
  282.     {
  283.         id := winID%A_Index%
  284.         winIDs.Push(id)
  285.     }
  286.     return winIDs
  287. }
  288. myGetNewWindowID(oldWinIDs, currentWinIDs)
  289. {
  290.     newID := 0
  291.     For i, winID1 in currentWinIDs
  292.     {
  293.         For j, winID2 in oldWinIDs
  294.         {
  295.             If (winID1 = winID2)
  296.             {
  297.                 newID := 0
  298.                 Break
  299.             }
  300.             Else
  301.             {
  302.                 newID := 1
  303.             }
  304.         }
  305.         if newID
  306.         {
  307.             return currentWinIDs[i]
  308.         }
  309.     }
  310.     return 0
  311. }
  312. #IfWinActive, ahk_group ShortcutLauncherGroup
  313. Esc::
  314. ^g::
  315. {
  316.     Gui, ShortcutLauncher:Show, Minimize
  317.     Return
  318. }
  319. Up::
  320. ^p::
  321. {
  322.     Scroll(-1)
  323.     Return
  324. }
  325. Down::
  326. ^n::
  327. {
  328.     Scroll(1)
  329.     Return
  330. }
  331. ^u::
  332. {
  333.     Gui, ShortcutLauncher:Default
  334.     GuiControl, , SearchString
  335.     Return
  336. }
  337. !a::
  338. {
  339.     SendInput, {End}+{Home}
  340.     Return
  341. }
  342. ^a::
  343. {
  344.     SendInput, {Home}
  345.     Return
  346. }
  347. ^e::
  348. {
  349.     SendInput, {End}
  350.     Return
  351. }
  352. ^Backspace::
  353. ^+h::
  354. {
  355.     SendInput, ^+{Left}{Backspace}
  356.     Return
  357. }
  358. !d::
  359. {
  360.     SendInput, ^{Del}
  361.     Return
  362. }
  363. ^b::
  364. {
  365.     Scroll(-20)
  366.     Return
  367. }
  368. ^f::
  369. {
  370.     Scroll(20)
  371.     Return
  372. }
  373. ^i::
  374. {
  375.     Gui, ShortcutLauncher:Default
  376.     GuiControl, Focus, SearchString
  377.     Return
  378. }
  379. ^m::
  380. Enter::
  381. {
  382.     Gui, ShortcutLauncher:Default
  383.     LV_GetText(ShortcutTarget, LV_GetNext(), 3)
  384.     Run %ShortcutTarget%,, UseErrorLevel
  385.  
  386.     if ErrorLevel
  387.     {
  388.         MsgBox Could not open "%FileDir%\%FileName%".
  389.     }
  390.     Else
  391.     {
  392.         Gui, ShortcutLauncher:Show, Minimize
  393.     }
  394.     Return
  395. }
  396.  
  397. ^q::
  398. {
  399.     Gui, ShortcutLauncher:Default
  400.     LV_GetText(ShortcutTarget, LV_GetNext(), 3)
  401.     newWinID := ""
  402.     oldWinIDs := myGetWindowIDs()
  403.     currentWinIDs := []
  404.     WinGet, activeWinID, ID, A
  405.     Run, %ShortcutTarget%,, UseErrorLevel
  406.     if ErrorLevel
  407.     {
  408.         MsgBox Could not open "%FileDir%\%FileName%".
  409.         Return
  410.     }
  411.     else
  412.     {
  413.      }
  414.     Sleep, 100
  415.     StartTime := A_TickCount
  416.     ElapsedTime := (A_TickCount - StartTime)
  417.     use_id := false
  418.     While (ElapsedTime < 20000)
  419.     {
  420.         WinGet, activeWinID_neu, ID, A
  421.         if (activeWinID_neu && activeWinID != activeWinID_neu)
  422.         {
  423.             newWinID := activeWinID_neu
  424.             WinGet, p_id, PID, ahk_id %newWinID%
  425.             WinGet, id_from_p_id, ID, ahk_pid %p_id%
  426.             if (newWinID != id_from_p_id) {
  427.                 use_id := true
  428.             }
  429.             break
  430.         }
  431.         Sleep, 100
  432.         ElapsedTime := (A_TickCount - StartTime)
  433.     }
  434.  
  435.     posX  := MonitorWorkAreaLeft
  436.     posY := MonitorWorkAreaTop
  437.     SysGet, BorderX, 32
  438.     if (BorderX) {
  439.         posX := posX - BorderX
  440.     }
  441.     if (newWinID)
  442.     {
  443.         new_id := newWinID
  444.         win_height := 0
  445.         win_width := 0
  446.         StartTime := A_TickCount
  447.         ElapsedTime := (A_TickCount - StartTime)
  448.         while (ElapsedTime < 20000) {
  449.             if !use_id {
  450.                 WinGet, new_id, ID, ahk_pid %p_id%
  451.             } else {
  452.                 WinSet, Trans, 0, ahk_id %new_id%
  453.                 WinMove, ahk_id %new_id%, , %posX%, %posY%
  454.                 WinMaximize, ahk_id %new_id%
  455.                 SendInput #{Right}
  456.                 WinSet, Trans, 255, ahk_id %new_id%
  457.                 break
  458.             }
  459.             WinSet, Trans, 0, ahk_id %new_id%
  460.             WinGetPos, current_x, , current_width, , ahk_id %new_id%
  461.             WinMove, ahk_id %new_id%, , % current_x + 1, , % current_width + 1
  462.             WinGetPos, x_new, , width_new, , ahk_id %new_id%
  463.             if (width_new = current_width + 1) {
  464.                 WinMove, ahk_id %new_id%, , % posX, % posY, % current_width
  465.                 WinMaximize, ahk_id %new_id%
  466.                 SendInput #{Right}
  467.                 WinSet, Trans, 255, ahk_id %new_id%
  468.                 break
  469.             } else {
  470.                 ; reset the position
  471.                 WinMove, ahk_id %new_id%, , % current_x
  472.             }
  473.             Sleep 100
  474.             ElapsedTime := (A_TickCount - StartTime)
  475.         }
  476.     }
  477.     Gui, ShortcutLauncher:Show, Minimize
  478.     Return
  479. }
  480.  
  481. !o::
  482. {
  483.     Gui, ShortcutLauncher:Default
  484.     LV_GetText(ShortcutTarget, LV_GetNext(), 3)
  485.     LV_GetText(Filename, LV_GetNext(), 2)
  486.     FileGetAttrib, Attributes, % Filename
  487.     If (InStr(Attributes, "D"))
  488.     {
  489.         Run %ShortcutTarget%,, UseErrorLevel
  490.     }
  491.     Else
  492.     {
  493.         SplitPath, Filename,, OutDir
  494.         Run, explore %OutDir%,, UseErrorLevel
  495.     }
  496.     If ErrorLevel
  497.     {
  498.         MsgBox Could not open "%FileDir%\%FileName%".
  499.     }
  500.     Else
  501.     {
  502.         Gui, ShortcutLauncher:Show, Minimize
  503.     }
  504.     Return
  505.  
  506.     Return
  507. }
  508. ^r::
  509. {
  510.     GoSub, ToggleRecent
  511.     Return
  512. }
  513. ^x::
  514. {
  515.     GoSub, GuiClose
  516.     Return
  517. }
  518. ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  519. GetOut:
  520. GuiClose:
  521. Gui, Hide
  522. SkinForm(0)
  523. ExitApp
  524. return
  525.  
  526. SkinForm(Param1 = "Apply", DLL = "", SkinName = ""){
  527.     if(Param1 = Apply){
  528.         DllCall("LoadLibrary", str, DLL)
  529.         DllCall(DLL . "\SkinH_AttachEx", AStr,SkinName, Str,"mhgd")
  530.     }else if(Param1 = 0){
  531.         DllCall(DLL . "\USkinExit")
  532.         }
  533. }
  534. ;=-=-=-=-=-=-=-=-=-=- END SCRIPT -=-=-=-=-=-=-=-=-=-=-=-
  535.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement