AutoHotkey Community

It is currently May 25th, 2012, 11:33 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 167 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 12  Next
Author Message
PostPosted: February 2nd, 2005, 5:30 pm 
Thanks for the adaptation of MS-Office dialogs.
It's works well at home and at the office! :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2005, 3:42 pm 
works good, thanks.
Would it be possible to show a default name for the new shortcut? For example I use the path also as the name - not fine to type it in. Perhaps one could program different templates for the default name?
Thank you again, great tool!
UREV


Report this post
Top
  
Reply with quote  
 Post subject: error at line 142
PostPosted: February 8th, 2005, 6:58 pm 
This looks like an incredibly useful script (for which, thanks!). I'm running into a problem though:

Error at line 142.

Line Text: FileGetShortcut, %f_shortcuts_folder%\%A_ThisMenuItem%.lnk, f_path
Error: This line does not contain a recognized action.

I have a Favorites folder of shortcuts in My Documents and haven't made any changes in the script. Can anyone tell me what's going wrong?

Thanks,

Michael


Report this post
Top
  
Reply with quote  
 Post subject: Problem solved
PostPosted: February 8th, 2005, 7:19 pm 
I downloaded the latest version of AutoHotkey, and the script works beautifully. (Much better than AutoDialogs and similar programs, and completely free!) Thanks again. With this script and RUNit, I'm one happy camper.

It's funny (at least to me) that posting a question so often jogs my brain into figuring out a possible solution.

Michael


Report this post
Top
  
Reply with quote  
PostPosted: February 9th, 2005, 8:19 pm 
Offline

Joined: November 28th, 2004, 10:26 pm
Posts: 58
urev wrote:
Quote:
Would it be possible to show a default name for the new shortcut? For example I use the path also as the name - not fine to type it in.


I can't use the path directly as the shortcut name because it's also the filename of the link file. ex: C:\.lnk is not a legal filename.

This new version displays a default shortcut name taken from the path with all ':' and '\' replaced with spaces. You can use any other character you want instead of a space as long as it's legal in a filename.

Code:
; Easy Access to Favorite Folders -- by Savage
; http://www.autohotkey.com

; Tested with version 1.0.23 on Win/XP

; 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


; 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


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

#SingleInstance  ; 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.
  Run, Explorer %f_path%  ; Might work on more systems without double quotes.
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 always open explorer window to f_shortcuts_folder to allow editing.
  Run, Explorer %f_shortcuts_folder%
  Reload
return


_________________
ChrisM


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2005, 1:55 pm 
Great! It really works good!
Thank you very much.
UREV


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2005, 10:27 pm 
Offline

Joined: February 6th, 2005, 11:33 pm
Posts: 8
hi guys and a big thx for this awesome script!
i did a little change on the default name for the new shortcut, because i like shorter names ;) it shows the last foldername in the path as default shortcut name.

see:

Code:
...

f_AddToFavorites:

  StringLen, f_length, f_addFavorite
   
   ;Make a default shortcut name from the last foldername in the path.
   StringGetPos, last_backslash, f_addFavorite,\, r
   StringRight, f_shortName, f_addFavorite, (f_length - last_backslash - 1)
   
   ; Resize and display inputbox.
  f_length *= 8

...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2005, 5:20 pm 
This script is a real lifesaver. The capability of using this within MS Office is a real bonus.

For some reason, I keep going back to using my mouse to run commands. I was wondering if a slight modification could be added to run with RButton & LButton with RButton still functional. I've tried ~RButton & LButton, but it doesn't seem to work very well. It functions in Open/Save as dialogue windows but not in explorer. Thanks in advance.

