AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Favorite Folders popup menu that you can change on the fly.
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Mon Jun 06, 2005 12:34 am    Post subject: Reply with quote

Thanks for posting this combined version.

Perhaps the version in the script showcase should be updated. I haven't been keeping up with all the changes, so my main concerns are that it isn't missing any of its original functionality and that beginners will still find it easy to set up and configure.
Back to top
View user's profile Send private message Send e-mail
guivho



Joined: 04 Jun 2005
Posts: 26
Location: Lokeren, Belgium

PostPosted: Mon Jun 06, 2005 6:26 pm    Post subject: Reply with quote

Chris,

I agree that the showcase version should be updated.

I do not know how this is done
nor how and by whom it is decided to do so.

I believe that the original functionality is still there,
and that it is still easy to setup and configure.

Maybe we should check this with Savage, the original author.

By the way, while using the posted script, I detected a little bug:
the %path% variable in the run statement needs to be double quoted.
I had a couple of links with one or more spaces in them,
and I could not browse them without quotes around the %path% variable.

I have also added a Time-stamp line so that people can
check their version against the one posted in this thread or in the showcase.

Guido

So here's my current version:
Code:
; Easy Access to Favorite Folders -- by Savage
; http://www.autohotkey.com

; Tested with version 1.0.23 on Win/XP
; Time-stamp: <FavoriteFolders.ahk 2005/06/06 19:17:53 +0200 guivho>

; When you click the middle mouse button while certain types of
; windows are active, this script displays a menu of your favorite
; folders.  Upon selecting a favorite, the script will instantly
; switch to that folder within the active window.  The following
; window types are supported: 1) Standard file-open or file-save
; dialogs; 2) Explorer windows; 3) Console (command prompt)
; windows; 4) Microsoft Office file Open and Save As dialogs.           ;jh0105
; The menu can also be optionally shown for unsupported window
; types, in which case the chosen favorite will be opened as a new
; Explorer window.

; Note: In Windows Explorer, if "View > Toolbars > Address Bar" is
; not enabled, the menu will not be shown if the hotkey chosen below
; has a tilde.  If it does have a tilde, the menu will be shown
; but the favorite will be opened in a new Explorer window rather
; than switching the active Explorer window to that folder.

; Revisions - by JHoward                                                ;jh0105
; Added support for Microsoft Office Open and Save As dialog boxes.     ;jh0105
;
; Revisions - by Sandeep
; Menu items now point to folder shortcuts ( link files ) in the
; directory of your choice. The name of the shortcut is what appears
; in the popup menu. The shortcut's target is used to switch the
; active window.
;
; Revisions - by ChrisM
; Two menu items always appear at the bottom:
;  - Add to Favorites - allows the user to add new menu items and
; make new link files. Valid paths can be extracted from any window
; title or from the clipboard.
;  - Edit Favorites Folder - conveniently opens an explorer window
; to the link files.
; Adding numbers to the start of link file names will sort the
; menu in that order. The menu is alphabetically sorted.
;
; Added the default shortcut name as the found path with the ':' and '\' ;cm0205
; replaced with spaces to make a legal link file name.                   ;cm0205
;
; Revisions - by guivho
; - Formally define desired directory explorer/editor
; - Use the defined explorer to run in the fall-through case
; - use the defined explorer to edit the favorites folder
; - Double quotes around %path% in run statement are needed if any
;   of the lnk names contain spaces

; CONFIG: CHOOSE DIRECTORY TO HOLD SHORTCUTS
; Set the following variable to the folder name which holds all your
; folder shortcuts. The suggested place is
; %HOMEPATH%\My Documents\Favorites for easy access from other apps.
f_shortcuts_folder =%USERPROFILE%\My Documents\Favorites

; CONFIG: CHOOSE RELOADING
; Set the following variable to 1 to always reload the menu and 0 to
; disable automatic reloading. Keep this 1 unless you have a really
; long list, because it harldy takes any time to load. But if you
; don't change your list very often, then you may want to keep it 0.
f_AlwaysReload = 1


