AutoHotkey Community

It is currently May 25th, 2012, 3:17 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 40 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Recent Folders script
PostPosted: January 23rd, 2005, 3:35 pm 
Offline

Joined: October 19th, 2004, 12:11 pm
Posts: 102
I don't know if anyone's made one of these yet, but it was a good learning experience nevertheless.

This script monitors your Windows explorer navigation and keeps a log of folders you visit (and spend more than a few seconds in, to eliminate logging 'pass-thru' folders on your way deeper into the path structure). The list of most recently visited places is stored in a menu which can be accessed via the tray or by pressing Win-LeftMouseButton.
On exit, it will write your list of recent folders to a file called 'Recent Folders lists.log' so it can remember the list from session to session.

The script can be exited quickly with a double-click on the tray icon.

Thanks to Rajat for alerting me to the %A_ThisMenuItem% variable as a means to keep track of an ever-changing menu.

Comments and suggestions welcome.
Code:
;CONFIG
rf_foldernum=10   ;set this value to the maximum number of folders you want remembered
rf_timer=2000   ;this is the period of the timer that checks the current window.
      ;Experiment to find something that works for you
      ;Too long = quick-access folders won't be picked up
      ;Too short = too many 'pass-thru' folders will be logged.


Process, Priority,, High ;This is necessary on my PC, but can probably be disabled on most modern, fast PCs.

;load current folder list from file
Loop, Read, Recent Folders list.log
   {
   If A_LoopReadLine=
      break
   rf_folder%A_Index%=%A_LoopReadLine%
   }


;Get display names for those folder paths
Loop
   {
   If rf_folder%A_Index%=
      break
   StringSplit, temp_path_split, rf_folder%A_Index%,\,
   rf_display%A_Index%:=temp_path_split%temp_path_split0%
   }

;Launch initial menu items
Menu, Tray, NoStandard
;Menu, Tray, Icon, folders.ico ;add your own icon here, and de-comment this line.
Menu, Tray, Add, Exit Recent Folders, rf_close
menu, tray, Add ; separator
Menu, Tray, Default, Exit Recent Folders
Loop, %rf_foldernum%
   {
   temp_display:=rf_display%A_Index%
   If temp_display<>
      Menu, Tray, Add, %temp_display%, rf_launch
   }

;load filter list
Loop, Read, Recent Folders filter.log
   {
   rf_filter%A_Index% = %A_LoopReadLine%
   rf_filternum = %A_Index%
   }



SetTimer, rf_trackfolders, %rf_timer%

#LButton:: Menu, Tray, Show ;Shows the menu wherever the mouse is. Key can be changed to whatever you like.

rf_trackfolders:  ;monitors windows and updates the script with any folder windows.
WinGetActiveTitle, rf_current_win
WinGetClass, rf_class, %rf_current_win%
If rf_class = CabinetWClass
   {
   ;Acquires folder path from window
   SetTitleMatchMode, Slow
   WinGetText, rf_win_info, %rf_current_win%, %rf_current_win%,
   StringSplit, rf_new_folder, rf_win_info,`n
   rf_new_folder= %rf_new_folder1%
   StringTrimRight, rf_new_folder, rf_new_folder, 1
   if rf_new_folder = %rf_last_folder%  ;makes sure folder window has had focus for at least 1 complete cycle of timer
      {
      ;check folder against filter list.
      Loop, %rf_filternum%
        {
        temp_filter := rf_filter%A_Index%
      If rf_current_win = %temp_filter%
        {
        rf_skip=1
        break
        }
      }
      ;Begin re-sort menu - checks for a match to an existing item
      If rf_skip<>1
        {
      Loop
           {
           temp_hold := rf_folder%A_Index%
           If rf_new_folder = %temp_hold%
              {
              match=1
              If rf_display%A_Index%<>%rf_foldernum%
                {
                rf_slot_number=%A_Index%
                Gosub, rf_reshuffle_match
                break
                }
              }
           If rf_folder%A_Index%=
              {
              rf_first_empty=%A_Index%
              break
              }
           }
        If match<>1  ;adds new folder to empty slot
           {
           StringSplit, temp_path_split, rf_new_folder,\
           If rf_first_empty <= %rf_foldernum%
              {
              rf_folder%rf_first_empty% = %rf_new_folder%
              rf_display%rf_first_empty% :=temp_path_split%temp_path_split0%
              temp_display :=rf_display%rf_first_empty%
              Menu, Tray, Add, %temp_display%, rf_launch
              }
           else   ;what happens when all slots are full - shuffles them all down 1
              {
              Menu, Tray, Delete, %rf_display1%
              Loop
                 {
                 plus_count=%A_Index%
                 plus_count += 1
                 If A_Index > %rf_foldernum%
                    {
                    rf_folder%rf_foldernum% = %rf_new_folder%
                    rf_display%rf_foldernum% :=temp_path_split%temp_path_split0%
                    temp_display := rf_display%rf_foldernum%
                    Menu, Tray, Add, %temp_display%, rf_launch
                    break
                    }
                 rf_folder%A_Index% := rf_folder%plus_count%
                 rf_display%A_Index% := rf_display%plus_count%
                 }
              }
           match=
           }
        }
      rf_last_folder=
      }
   else
      rf_last_folder = %rf_new_folder%
   }
match=
rf_skip=
return


rf_launch:
Loop   ;checks which menu item folder to launch
   {
   If rf_display%A_Index% = %A_ThisMenuItem%
      {
      rf_open_folder := rf_folder%A_Index%
      If rf_open_folder=Desktop ;these exceptions take care of some of the special folders - more to do.
         {
         Run, %A_Desktop%
         break
         }
      If rf_open_folder=My Documents
         {
         Run, %A_MyDocuments%
         break
         }
      Run, %rf_open_folder%
      }
   If A_Index > %rf_foldernum%
      break
   }
return

rf_reshuffle_match:
temp_tray := rf_display%rf_slot_number%
Menu, Tray, Delete, %temp_tray%
StringSplit, temp_path_split, rf_new_folder,\
rf_count=%rf_slot_number%
Loop
   {
   plus_count=%rf_count%
   plus_count += 1
   If rf_count = %rf_foldernum%
      {
      rf_folder%rf_foldernum% = %rf_new_folder%
      rf_display%rf_foldernum% :=temp_path_split%temp_path_split0%
      temp_display := rf_display%rf_foldernum%
      Menu, Tray, Add, %temp_display%, rf_launch
      break
      }
   rf_folder%rf_count% := rf_folder%plus_count%
   rf_display%rf_count% := rf_display%plus_count%
   rf_count++
   }
return

rf_close:   ;writes current folder list to file on exit
FileDelete, Recent Folders list.log
Loop
   {
   If rf_display%A_Index% =
      break
   rf_write_string := rf_folder%A_Index%
   FileAppend, %rf_write_string%`n, Recent Folders list.log
   }