(I used to use PathBuddy2 that has a similar function of Favorite Folders -- and it uses RButton & LButton to trigger.)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 30th, 2005, 2:00 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Hotfoot wrote:
... to run with RButton & LButton with RButton still functional. I've tried ~RButton & LButton, but ... it functions in Open/Save as dialogue windows but not in explorer.
Yes, it's tricky to get combinations of LButton+RButton working without giving up something. You might try using ~MButton & LButton instead. If that's no good, go back to ~RButton & LButton and have the hotkey do special handling as a workaround whenever an Explorer window is active. Special handling might be to send an Escape keystroke to dismiss the context menu, but I'm not sure.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 30th, 2005, 11:58 pm 
Offline

Joined: November 28th, 2004, 10:26 pm
Posts: 58
Make these changes:

Code:
f_Hotkey = ~LButton & RButton
;f_Hotkey = ^MButton

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

#NoTrayIcon
#SingleInstance  ; 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


The last three lines I commented out are why Explorer wouldn't work with
~RButton & LButton. Explorer is an unsupported window type according to Savage's original intent. I think this section of code needs to be rethought and perhaps remove this if else statement.

You need to press left mouse first then right mouse.
I haven't heavily tested it yet, but both left and right buttons seem to behave normally on their own for me.
I use Win XP SP2 and AHK ver 1.0.31.07.

Let me know how this works out.

_________________
ChrisM


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2005, 8:05 am 
Offline

Joined: May 2nd, 2005, 8:02 am
Posts: 12
May I suggest two aimportant additions:

-separators. I would like to have the display of my favorite folders divide in sections, through separators. This was easy to do in ini. How do you do that with a directory full of shortcuts?

-open office: the save box of openoffice is terrible. this script would make it quite easier to use it.

Thanks! :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2005, 3:10 pm 
On the off chance there are others like me who prefer to have Windows Explorer open with the folder pane visible, you can change the following line

Code:
  Run, Explorer %f_path%  ; Might work on more systems without double quotes.


to this

Code:
  f_command = Explorer /e, %f_path%
  Run, %f_command%


I assume most people who would want this have made the change any way, but I figure someone might find it useful.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2005, 9:42 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
dmiranda wrote:
I would like to have the display of my favorite folders divide in sections, through separators. This was easy to do in ini. How do you do that with a directory full of shortcuts?
Maybe by having a special file or folder name whose only purpose is to signal the script where a separator line should be drawn in the menu.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2005, 12:20 pm 
Offline

Joined: November 28th, 2004, 10:26 pm
Posts: 58
dmiranda wrote:
Quote:
-open office: the save box of openoffice is terrible. this script would make it quite easier to use it.

What is the problem? Does it not work with open office? If not you probably have to find out what class of window the save box is and add it to the list of supported window types.

dmiranda wrote:
Quote:
-separators. I would like to have the display of my favorite folders divide in sections, through separators. This was easy to do in ini. How do you do that with a directory full of shortcuts?

Chris wrote:
Quote:
Maybe by having a special file or folder name whose only purpose is to signal the script where a separator line should be drawn in the menu.

I had thought of using the description parameter of the FileCreateShortcut command for this purpose as well as to indicate the order that an item should appear in the menu. I don't think there would be any drawback or conflict using the description parameter like this. But it may be some time before I get the chance to do it.
So if anyone else would like to try...go for it!

_________________
ChrisM


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 6th, 2005, 5:47 am 
Offline

Joined: May 2nd, 2005, 8:02 am
Posts: 12
Quote:
What is the problem? Does it not work with open office? If not you probably have to find out what class of window the save box is and add it to the list of supported window types


Yeah, does not work in openoffice, which is a pitty. Using active windows info, the reported class is ahk_class SALSUBFRAME. But I have no idea where to put that in the code. Sowy, i am a newb here :roll:

Quote:
I had thought of using the description parameter of the FileCreateShortcut command for this purpose as well as to indicate the order that an item should appear in the menu. I don't think there would be any drawback or conflict using the description parameter like this. But it may be some time before I get the chance to do it. So if anyone else would like to try...go for it!


Same as above. I love the versatility of this program, but am too new at it to code it. Thanks!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 167 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 12  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: JamixZol, Morpheus and 31 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