; CONFIG: CHOOSE YOUR HOTKEY
; If your mouse has more than 3 buttons, you could try using
; XButton1 (the 4th) or XButton2 (the 5th) instead of MButton.
; You could also use a modified mouse button (such as ^MButton) or
; a keyboard hotkey.  In the case of MButton, the tilde (~) prefix
; is used so that MButton's normal functionality is not lost when
; you click in other window types, such as a browser.  The presence
; of a tilde tells the script to avoid showing the menu for
; unsupported window types.  In other words, if there is no tilde,
; the hotkey will always display the menu; and upon selecting a
; favorite while an unsupported window type is active, a new
; Explorer window will be opened to display the contents of that
; folder.
f_Hotkey = ^MButton

; CONFIG: CHOOSE YOUR DIRECTORY BROWSER / EDITOR
; define your preferred explorer in one of following ways:
; f_Explorer = explorer.exe /e, ;open explorer in dual pane mode
; f_Explorer = d:\ap\totalcmd\totalcmd.exe ;use total commander
f_Explorer = explorer.exe /n, ;open explorer in single pane mode

; END OF CONFIGURATION SECTION
; Do not make changes below this point unless you want to change
; the basic functionality of the script.

#SingleInstance, Force ; Needed since the hotkey is dynamically created.

Hotkey, %f_Hotkey%, f_DisplayMenu
StringLeft, f_HotkeyFirstChar, f_Hotkey, 1
If f_HotkeyFirstChar = ~  ; Show menu only for certain window types.
  f_AlwaysShowMenu = n
else
  f_AlwaysShowMenu = y


;----Build the menu from link files found in f_shortcuts_folder.
f_CreateMenu:
  If f_AlwaysReload = 1
  {
     If f_NotFirstTime = true
        Menu, Favorites, DeleteAll
  }
  else
  {
     If f_NotFirstTime = true
        return
  }
  f_NotFirstTime = true

  ; Retrieve file names in sorted order:
  f_FileList =  ; Initialize to be blank.
  Loop, %f_shortcuts_folder%\*.lnk
    f_FileList = %f_FileList%`n%A_LoopFileName%
  Sort, f_FileList

  f_MenuItemCount = 0
  Loop, parse, f_FileList, `n
  {
    If A_LoopField =  ; Ignore the blank item at the end of the list.
      continue
    StringLen, f_LenFileName, A_LoopField
    f_LenFileName -= 4
    StringLeft, f_MenuItemName, A_LoopField, %f_LenFileName% ;To cut off .lnk
    f_MenuItemCount++
    ; Build an array of menu names to check for duplicates in f_AddToFavorites.
    Transform, f_menuName%f_MenuItemCount%, deref, %f_MenuItemName%
    Menu, Favorites, add, %f_MenuItemName%, f_OpenFavorite
  }

  ; Add a separator line.
  Menu, Favorites, Add
  ; Add a command to capture the current folder address.
  Menu, Favorites, Add, Add to Favorites, f_FindPath
  ; Add a command to allow the user to edit the shortcuts.
  Menu, Favorites, Add, Edit Favorites Folder, f_EditFavorites
  ; Show Reload menu only if not set to reload on every popup.
  If f_AlwaysReload = 0
    Menu,Favorites,add,Reload,Reload
return


Reload:
   Reload
return


