Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; <COMPILER: v1.1.34.04>
- /* INFO
- SHOW SHORTCUT LAUNCHER RECENT FILES
- Written by: Najeeb Shah Khan (najeebshahkhan@gmail.com)
- Last Modified: 4-6-2023
- */
- #NoEnv
- ; #Warn
- ;#NoTrayIcon
- #SingleInstance force
- #MaxHotkeysPerInterval 99000000
- #HotkeyInterval 99000000
- #KeyHistory 0
- ListLines Off
- Process, Priority, , A
- SetBatchLines, -1
- SetKeyDelay, -1, -1
- SetMouseDelay, -1
- SetDefaultMouseSpeed, 0
- SetWinDelay, -1
- SetControlDelay, -1
- SendMode Input
- SetWorkingDir, %A_ScriptDir%
- FileCreateDir, %A_ScriptDir%\DATA
- FileInstall , RECEND-SHORTCUT-LAUNCHER.ahk, %A_ScriptDir%\DATA\RECEND-SHORTCUT-LAUNCHER.ahk, 1
- FileInstall , S12.she, %A_ScriptDir%\DATA\S12.she, 1
- FileInstall , SkinH_EL.dll, %A_ScriptDir%\DATA\SkinH_EL.dll, 1
- FileSetAttrib +HS, %A_ScriptDir%\DATA\RECEND-SHORTCUT-LAUNCHER.ahk, 2
- FileSetAttrib +HS, %A_ScriptDir%\DATA\S12.she, 2
- FileSetAttrib +HS, %A_ScriptDir%\DATA\SkinH_EL.dll, 2
- FileSetAttrib +HS, %A_ScriptDir%\DATA, 2
- ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- SkinForm(Apply, A_ScriptDir . "\DATA\SkinH_EL.dll", A_ScriptDir . "\DATA\S12.she")
- OnExit, GetOut
- Loop, Files, %A_ScriptDir%\*.lnk
- {
- FileName := A_LoopFileFullPath
- FileGetShortcut, %FileName%, ProfilePath
- if (!Instr(FileName, "default-profile.lnk"))
- {
- break
- }
- }
- IniRead, ProfileName, % ProfilePath . "/config.ini", Config, Name
- IniRead, ShowRecent, % ProfilePath . "/config.ini", Config, ShowRecent
- IniRead, DeleteDuplicatesInRecent, % ProfilePath . "/config.ini", Config, DeleteDuplicatesInRecent
- IniRead, DeleteNonExistingInRecent, % ProfilePath . "/config.ini", Config, DeleteNonExistingInRecent
- If (ShowRecent == "ERROR" || ShowRecent == "True")
- {
- ShowRecent := True
- }
- Else
- {
- ShowRecent := False
- }
- If (DeleteDuplicatesInRecent == "ERROR" || DeleteDuplicatesInRecent == "True")
- {
- DeleteDuplicatesInRecent := True
- }
- Else
- {
- DeleteDuplicatesInRecent := False
- }
- If (DeleteNonExistingInRecent == "ERROR" || DeleteNonExistingInRecent == "True")
- {
- DeleteNonExistingInRecent := True
- }
- Else
- {
- DeleteNonExistingInRecent := False
- }
- Shortcuts := []
- LastSearchString := ""
- Gui, ShortcutLauncher:New, +HwndShortcutsHwnd, Shortcut Launcher
- GroupAdd, ShortcutLauncherGroup, ahk_id %ShortcutsHwnd%
- Gui, ShortcutLauncher:Color, 091D33, 091D33
- Gui, ShortcutLauncher:Font, s10 cDDDDDD, Calibri
- Gui, ShortcutLauncher:-Caption -Border
- Gui, ShortcutLauncher:Margin, 15, 15
- Gui, ShortcutLauncher:Add, Edit, w900 h30 +0x200 -VScroll -wrap -E0x200 vSearchString gIncrementalSearch,
- Gui, ShortcutLauncher:Add, ListView, +LV0x10000 r32 w900 -Multi -Hdr -E0x200 Background091D33 cB6C9DE vShortcutsListView, Name|Target|Filename
- GuiControl, -Redraw, ShortcutsListView
- GoSub, PushShortcutsFromFolder
- if ShowRecent {
- GoSub, PushShortcutsFromRecent
- }
- GoSub, AddAll
- LV_Modify(1, "Select Vis") ; Select first and make sure it is in view.
- LV_ModifyCol() ; Auto-size each column to fit its contents.
- LV_ModifyCol(3, 0) ; Hide the full filename.
- LV_ModifyCol(1, 600) ; Set width of first column.
- GuiControl, +Redraw, ShortcutsListView ; Re-enable redrawing (it was disabled above).
- Gui, ShortcutLauncher:Show
- Return
- PushShortcutsFromFolder:
- Loop, Files, %ProfilePath%\*.lnk
- {
- FileName := A_LoopFileFullPath
- FileGetShortcut, %FileName%, Folder
- FileGetAttrib, FolderExists, % Folder
- If (FolderExists = "") {
- Continue
- }
- FilePattern := Folder . "\*"
- Loop, Files, %FilePattern%, R
- {
- If A_LoopFileExt in lnk,url
- {
- FileName := A_LoopFileFullPath
- SplitPath, FileName, Name, Dir, FileExt, FilenameNoExtension
- If (Dir = Folder)
- {
- Dirname := ""
- }
- Else
- {
- Dirname := StrReplace(Dir, Folder . "\", "")
- Dirname := StrReplace(Dirname, "\", " > ")
- }
- FileGetShortcut, %FileName%, OutTarget, OutDir, OutArgs
- If (FileExt = "url")
- {
- Loop, read, %Filename%
- {
- If (SubStr(A_LoopReadLine, 1, 4) = "URL=")
- {
- OutTarget := SubStr(A_LoopReadLine, 5)
- OutTarget := StrReplace(OutTarget, "microsoft-edge:", "(edge) ")
- break
- }
- }
- }
- If (RegExMatch(OutTarget . OutArgs, "(chrome|firefox|iexplore)\.exe.*(https.?://.*)$", Match) <> 0)
- {
- RegExMatch(OutArgs, "")
- OutTarget := "(" . Match1 . ") " . Match2
- }
- Shortcuts.Push({dir:Dirname, file:FilenameNoExtension, target:OutTarget, filename:Filename})
- }
- }
- }
- Return
- PushShortcutsFromRecent:
- RecentFiles := []
- Loop, Files, %A_AppData%\Microsoft\Windows\Recent\*.lnk
- {
- FileName := A_LoopFileFullPath
- FileGetShortcut, %FileName%, OutTarget
- If (DeleteNonExistingInRecent) {
- If (InStr(OutTarget, "\")) {
- FileGetAttrib, FileExists, % OutTarget
- If (FileExists = "") {
- FileDelete, %FileName%
- Continue
- }
- }
- }
- IsDuplicate := False
- for index, value in RecentFiles
- {
- If (OutTarget == value) {
- If (DeleteDuplicatesInRecent) {
- FileDelete, %FileName%
- }
- IsDuplicate := True
- break
- }
- }
- If (!IsDuplicate) {
- RecentFiles.Push(OutTarget)
- SplitPath, OutTarget, Fname
- Shortcuts.Push({dir:"Recent", file:Fname, target:OutTarget, filename:Filename})
- }
- }
- Return
- AddEntry:
- If (value.dir = "")
- {
- LV_Add("", value.file, value.target, value.filename)
- }
- Else
- {
- LV_Add("", value.dir . " > " . value.file, value.target, value.filename)
- }
- Return
- AddEntryAtTop:
- If (value.dir = "")
- {
- LV_Insert(VIPRow, "", value.file, value.target, value.filename)
- }
- Else
- {
- LV_Insert(VIPRow, "", value.dir . " > " . value.file, value.target, value.filename)
- }
- Return
- AddAll:
- For key, value In Shortcuts
- {
- If (ShowRecent || (SubStr(TextToCompare, 1, 6) != "Recent"))
- {
- Gosub, AddEntry
- }
- }
- Return
- IncrementalSearch:
- Gui, ShortcutLauncher:Default
- Gui, ShortcutLauncher:Submit, NoHide
- If (SearchString != LastSearchString)
- {
- LastSearchString := SearchString
- GuiControl, -Redraw, ShortcutsListView
- LV_Delete()
- VIPRow := 1
- For key, value In Shortcuts
- {
- TextToCompare := value.dir . " > " . value.file . " " . value.target
- VIPText := value.dir . " > " . value.file
- If (SearchString != "")
- {
- Regexp := StrReplace(SearchString, " ", ".*")
- If (! RegExMatch(Regexp, "[A-Z]"))
- {
- Regexp := "i)" . Regexp
- }
- If (RegExMatch(TextToCompare, Regexp) && (ShowRecent || (SubStr(TextToCompare, 1, 6) != "Recent")))
- {
- If (RegExMatch(VIPText, Regexp))
- {
- Gosub, AddEntryAtTop
- VIPRow++
- }
- Else
- {
- Gosub, AddEntry
- }
- }
- }
- Else If (ShowRecent || (SubStr(TextToCompare, 1, 6) != "Recent"))
- {
- Gosub, AddEntry
- }
- }
- LV_Modify(1, "Select Vis")
- GuiControl, +Redraw, ShortcutsListView
- }
- Return
- ToggleRecent:
- Gui, ShortcutLauncher:Default
- ShowRecent := !ShowRecent
- LastSearchString := False
- GoSub, IncrementalSearch
- Return
- Scroll(num)
- {
- If (num > 0)
- {
- Gui, ShortcutLauncher:Default
- NewRow := Min(LV_GetNext() + num, LV_GetCount())
- LV_Modify(NewRow, "Select Vis")
- Return num
- }
- Else If (num < 0)
- {
- Gui, ShortcutLauncher:Default
- NewRow := Max(LV_GetNext() + num, 1)
- LV_Modify(NewRow, "Select Vis")
- Return num
- }
- }
- myGetWindowIDs()
- {
- winIDs := []
- WinGet, winID, list
- Loop %winID%
- {
- id := winID%A_Index%
- winIDs.Push(id)
- }
- return winIDs
- }
- myGetNewWindowID(oldWinIDs, currentWinIDs)
- {
- newID := 0
- For i, winID1 in currentWinIDs
- {
- For j, winID2 in oldWinIDs
- {
- If (winID1 = winID2)
- {
- newID := 0
- Break
- }
- Else
- {
- newID := 1
- }
- }
- if newID
- {
- return currentWinIDs[i]
- }
- }
- return 0
- }
- #IfWinActive, ahk_group ShortcutLauncherGroup
- Esc::
- ^g::
- {
- Gui, ShortcutLauncher:Show, Minimize
- Return
- }
- Up::
- ^p::
- {
- Scroll(-1)
- Return
- }
- Down::
- ^n::
- {
- Scroll(1)
- Return
- }
- ^u::
- {
- Gui, ShortcutLauncher:Default
- GuiControl, , SearchString
- Return
- }
- !a::
- {
- SendInput, {End}+{Home}
- Return
- }
- ^a::
- {
- SendInput, {Home}
- Return
- }
- ^e::
- {
- SendInput, {End}
- Return
- }
- ^Backspace::
- ^+h::
- {
- SendInput, ^+{Left}{Backspace}
- Return
- }
- !d::
- {
- SendInput, ^{Del}
- Return
- }
- ^b::
- {
- Scroll(-20)
- Return
- }
- ^f::
- {
- Scroll(20)
- Return
- }
- ^i::
- {
- Gui, ShortcutLauncher:Default
- GuiControl, Focus, SearchString
- Return
- }
- ^m::
- Enter::
- {
- Gui, ShortcutLauncher:Default
- LV_GetText(ShortcutTarget, LV_GetNext(), 3)
- Run %ShortcutTarget%,, UseErrorLevel
- if ErrorLevel
- {
- MsgBox Could not open "%FileDir%\%FileName%".
- }
- Else
- {
- Gui, ShortcutLauncher:Show, Minimize
- }
- Return
- }
- ^q::
- {
- Gui, ShortcutLauncher:Default
- LV_GetText(ShortcutTarget, LV_GetNext(), 3)
- newWinID := ""
- oldWinIDs := myGetWindowIDs()
- currentWinIDs := []
- WinGet, activeWinID, ID, A
- Run, %ShortcutTarget%,, UseErrorLevel
- if ErrorLevel
- {
- MsgBox Could not open "%FileDir%\%FileName%".
- Return
- }
- else
- {
- }
- Sleep, 100
- StartTime := A_TickCount
- ElapsedTime := (A_TickCount - StartTime)
- use_id := false
- While (ElapsedTime < 20000)
- {
- WinGet, activeWinID_neu, ID, A
- if (activeWinID_neu && activeWinID != activeWinID_neu)
- {
- newWinID := activeWinID_neu
- WinGet, p_id, PID, ahk_id %newWinID%
- WinGet, id_from_p_id, ID, ahk_pid %p_id%
- if (newWinID != id_from_p_id) {
- use_id := true
- }
- break
- }
- Sleep, 100
- ElapsedTime := (A_TickCount - StartTime)
- }
- posX := MonitorWorkAreaLeft
- posY := MonitorWorkAreaTop
- SysGet, BorderX, 32
- if (BorderX) {
- posX := posX - BorderX
- }
- if (newWinID)
- {
- new_id := newWinID
- win_height := 0
- win_width := 0
- StartTime := A_TickCount
- ElapsedTime := (A_TickCount - StartTime)
- while (ElapsedTime < 20000) {
- if !use_id {
- WinGet, new_id, ID, ahk_pid %p_id%
- } else {
- WinSet, Trans, 0, ahk_id %new_id%
- WinMove, ahk_id %new_id%, , %posX%, %posY%
- WinMaximize, ahk_id %new_id%
- SendInput #{Right}
- WinSet, Trans, 255, ahk_id %new_id%
- break
- }
- WinSet, Trans, 0, ahk_id %new_id%
- WinGetPos, current_x, , current_width, , ahk_id %new_id%
- WinMove, ahk_id %new_id%, , % current_x + 1, , % current_width + 1
- WinGetPos, x_new, , width_new, , ahk_id %new_id%
- if (width_new = current_width + 1) {
- WinMove, ahk_id %new_id%, , % posX, % posY, % current_width
- WinMaximize, ahk_id %new_id%
- SendInput #{Right}
- WinSet, Trans, 255, ahk_id %new_id%
- break
- } else {
- ; reset the position
- WinMove, ahk_id %new_id%, , % current_x
- }
- Sleep 100
- ElapsedTime := (A_TickCount - StartTime)
- }
- }
- Gui, ShortcutLauncher:Show, Minimize
- Return
- }
- !o::
- {
- Gui, ShortcutLauncher:Default
- LV_GetText(ShortcutTarget, LV_GetNext(), 3)
- LV_GetText(Filename, LV_GetNext(), 2)
- FileGetAttrib, Attributes, % Filename
- If (InStr(Attributes, "D"))
- {
- Run %ShortcutTarget%,, UseErrorLevel
- }
- Else
- {
- SplitPath, Filename,, OutDir
- Run, explore %OutDir%,, UseErrorLevel
- }
- If ErrorLevel
- {
- MsgBox Could not open "%FileDir%\%FileName%".
- }
- Else
- {
- Gui, ShortcutLauncher:Show, Minimize
- }
- Return
- Return
- }
- ^r::
- {
- GoSub, ToggleRecent
- Return
- }
- ^x::
- {
- GoSub, GuiClose
- Return
- }
- ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- GetOut:
- GuiClose:
- Gui, Hide
- SkinForm(0)
- ExitApp
- return
- SkinForm(Param1 = "Apply", DLL = "", SkinName = ""){
- if(Param1 = Apply){
- DllCall("LoadLibrary", str, DLL)
- DllCall(DLL . "\SkinH_AttachEx", AStr,SkinName, Str,"mhgd")
- }else if(Param1 = 0){
- DllCall(DLL . "\USkinExit")
- }
- }
- ;=-=-=-=-=-=-=-=-=-=- END SCRIPT -=-=-=-=-=-=-=-=-=-=-=-
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement