Notepad++ Recently Opened List Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Stinkfoot9
Posts: 51
Joined: 29 May 2022, 12:17

Notepad++ Recently Opened List

Post by Stinkfoot9 » 26 Jan 2023, 20:27

Im Making a Simple tray icon to run notepad++ and would like the context menu to show recently opened/closed items.
There is a list in np++ in the drop down file menu but i dont know how to retrieve them

Does anyone know if there's there a way to get a list of recently opened/closed np++ files?

Any help appreciated

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Notepad++ Recently Opened List

Post by mikeyww » 26 Jan 2023, 20:38

config.xml

Code: Select all

#Requires AutoHotkey v1.1.33
npp  := "d:\utils\npp\notepad++.exe"
list := nppRecentFiles(npp)

For fileNum, filePath in list
 MsgBox 0, % "File #" fileNum "/" list.Count(), % filePath

nppRecentFiles(npp) { ; Return array of file paths recently opened in Notepad++
 pos := 0, list := []
 SplitPath npp,, dir
 If FileExist(xml := dir "\config.xml") {
  FileRead txt, % xml
  While pos := RegExMatch(txt, "filename=""(.+?)""", m, pos + 1)
   list.Push(m1)
 } Else MsgBox 48, Error, File not found.`n`n%xml%
 Return list
}

Code: Select all

#Requires AutoHotkey v2.0
npp  := "d:\utils\npp\notepad++.exe"
list := nppRecentFiles(npp)

For fileNum, filePath in list
 MsgBox filePath, "File #" fileNum "/" list.Length

nppRecentFiles(npp) { ; Return array of file paths recently opened in Notepad++
 pos := 0, list := []
 SplitPath npp,, &dir
 If FileExist(xml := dir "\config.xml") {
  txt := FileRead(xml)
  While pos := RegExMatch(txt, 'filename="(.+?)"', &m, pos + 1)
   list.Push(m.1)
 } Else MsgBox 'File not found.`n`n' xml, 'Error', 48
 Return list
}

User avatar
Stinkfoot9
Posts: 51
Joined: 29 May 2022, 12:17

Re: Notepad++ Recently Opened List

Post by Stinkfoot9 » 26 Jan 2023, 22:16

mikeyww wrote:
26 Jan 2023, 20:38
config.xml

Thank you... i swear i searched config.xml before but i guess not :facepalm: anyways your code works very good.

i came up with something also here's what i have so far and It works but it seems the config.xml file doesn't update every time you close/open a file, nothing i can do about that i don't think.

Code: Select all


OnMessage(0x404,"AHK_NotifyTrayIcon") ; https://www.autohotkey.com/board/topic/47840-updating-the-tray-menu-before-displaying-it/
AHK_NotifyTrayIcon(wParam, lParam) {

  If (lparam = 517)

    Gosub, ChangeMenu

}

ChangeMenu:
Menu,Tray,DeleteAll
Menu,Tray,NoStandard
menu,tray,add,Open,Open
menu,tray,add, Exit, Exit
Menu,tray,default,open	
fr1()
Menu,tray,add, &%xxx5% ,xox5
Menu,tray,add, &%xxx4% ,xox4
Menu,tray,add, &%xxx3% ,xox3
Menu,tray,add, &%xxx2% ,xox2
Menu,tray,add, &%xxx1% ,xox1
return

xox1:
run, Notepad++.exe %xxx1%
return
xox2:
run, Notepad++.exe %xxx2%
return
xox3:
run, Notepad++.exe %xxx3%
return
xox4:
run, Notepad++.exe %xxx4%
return
xox5:
run, Notepad++.exe %xxx5%
return

open:
Run, Notepad++.exe
return

Exit:
Exitapp
return


return1:
return




fr1()
{
Fileread,xx,AppData\Roaming\Notepad++\config.xml
Loop,Parse,xx,`n
	{
	If a_index between 42 and 47
		{
		word_array := StrSplit(a_loopfield, """") 
		xlx .= word_array[2] "`n"
		}
	}
	
Loop,parse,xlx,`n
	{
	xxx%a_index% := """" A_loopfield """"
	}
}

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Notepad++ Recently Opened List  Topic is solved

Post by mikeyww » 26 Jan 2023, 22:23

I did not run your script, but it looks like you are selecting specific line numbers, and I'm not sure why that would be a good idea.

You can insert my function into your script if you like.

Code: Select all

#Requires AutoHotkey v1.1.33
#Persistent
npp  := "d:\utils\npp\notepad++.exe"
show := 5
ChangeMenu:
Menu Tray, DeleteAll
Menu Tray, Add
For fileNum, filePath in nppRecentFiles(npp) {
 Menu Tray, Add, % filePath, Open
 If (fileNum = show)
  Break
}
Return

Open:
Run % npp " " A_ThisMenuItem
Return

nppRecentFiles(npp) { ; Return array of file paths recently opened in Notepad++
 pos := 0, list := []
 SplitPath npp,, dir
 If FileExist(xml := dir "\config.xml") {
  FileRead txt, % xml
  While pos := RegExMatch(txt, "filename=""(.+?)""", m, pos + 1)
   list.InsertAt(1, m1)
 } Else MsgBox 48, Error, File not found.`n`n%xml%
 Return list
}

sofista
Posts: 650
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Notepad++ Recently Opened List

Post by sofista » 27 Jan 2023, 08:18

Stinkfoot9 wrote:
26 Jan 2023, 22:16
i came up with something also here's what i have so far and It works but it seems the config.xml file doesn't update every time you close/open a file, nothing i can do about that i don't think.
That's right, Notepad++ writes the configuration files when it exits.

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Notepad++ Recently Opened List

Post by mikeyww » 27 Jan 2023, 08:21

The Recent directory also contains LNK files pointing to recently accessed files.

Code: Select all

#Requires AutoHotkey v1.1.33
recent := A_AppData "\Microsoft\Windows\Recent"
Run % recent

Post Reply

Return to “Ask for Help (v1)”