;----Open the selected favorite
f_OpenFavorite:
  ; Fetch the shortcut's target that corresponds to the selected menu item:
  FileGetShortcut, %f_shortcuts_folder%\%A_ThisMenuItem%.lnk, f_path
  If f_path =
    return
  If f_class = #32770    ; It's a dialog.
  {
    If f_Edit1Pos <>   ; And it has an Edit1 control.
    {
      ; Activate the window so that if the user is middle-clicking
      ; outside the dialog, subsequent clicks will also work:
      WinActivate ahk_id %f_window_id%
      ; Retrieve any filename that might already be in the field so
      ; that it can be restored after the switch to the new folder:
      ControlGetText, f_text, Edit1, ahk_id %f_window_id%
      ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
      ControlSend, Edit1, {Enter}, ahk_id %f_window_id%
      Sleep, 100  ; It needs extra time on some dialogs or in some cases.
      ControlSetText, Edit1, %f_text%, ahk_id %f_window_id%
      return
    }
    ; else fall through to the bottom of the subroutine to take standard action.
  }
  else If f_class in ExploreWClass,CabinetWClass  ; In Explorer, switch folders.
  {
    If f_Edit1Pos <>   ; And it has an Edit1 control.
    {
      ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
      ; Tekl reported the following: "If I want to change to Folder L:\folder
      ; then the addressbar shows http://www.L:\folder.com. To solve this,
      ; I added a {right} before {Enter}":
      ControlSend, Edit1, {Right}{Enter}, ahk_id %f_window_id%
      return
    }
    ; else fall through to the bottom of the subroutine to take standard action.
  }
  else IfInString, f_class, bosa_sdm_  ; Microsoft Office application   ;jh0105
  {                                                                     ;jh0105
    ; Activate the window so that if the user is middle-clicking        ;jh0105
    ; outside the dialog, subsequent clicks will also work:             ;jh0105
    WinActivate ahk_id %f_window_id%                                    ;jh0105
    ; Retrieve any file name that might already be in the File name     ;jh0105
    ; control, so that it can be restored after the switch to the new   ;jh0105
    ; folder.                                                           ;jh0105
    ControlGetText, f_text, RichEdit20W2, ahk_id %f_window_id%          ;jh0105
    ControlClick, RichEdit20W2, ahk_id %f_window_id%                    ;jh0105
    ControlSetText, RichEdit20W2, %f_path%, ahk_id %f_window_id%        ;jh0105
    ControlSend, RichEdit20W2, {Enter}, ahk_id %f_window_id%            ;jh0105
    Sleep, 100  ; It needs extra time on some dialogs or in some case   ;jh0105
    ControlSetText, RichEdit20W2, %f_text%, ahk_id %f_window_id%        ;jh0105
    return                                                              ;jh0105
  }                                                                     ;jh0105
  else If f_class = ConsoleWindowClass ; In a console window, CD to that directory
  {
    WinActivate, ahk_id %f_window_id% ; Because sometimes the mclick deactivates it.
    SetKeyDelay, 0  ; This will be in effect only for the duration of this thread.
    IfInString, f_path, :  ; It contains a drive letter
    {
      StringLeft, f_path_drive, f_path, 1
      Send %f_path_drive%:{enter}
    }
    Send, cd %f_path%{Enter}
    return
  }
  ; Since the above didn't return, one of the following is true:
  ; 1) It's an unsupported window type but f_AlwaysShowMenu is y (yes).
  ; 2) It's a supported type but it lacks an Edit1 control to facilitate the custom
  ;    action, so instead do the default action below.
  ; Use the preferred directory browser of the user
  Run, %f_Explorer% "%f_path%"
return


;----Display the menu
f_DisplayMenu:
  ; This next variable is used to record the title of the ative window when popup menu
  ; was called. This variable is then used in f_AddToFavorites: if user wants to save it.
  WinGetActiveTitle, f_addFavorite

  ; These first few variables are set here and used by f_OpenFavorite:
  WinGet, f_window_id, ID, A
  WinGetClass, f_class, ahk_id %f_window_id%
  If f_class in #32770,ExploreWClass,CabinetWClass  ; Dialog or Explorer.
    ControlGetPos, f_Edit1Pos,,,, Edit1, ahk_id %f_window_id%
  If f_AlwaysShowMenu = n  ; The menu should be shown only selectively.
  {
    If f_class in #32770,ExploreWClass,CabinetWClass  ; Dialog or Explorer.
    {
      If f_Edit1Pos =  ; The control doesn't exist, so don't display the menu
        return
    }
    else
    {                                                                   ;jh0105
      If f_class <> ConsoleWindowClass
      {                                                                 ;jh0105
         IfNotInString, f_class, bosa_sdm_  ; Microsoft Office application ;jh0105
            return  ; Since it's some other window type, don't display menu.
      }                                                                 ;jh0105
    }                                                                   ;jh0105
  }
  ; Otherwise, the menu should be presented for this type of window:
  gosub f_CreateMenu
  Menu, Favorites, show
