Tuesday, August 5, 2014

AHK Script to Open Random Picture Files in a Folder [Random]


I have been meaning to do this for a while -- to write some AHK code to open a random file (picture) in a folder. I have a folder full of notes (mostly web clippings as screen captures) about life hacks and other information I find useful. The AHK script allow me to review them once a while. I invoke the script by typing "//rp" anywhere, resulting in paintbrush (my default image viewer) to open up with the note. 

The code follows. "O:\PhotoNotes\*.*" is the location of the screen captures. "run" invokes the default viewer. 

:://rp::
total = 0
Loop, O:\PhotoNotes\*.*
  total += 1
Random, select, 1, %total%
Loop, O:\PhotoNotes\*.*
  IfEqual, A_Index, %select%, Setenv, file, %A_LoopFileFullPath%
run, %file%,,hide
return

I save my notes mostly as images because I find that if I put it in OneNote, I rarely go back to the notes and read them over again. This is my solution to that problem.