PageRenderTime 49ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/AutoHotkey.docset/Contents/Resources/Documents/scripts/FavoriteFolders.htm

https://gitlab.com/ahkscript/Autohotkey.docset
HTML | 202 lines | 185 code | 17 blank | 0 comment | 0 complexity | 07128284146251e17e7d6d6bf2e824ef MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Easy Access to Favorite Folders -- by Savage</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  8. <script src="../static/content.js" type="text/javascript"></script>
  9. </head>
  10. <body>
  11. <h1>Easy Access to Favorite Folders -- by Savage</h1>
  12. <p>When you click the middle mouse button while certain types of
  13. windows are active, this script displays a menu of your favorite
  14. folders. Upon selecting a favorite, the script will instantly
  15. switch to that folder within the active window. The following
  16. window types are supported: 1) Standard file-open or file-save
  17. dialogs; 2) Explorer windows; 3) Console (command prompt) windows.
  18. The menu can also be optionally shown for unsupported window
  19. types, in which case the chosen favorite will be opened as a new
  20. Explorer window.
  21. </p>
  22. <p><a href="FavoriteFolders.ahk">Download This Script</a> &nbsp;| &nbsp;<a href="index.htm">Other Sample Scripts</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">Home</a></p>
  23. <pre class="NoIndent"><em>; Note: In Windows Explorer, if &quot;View &gt; Toolbars &gt; Address Bar&quot; is
  24. ; not enabled, the menu will not be shown if the hotkey chosen below
  25. ; has a tilde. If it does have a tilde, the menu will be shown
  26. ; but the favorite will be opened in a new Explorer window rather
  27. ; than switching the active Explorer window to that folder.</em>
  28. <em>; CONFIG: CHOOSE YOUR HOTKEY
  29. ; If your mouse has more than 3 buttons, you could try using
  30. ; XButton1 (the 4th) or XButton2 (the 5th) instead of MButton.
  31. ; You could also use a modified mouse button (such as ^MButton) or
  32. ; a keyboard hotkey. In the case of MButton, the tilde (~) prefix
  33. ; is used so that MButton's normal functionality is not lost when
  34. ; you click in other window types, such as a browser. The presence
  35. ; of a tilde tells the script to avoid showing the menu for
  36. ; unsupported window types. In other words, if there is no tilde,
  37. ; the hotkey will always display the menu; and upon selecting a
  38. ; favorite while an unsupported window type is active, a new
  39. ; Explorer window will be opened to display the contents of that
  40. ; folder.</em>
  41. f_Hotkey = ~MButton
  42. <em>; CONFIG: CHOOSE YOUR FAVORITES
  43. ; Update the special commented section below to list your favorite
  44. ; folders. Specify the name of the menu item first, followed by a
  45. ; semicolon, followed by the name of the actual path of the favorite.
  46. ; Use a blank line to create a separator line.</em>
  47. <em>/*
  48. ITEMS IN FAVORITES MENU &lt;-- Do not change this string.
  49. Desktop ; %A_Desktop%
  50. Favorites ; %A_Desktop%\..\Favorites
  51. My Documents ; %A_MyDocuments%
  52. Program Files; %A_ProgramFiles%
  53. */</em>
  54. <em>; END OF CONFIGURATION SECTION
  55. ; Do not make changes below this point unless you want to change
  56. ; the basic functionality of the script.</em>
  57. #SingleInstance <em>; Needed since the hotkey is dynamically created.</em>
  58. Hotkey, %f_Hotkey%, f_DisplayMenu
  59. StringLeft, f_HotkeyFirstChar, f_Hotkey, 1
  60. if f_HotkeyFirstChar = ~ <em>; Show menu only for certain window types.</em>
  61. f_AlwaysShowMenu = n
  62. else
  63. f_AlwaysShowMenu = y
  64. <em>; Used to reliably determine whether script is compiled:</em>
  65. SplitPath, A_ScriptName,,, f_FileExt
  66. if f_FileExt = Exe <em>; Read the menu items from an external file.</em>
  67. f_FavoritesFile = %A_ScriptDir%\Favorites.ini
  68. else <em>; Read the menu items directly from this script file.</em>
  69. f_FavoritesFile = %A_ScriptFullPath%
  70. <em>;----Read the configuration file.</em>
  71. f_AtStartingPos = n
  72. f_MenuItemCount = 0
  73. Loop, Read, %f_FavoritesFile%
  74. {
  75. if f_FileExt &lt;&gt; Exe
  76. {
  77. <em>; Since the menu items are being read directly from this</em>
  78. <em>; script, skip over all lines until the starting line is</em>
  79. <em>; arrived at.</em>
  80. if f_AtStartingPos = n
  81. {
  82. IfInString, A_LoopReadLine, ITEMS IN FAVORITES MENU
  83. f_AtStartingPos = y
  84. continue <em>; Start a new loop iteration.</em>
  85. }
  86. <em>; Otherwise, the closing comment symbol marks the end of the list.</em>
  87. if A_LoopReadLine = */
  88. break <em>; terminate the loop</em>
  89. }
  90. <em>; Menu separator lines must also be counted to be compatible</em>
  91. <em>; with A_ThisMenuItemPos:</em>
  92. f_MenuItemCount++
  93. if A_LoopReadLine = <em>; Blank indicates a separator line.</em>
  94. Menu, Favorites, Add
  95. else
  96. {
  97. StringSplit, f_line, A_LoopReadLine, `;
  98. f_line1 = %f_line1% <em>; Trim leading and trailing spaces.</em>
  99. f_line2 = %f_line2% <em>; Trim leading and trailing spaces.</em>
  100. <em>; Resolve any references to variables within either field, and</em>
  101. <em>; create a new array element containing the path of this favorite:</em>
  102. Transform, f_path%f_MenuItemCount%, deref, %f_line2%
  103. Transform, f_line1, deref, %f_line1%
  104. Menu, Favorites, Add, %f_line1%, f_OpenFavorite
  105. }
  106. }
  107. return <em>;----End of auto-execute section.</em>
  108. <em>;----Open the selected favorite</em>
  109. f_OpenFavorite:
  110. <em>; Fetch the array element that corresponds to the selected menu item:</em>
  111. StringTrimLeft, f_path, f_path%A_ThisMenuItemPos%, 0
  112. if f_path =
  113. return
  114. if f_class = #32770 <em>; It's a dialog.</em>
  115. {
  116. if f_Edit1Pos &lt;&gt; <em>; And it has an Edit1 control.</em>
  117. {
  118. <em>; Activate the window so that if the user is middle-clicking</em>
  119. <em>; outside the dialog, subsequent clicks will also work:</em>
  120. WinActivate ahk_id %f_window_id%
  121. <em>; Retrieve any filename that might already be in the field so</em>
  122. <em>; that it can be restored after the switch to the new folder:</em>
  123. ControlGetText, f_text, Edit1, ahk_id %f_window_id%
  124. ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
  125. ControlSend, Edit1, {Enter}, ahk_id %f_window_id%
  126. Sleep, 100 <em>; It needs extra time on some dialogs or in some cases.</em>
  127. ControlSetText, Edit1, %f_text%, ahk_id %f_window_id%
  128. return
  129. }
  130. <em>; else fall through to the bottom of the subroutine to take standard action.</em>
  131. }
  132. else if f_class in ExploreWClass,CabinetWClass <em>; In Explorer, switch folders.</em>
  133. {
  134. if f_Edit1Pos &lt;&gt; <em>; And it has an Edit1 control.</em>
  135. {
  136. ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
  137. <em>; Tekl reported the following: &quot;If I want to change to Folder L:\folder</em>
  138. <em>; then the addressbar shows http://www.L:\folder.com. To solve this,</em>
  139. <em>; I added a {right} before {Enter}&quot;:</em>
  140. ControlSend, Edit1, {Right}{Enter}, ahk_id %f_window_id%
  141. return
  142. }
  143. <em>; else fall through to the bottom of the subroutine to take standard action.</em>
  144. }
  145. else if f_class = ConsoleWindowClass <em>; In a console window, CD to that directory</em>
  146. {
  147. WinActivate, ahk_id %f_window_id% <em>; Because sometimes the mclick deactivates it.</em>
  148. SetKeyDelay, 0 <em>; This will be in effect only for the duration of this thread.</em>
  149. IfInString, f_path, : <em>; It contains a drive letter</em>
  150. {
  151. StringLeft, f_path_drive, f_path, 1
  152. Send %f_path_drive%:{enter}
  153. }
  154. Send, cd %f_path%{Enter}
  155. return
  156. }
  157. <em>; Since the above didn't return, one of the following is true:
  158. ; 1) It's an unsupported window type but f_AlwaysShowMenu is y (yes).
  159. ; 2) It's a supported type but it lacks an Edit1 control to facilitate the custom
  160. ; action, so instead do the default action below.</em>
  161. Run, Explorer %f_path% <em>; Might work on more systems without double quotes.</em>
  162. return
  163. <em>;----Display the menu</em>
  164. f_DisplayMenu:
  165. <em>; These first few variables are set here and used by f_OpenFavorite:</em>
  166. WinGet, f_window_id, ID, A
  167. WinGetClass, f_class, ahk_id %f_window_id%
  168. if f_class in #32770,ExploreWClass,CabinetWClass <em>; Dialog or Explorer.</em>
  169. ControlGetPos, f_Edit1Pos,,,, Edit1, ahk_id %f_window_id%
  170. if f_AlwaysShowMenu = n <em>; The menu should be shown only selectively.</em>
  171. {
  172. if f_class in #32770,ExploreWClass,CabinetWClass <em>; Dialog or Explorer.</em>
  173. {
  174. if f_Edit1Pos = <em>; The control doesn't exist, so don't display the menu</em>
  175. return
  176. }
  177. else if f_class &lt;&gt; ConsoleWindowClass
  178. return <em>; Since it's some other window type, don't display menu.</em>
  179. }
  180. <em>; Otherwise, the menu should be presented for this type of window:</em>
  181. Menu, Favorites, show
  182. return
  183. </pre>
  184. </body>
  185. </html>