ExitApp


Cheers,

C

Edit: Updated script with the changes listed in subsequent posts.


Last edited by CarlosTheTackle on January 24th, 2005, 11:23 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2005, 4:53 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1868
that's a nice script! :)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2005, 11:02 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1868
i don't know how many ppl tried this script, but i'm adding it to my 24*7.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 23rd, 2005, 11:16 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2541
Very nice :). That's really handy. Thanks :).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2005, 12:18 am 
Offline

Joined: October 19th, 2004, 12:11 pm
Posts: 102
Thanks for the comments guys.

Improvements I'm thinking of making:
1. Add a 'filter list' for folders that never get added to the log (for things you have easy access to anyway, like My Computer, or whatever)
2. Currently, folders move further down the list no matter how recently they've been used. I'd like to modify it so that when you go to a folder it autmatically moves its entry to the top slot, so that you never lose your most commonly accessed folders.

Any other suggestions welcome.

C.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2005, 10:07 am 
Offline

Joined: October 19th, 2004, 12:11 pm
Posts: 102
OK, I've made those two improvements above, and changed the script code in my original post to accomodate it. The filter list is simply a file called 'Recent Folders filter.log' where you can make a list of folders that you don't want captured by the script. eg.:
Quote:
My Computer
My Documents
Joe Blogg's Secret stuff


The folder list now also updates existing folders to the top of the list, so frequently visited places don't creep down the list and disappear.

And now one question/suggestion for Chris:
It is mildly annoying that when using the 'Menu, Tray, Show' command, the menu appears down from the current mouse position (as long as it's not too close to the bottom of the screen), whereas when accessed from the tray it appears up from the mouse position, so if I've designed it so the 'Exit' option is furtherest from the tray origin, it appears closest when shown with the 'Show' command.
It would be nice if either:
a) the menu order could be instructed to appear in reverse with something like 'Menu, Tray, Show, Reverse' or
b)the menu would appear upwards by default (except for when it is too close to the top of the screen).

Just a thought.

Cheers all,
C


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2005, 11:19 am 
Offline
User avatar

Joined: December 20th, 2004, 12:19 pm
Posts: 794
Location: LooseChange911.com Ask Questions, Demand Answers █ The WTC bldgs █ shouldn't have fallen █ that fast
Rajat wrote:
i don't know how many ppl tried this script, but i'm adding it to my 24*7.

...I tried it, it didn't work...I open my AutoHotkey dir (or any dir) & it adds a "Links" item to the list, I close the folder & click the menu item & get an error (from AHK, a bad error)...

Code:
Error: Failed attempt to launch program or document:
Action: <Links>
Params: <>