return


;----Try to find a valid path from the active window title or the clipboard.
f_FindPath:
  ; First, test whole active window title as valid path.
  IfExist, %f_addFavorite%
  {
    GoSub, f_AddToFavorites
    return
  }

  ; Second, test clipboard contents for valid path.
  f_clipboard = %clipboard%
  IfExist, %f_clipboard%
  {
    f_addFavorite = %clipboard%
    GoSub, f_AddToFavorites
    return
  }

  ; Third, parse the Active window title for a valid path.
  f_index = 0
  f_goodPath = ; Initialize to blank
  ; Loop one character at a time. This is like "Loop, Count". It ensures
  ; we loop once for every character without having to find the string length.
  Loop, Parse, f_addFavorite
  {
    f_index++
    ; Keep adding characters from the right.
    StringRight, f_newPath, f_addFavorite, %f_index%
    ; Get rid of everything to the right of the last "\".
    SplitPath, f_newPath, , f_OutDir
    ; Only keep a path that is valid.
    IfExist, %f_OutDir%
      f_goodPath = %f_OutDir%
  }
  IfExist, %f_goodPath%
  {
    f_addFavorite = %f_goodPath%
    GoSub, f_AddToFavorites
    return
  }

  ; Report to user that no valid path was found.
  MsgBox, No valid path was found. The folder path to be added must be in the active window title or on the clipboard.  ;jh0105
return