The current thread will exit.

Specifically: The system cannot find the file specified.


        Line#
        151: Break
        152: }
        153: if rf_open_folder = My Documents
        154: {
        155: Run,%A_MyDocuments%
        156: Break
        157: }
--->    158: Run,%rf_open_folder%
        159: }
        160: if A_Index > %rf_foldernum%
        161: Break
        162: }
        163: Return
        166: temp_tray := rf_display%rf_slot_number%
        167: Menu,Tray,Delete,%temp_tray%

...evidently my toolbars are different (than yours...they are default for my computer tho) & the search for the window text...

Code:
WinGetText, rf_win_info, %rf_current_win%, %rf_current_win%,

...don't find the right thing...Window Spy say's the control is Edit1, so instead of window text, you should try some type of ControlGet...or loop thru all window text looking for at least one : (colon) & one or more \ (backslashes) & any other path stuff to make sure you found a path. This was testing the 1st version, but it's still there in the revised version, also in the revised version I got...

Code:
Error: Icon could not be loaded.  The current thread will exit.

Specifically: folders.ico

        Line#
        022: {
        023: if rf_folder%A_Index% =
        024: Break
        025: StringSplit,temp_path_split,rf_folder%A_Index%,\
        026: rf_display%A_Index% := temp_path_split%temp_path_split0%
        027: }
        030: Menu,Tray,NoStandard
--->    031: Menu,Tray,Icon,folders.ico
        032: Menu,Tray,Add,Exit Recent Folders,rf_close
        033: Menu,tray,Add
        034: Menu,Tray,Default,Exit Recent Folders
        035: Loop,%rf_foldernum%
        036: {
        037: temp_display := rf_display%A_Index%
        038: if temp_display <>

...after that thread exited, it hadn't added the exit menu item & the double click code didn't work...so I couldn't exit. Chris, AHK needs a Ctrl+Shift+Right click tray option to get the standard items in an emergency like this, when it crashes & can't exit...or make it crash in a way that exits so it don't ever get stuck like that. You might wanna move NoStandard to the bottom of the menu commands so it only does that after everything else succeeds & also use IfExist on the tray icon & only add (the special icon) if found...you should also provide a place to download the icon if that's what we're supposed to use.

_________________
AutoHotkey-Hotstring.ahk - Helping the world spell "AutoHotkey" correctly! (btw, it's a lowercase k!)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2005, 11:32 am 
Offline

Joined: October 19th, 2004, 12:11 pm
Posts: 102
OK, sorry about the icon thing; have editied it to comment this line so it won't try and find an icon that isn't there!

As for the other issue - I guess the nature of the WinText for CabinetWClass windows on your system is different than mine. I thought it would be standard, but maybe not. What Windows are you on? Mine's XP, and it's working fine.

I guess I'll look into those other options to see how else I can pull the relevant folder info from the winow.

Incidentally, what entries are being added to the menu?

C


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2005, 12:19 pm 
Offline
User avatar

Joined: December 20th, 2004, 12:19 pm
Posts: 794
Location: LooseChange911.com Ask Questions, Demand Answers █ The WTC bldgs █ shouldn't have fallen █ that fast
CarlosTheTackle wrote:
OK, sorry about the icon thing; have editied it to comment this line so it won't try and find an icon that isn't there!

...don't exactly need to comment it out, I changed that part too...

Code:
IfExist, folders.ico
   Menu, Tray, Icon, folders.ico

...& it slides past it with no problems.

CarlosTheTackle wrote:
As for the other issue - I guess the nature of the WinText for CabinetWClass windows on your system is different than mine.

...some of what Window Spy say's about the CabinetWClass...

Code:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
AutoHotkey
ahk_class CabinetWClass

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
Links
FolderView

>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<

>>>>( TitleMatchMode=slow Visible Text )<<<<
C:\Program Files\AutoHotkey
C:\Program Files\AutoHotkey

>>>>( TitleMatchMode=slow Hidden Text )<<<<

...the 1st text the script will find is "Links".

CarlosTheTackle wrote:
What Windows are you on? Mine's XP, and it's working fine.

...WinXP here too, but what toolbars are on your folder windows?

CarlosTheTackle wrote:
I guess I'll look into those other options to see how else I can pull the relevant folder info from the winow.

...my changes...

Code:
IfExist, folders.ico
   Menu, Tray, Icon, folders.ico
; ...skip...
; moved...
Menu, Tray, NoStandard
;...below the Loop which adds menu items.
; commented these out...
   ;WinGetText, rf_win_info, %rf_current_win%, %rf_current_win%,
   ;StringSplit, rf_new_folder, rf_win_info,`n
   ;rf_new_folder= %rf_new_folder1%
   ;StringTrimRight, rf_new_folder, rf_new_folder, 1
; added this...
   ControlGetText, rf_new_folder, Edit1, %rf_current_win%, %rf_current_win%,
; but I don't know why you need %rf_current_win% for both WinTitle & WinText params, should only be on WinTitle & the extra comma at the end is unnecessary.

CarlosTheTackle wrote:
Incidentally, what entries are being added to the menu?

JSLover wrote:
...& it adds a "Links" item to the list...

..."Links" is the only item it adds, for every window it sees "Links", knows that it saw it before & does nothing. With my edits it works (for me anyway...).

You need to add an OnExit command to make it run your exit sub no matter how the script exits, currently, running the script again & saying Yes to the #SingleInstance message, quit the previous copy in a way that don't save anything. Actually it don't always save even if I exit with the menu, but I haven't tried to find out why.

_________________
AutoHotkey-Hotstring.ahk - Helping the world spell "AutoHotkey" correctly! (btw, it's a lowercase k!)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2005, 3:40 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Quote:
It would be nice if either:
a) the menu order could be instructed to appear in reverse with something like 'Menu, Tray, Show, Reverse' or
b)the menu would appear upwards by default (except for when it is too close to the top of the screen).


Hey Chris, a whole set of new Menu options would be nice. I have many uses for menus, and it would be nice to have more control over them. Some examples:

  • Positional control, like Carlos hinted toward.
  • More advanced sorting options than the order in which they were added.
  • Support for icons on the individual items.
  • Certain automatic menu-building functions, like making an entire folder a submenu (with, without, or only subfolders), making other system menus into submenus, etc.
  • Possibly (I know I'm stretching it here) "tear-offs" like some menu software has - that is, you can drag the menu someplace and it will become a window of it's own.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2005, 4:04 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
CarlosTheTackle wrote:
It would be nice if either:
a) the menu order could be instructed to appear in reverse with something like 'Menu, Tray, Show, Reverse' or
b)the menu would appear upwards by default (except for when it is too close to the top of the screen).
That sounds good. I will add it to the to-do list, probably taking the former approach to avoid changing the behavior of existing scripts.

JSLover wrote:
AHK needs a Ctrl+Shift+Right click tray option to get the standard items in an emergency like this, when it crashes & can't exit...or make it crash in a way that exits so it don't ever get stuck like that.
I've considered things of that nature but decided against them to reduce code complexity, which keeps the size of compiled scripts lower. Although you do get "trapped" in rare cases, you can "end task" a script, or have another script close that script via DetectHiddenWindows and WinClose. I know it's not pretty.

jonny wrote:
a whole set of new Menu options would be nice. I have many uses for menus, and it would be nice to have more control over them.
Thanks for that great list of suggestions. I'm adding them to the to-do list next to the other menu enhancements that are planned.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2005, 11:42 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1868
if ppl are having issues regarding window class of explorers then the mod i use of this script in my 24*7 might be of some help:

Code:
WinGetActiveTitle, CurrWTitle
FileGetAttrib, PathAtr, %CurrWTitle%
IfInString, PathAtr, D
{
....
}


this might even work for other file explorers.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2005, 12:18 am 
Offline

Joined: October 19th, 2004, 12:11 pm
Posts: 102
OK, this might work better if you change (from my original post):
Code:
  ;Acquires folder path from window
   SetTitleMatchMode, Slow
   WinGetText, rf_win_info, %rf_current_win%, %rf_current_win%,
   StringSplit, rf_new_folder, rf_win_info,`n
   rf_new_folder= %rf_new_folder1%
   StringTrimRight, rf_new_folder, rf_new_folder, 1

to:
Code:
   ;Acquires folder path from window
   ControlGet, rf_new_folder, Line, 1, Edit1, %rf_current_win%


Please note, though, that this requires the Address bar to be visible in your explorer windows, or else you will need to use the original way to detect the folder path from the window. (If anyone has a sure-fire way to get the folder path from an explorer window that will work for EVERY system, be sure to let us know)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 16th, 2007, 11:17 pm 
guys this script is awesome!

I have some questions though...

Is it possible to display the whole path or at least more than the folder name in the menu :?:
I have similar folder structures with same names for different projects and when I open say folder "design" all design folders in my list open up. :o

what is the timer setting you use? 2000? I ended up with 500 otherwise nothing would come up in my folder list. Maybe I navigate to quick 8)

Is it possible to open the folder window with the folder tree (explorer bar: folders) ON :?: maybe by adding a some "explorer bar folder on" command to the call... *duckandrun*

anyway this script is great and I am glad I found it!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 16th, 2007, 11:42 pm 
error/bug :?:

has anyone any ideas about the error message I get quite often

Image

I can't figure out when it happens but sometimes it is only once, then again it won't go away!


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 40 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, JamixZol, mrhobbeys, MSN [Bot] and 24 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group