;----Save found valid path to a new link file in f_shortcuts_folder.
f_AddToFavorites:
   ; Make a default shortcut name from the path.                         ;cm0205
   ; Replace ':' and '/' with spaces to make a legal filename.           ;cm0205
   StringReplace, f_shortName, f_addFavorite, :, %A_Space%, All          ;cm0205
   StringReplace, f_shortName, f_shortName, \, %A_Space%, All            ;cm0205
   ; Resize and display inputbox.
  StringLen, f_length, f_addFavorite
  f_length *= 8
  If f_length < 340
    f_length = 340
  f_msg = Found: %f_addFavorite%`nWhat name would you like to give the Favorite shortcut
  InputBox, f_shortName, Favorite Name, %f_msg%, ,%f_length%, 140, , , , , %f_shortName% ;cm0205
  ; If OK was pressed, try to add menu item.
  If ErrorLevel = 0
  {
    f_shortName = %f_shortName%  ; Trim leading and trailing spaces.
    If f_shortName =
    {
      MsgBox, You must supply a name for the shortcut.
      return
    }
    StringLower, f_test, f_shortName
    ; Loop thru existing menu items to check for duplicates.
    f_index = 0
    Loop, %f_MenuItemCount%
    {
      f_index++
      StringLower, f_nextMenu, f_MenuName%f_index%
      IfEqual f_nextMenu, %f_test%
      {
        MsgBox, The name %f_shortName% is already in the menu.`nTry again.
        return
      }
    }

    ; Here's where we save the menu item to file.
    FileCreateShortcut, %f_addFavorite%, %f_shortcuts_folder%\%f_shortName%.lnk
      ; If errorlevel is not 0 it's most likely %f_shortName%.lnk is not ;cm0205
      ; a legal filename.                                                ;cm0205
      ; Other possible problems are no write permissions, etc.           ;cm0205
      if ErrorLevel <> 0                                                 ;cm0205
        MsgBox, The name %f_shortName% is not a legal filename.`nTry again. ;cm0205
      else                                                               ;cm0205
         MsgBox, The path %f_addFavorite% has been added to favorites.   ;cm0205
  }
return


;----Open explorer window to f_shortcuts_folder to allow user to edit the shortcuts.
f_EditFavorites:
  ; We use the defined directory editor to edit f_shortcuts_folder
  Run, %f_explorer% %f_shortcuts_folder%
  Reload
return
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Aug 18, 2005 7:15 am    Post subject: Reply with quote

Hi,
I would be interested in the changes savage made also!
"sub folders" would be cool.

Would it be possible to add separating lines to the menu?

Bye,urev
Back to top
papexus
Guest





PostPosted: Sat Aug 20, 2005 3:46 am    Post subject: how do you add the topmost "Desktop" folder ? Reply with quote

Hello,

Can someone tell me how to add the root desktop folder (the one above my computer) to this list of favorite folders?
When I try adding it, I get the error message:
"no valid path was found..."

thanks in advance

papex
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sat Aug 20, 2005 3:33 pm    Post subject: Reply with quote

Although I haven't reviewed exactly how to integrate it with this script, there is a built-in variable A_Desktop, which contains the full path and name of the folder containing the current user's desktop files.
Back to top
View user's profile Send private message Send e-mail
ChrisM



Joined: 28 Nov 2004
Posts: 58

PostPosted: Sun Aug 21, 2005 1:59 am    Post subject: Reply with quote

Quote:
Can someone tell me how to add the root desktop folder (the one above my computer) to this list of favorite folders?

I'm assuming Win XP in my comments below. Reply back if this does not work for you.

The desktop link above My Computer in a file browser window is a special Windows link, not the actual directory.
Open a file browser window ( Start -> My Computer ) and double click your way to your desktop directory. For a typical Windows install it will be:
C:\Documents and Settings\your_user_account_name\Desktop

If you don't know your user name ( the name that appears on the welcome login screen may not always be the same as your actual user account name ) open a command prompt window - Start -> All Programs -> Accessories -> Command Prompt
By default it starts with a prompt in your user account directory, like this:
C:\Documents and Settings\your_user_account_name>
If not you can type "set" and look for the folowing line:
USERPROFILE=C:\Documents and Settings\your_user_account_name

Once you have browsed to the actual desktop directory be sure you can se the full path in the browser title bar. If not: Tools -> Folder Options -> View -> turn on 'Display the full path in the title bar'
You can now add it to the list of favorites.

Hope this helps.
_________________
ChrisM
Back to top
View user's profile Send private message
papexus



Joined: 20 Aug 2005
Posts: 10

PostPosted: Sun Aug 21, 2005 7:28 am    Post subject: Reply with quote

hello,

Maybe my initial post was a bit confused.
I am under win xp andthe question is:
when in a open or save dialog with a non microsoft office dialog I would like to be able, trough the script, to have access to the same kind of window that is available with the "Burau" (desktop?) button of the microsoft office open & save dialog. I am using a french system so I am not sure of that button name in english systems, but clicking on it (bureau) will take at the topmost root of the system which is "poste de travail" maybe equivalent to "my computer" ?
I tried to use the quicklaunch button "toggle desktop" but I do not know how to integrate it with the script.

Thanks to all for your help,

papex
Back to top
View user's profile Send private message
ChrisM



Joined: 28 Nov 2004
Posts: 58

PostPosted: Sun Aug 21, 2005 11:05 am    Post subject: Reply with quote

Quote:
when in a open or save dialog with a non microsoft office dialog I would like to be able, trough the script, to have access to the same kind of window that is available with the "Burau" (desktop?) button of the microsoft office open & save dialog.

OK, now I see what your trying to do.

The Favorites Folder script, as written, only shows the contents of real directories. When you click the "Burau" or Desktop link that appears in some dialogs Windows does not take you to a real directory. Instead it builds a list made up of links, My Documents, My Computer, My Network Places, for example, plus it adds whatever is in the "All Users" desktop directory and finally whatever is in your user desktop directory.

Here's a workaround that requires one extra click:
Do the steps in my previous post to put your actual user Desktop directory on the Favorites Folder menu. I'll rename the link 'Desktop' for this example.
Bring up your Favorites Folder menu and click 'Edit Favorites Folder'.
Now save that folder as a Favorite - bring up your Favorites Folder menu and click 'Add to Favorites'. You may want to rename it 'Desktop Workaround' for example.

Now whenever you want to get to the Desktop bring up your Favorites Folder menu, click 'Desktop Workaround' then click 'Desktop'.
Windows will rebuild that list of links and directories.

Hope this helps.
_________________
ChrisM
Back to top
View user's profile Send private message
papexus



Joined: 20 Aug 2005
Posts: 10

PostPosted: Sun Aug 21, 2005 12:10 pm    Post subject: Reply with quote

dear ChrisM,

thank you very much for the help. Although I still do not understand how it does it, but it works !

Thanks again

papex
Back to top
View user's profile Send private message
papexus



Joined: 20 Aug 2005
Posts: 10

PostPosted: Mon Aug 22, 2005 5:52 am    Post subject: Reply with quote

ChrisM,

Actually, your workaround works well in an explorer window but in an open dialog the application will try to open the link file for "bureau" instead of navigating to the "directory" of the desktop.
for example in a notepad open dialog, clicking on the workaround desktop will show the favorite folders, then clicking on the desktop link opens the link file in notepad!

hope you can help again !

with thanks

papex
Back to top
View user's profile Send private message
Hotfoot
Guest





PostPosted: Sat Aug 27, 2005 2:21 am    Post subject: subfolders in Favorite Folders Reply with quote

savage,

can you post your version of the script that allows subfolders?

-------

I tried taking a look at savage's foldermenu function, but it is beyond my limited knowlegdge of AutoHotkey to try to integrate it into the Favorite Folders script. Anyone with more experience care to try?

http://www.autohotkey.com/forum/viewtopic.php?t=3745&highlight=foldermenu
Back to top
webber



Joined: 25 Aug 2005
Posts: 60

PostPosted: Mon Aug 29, 2005 6:53 pm    Post subject: using standard open Files dialog box Reply with quote

If the shortcut is to a folder instead of a file, is it possible to use the "Open Files" dialog instead of Explorer ?
_________________
winxp pro sp2
AHK v1.0.38.02

----------------------------------
One man's preacher is another man's terrorist
Back to top
View user's profile Send private message
ChrisM



Joined: 28 Nov 2004
Posts: 58

PostPosted: Tue Aug 30, 2005 2:21 am    Post subject: Reply with quote

Quote:
is it possible to use the "Open Files" dialog instead of Explorer ?

I'm not sure what you mean. Could you explain more?
_________________
ChrisM
Back to top
View user's profile Send private message
webber



Joined: 25 Aug 2005
Posts: 60

PostPosted: Tue Aug 30, 2005 5:44 am    Post subject: Reply with quote

In any application, like Textpad, if you click on the "File -> open" menu item it will bring up a dialog for file selection.

if possible it would be nice to pass the path to the dialog and have it in use instead of Explorer.
_________________
winxp pro sp2
AHK v1.0.38.02

----------------------------------
One man's preacher is another man's terrorist
Back to top
View user's profile Send private message
ChrisM



Joined: 28 Nov 2004
Posts: 58

PostPosted: Tue Aug 30, 2005 11:08 am    Post subject: Reply with quote

It does work inside File->Open dialogs. Once you have any File->Open or File->Save dialog open and active fire your hotkey to bring up your FavoritesFolder menu and select any shortcut. The File->Open dialog will switch to that folder.

Or are you thinking of having the File->Open dialog as the default action?
Such as on an empty desktop with no app running selecting a shortcut from your FavoritesFolder menu would open a certain app and then open the File->Open dialog and then switch to that folder?
_________________
ChrisM
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Page 5 of 10

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group