In dialogue windows like ‘Save’ or ‘Save As’ in XP and Vista, or ‘Insert Picture from File’ in Word you have to navigate a folder tree to get to the folder you want. If you have the folder visible already, say in Windows Explorer or on the desktop, it’s annoying that you can’t quickly transfer its path into the window. This script provides a solution.
Here are some screenshots:
http://docs.google.com/Doc?id=dccck29f_8hr2nj3dz.
Code:
; ;;;;;;;;;;;
;
; 'Send To Dialog Window'
; By DAT, 25-01-2009.
;
; Acknowledgement:
; The function f_Open_Target(target) is based on "Easy Access to Favorite
; Shortcuts" by ChrisM at http://www.autohotkey.com/forum/topic5414.html.
; I modified it to work with Directory Opus, 'Move To' and 'Copy To',
; and 'Export Registry File' in both Vista and XP.
;
; First you need to install a new item 'Send To Dialog Window' to the
; folder context menu (see below). After that, if you right-click on any
; folder icon and click 'Send To Dialog Window', the folder will be entered
; automatically in the 'Save in:' field in 'Save As' and other similar windows.
;
; This bypasses the restricted navigation options in the dialog Window.
; It's especially handy if you navigate to folders via popup cascaded menus.
; For example, the My Documents cascade in the XP Classic Start Menu
; after you enable 'Expand My Documents'. Or even better, popup toolbars from
; 'True Launch Bar'.
;
; It works with all the dialog windows I've found (so far) in Windows XP and Vista,
; Office 2003, and Directory Opus.
;
; It also works with the 'Move Items' and 'Copy Items' dialog windows from
; 'Move To' and 'Copy To'. [These are useful items that you can easily add
; to the context menu for files and folders in XP and Vista. See, eg,
; http://technobabble.com.au/technobabble/html/tweaks/context-menus.htm].
;
; To install the new 'Send To Dialog Window' item to the context menu for folders
; in Vista or XP use my associated script 'AddSDWtoRegistry.ahk', or do it manually
; like this:
;
; 1. Create a new registry key "HKEY_CLASSES_ROOT\Folder\shell\Send to Dialog window".
; 2. In the Default variable enter the label that you want to see in the context
; menu, eg, "Send to Dialog Window".
; 3. Make a new subkey "HKEY_CLASSES_ROOT\Folder\shell\Send to Dialog Window\Command"
; 4. In its default variable enter
; ""C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\AutoHotkey Scripts\SendToDialogWindow.ahk" "%1"".
; [Don't type the outer quote marks; alter paths to suit your own setup].
Path = %1% ; parameter contains folder path
MsgboxTitle := "Send to Dialogue Window"
IfInString, Path , ::
Path:= "" ; Avoids error message if CLSID sent to Word 'Save As'.
If (Path = "")
{
Msg := "Sorry`, can't handle this type of folder"
msgbox ,, %MsgboxTitle%, %Msg% , 4
ExitApp
}
; Find the top-most dialog window, if any, and get details
Gosub , Sort
If (Item = "")
{
Msg := "Closing since no dialogue windows found"
msgbox ,, %MsgboxTitle%, %Msg% , 4
ExitApp
}
; Get ready for f_Open_Target()
f_window_id := Item1
WinGetClass, f_class, ahk_id %f_window_id%
ControlGetPos, f_Edit1Pos,,,, Edit1, ahk_id %f_window_id%
ControlGetPos, f_Edit2Pos,,,, Edit2, ahk_id %f_window_id%
sleep , 200
; When 'folder' is a drive, %1% returns a value with
; a trailing " tacked on, as in C:". So remove any " characters.
; Also add a backslash to avoid warnings from XP 'Save As' windows
StringReplace , Path , Path , "
Path = %Path%\ ; needed when sending drive names to 'Save As' in Word 2003 .
f_Open_Target(Path) ; Put the data into the window
If (Item > 1) ; issue advisory message window
{
WinGetPos , xloc, yloc , wloc, hloc, ahk_id %Item1%
progw := 200
progh := 100
xloc := (xloc + wloc/2 - progw/2) ;Calculate x coordinate of Progress window
yloc := (yloc + hloc/2 - progh/2) ;Calculate y coordinate of Progress window
Msg := "Multiple dialogue windows are open. `n`nMake sure this is the one you wanted."
Progress, B2 x%xloc% Y%yloc% M zh0 w%progw% h%progh%, , %Msg%
#Persistent
}
SetTimer , KillProgress , 3000
Exit
;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;
Sort:
; Get id of top-most dialog-type window
WinGet, Item, list,,, Program Manager
index := "" ; counts number of windows in selection
Loop, %Item% ; loop thro' all current windows, top down.
{
this_Item := Item%A_Index% ; Item1 contains id of first window, etc
WinGetClass, f_class, ahk_id %this_item%
If f_class not contains #32770,f_class,bosa_sdm_
{
Item%A_Index% := ""
continue ; since not a suitable window
}
index++ ; increment pointer
Item%index% = %this_Item%
}
Item:= index ; number of dialog-type windows collected
return
;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;
KillProgress:
; Terminate the advisory message
Progress , off
SetTimer , killprogress , Off
ExitApp
;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
; Enter path of selected folder into dialog window
f_Open_Target( target )
{
global f_class, f_Edit1Pos, f_Edit2Pos, f_window_id
WinGetTitle, Title , ahk_id %f_window_id%
; It's a dialog
If (f_class = "#32770")
{
If (f_Edit1Pos <> "" And f_Edit2Pos <> "" And Title <> "Export Registry File")
; Has Edit1 and Edit2 so put folder into Edit2, except if title is 'Export Registry File'
; eg could be 'Save As' in Vista or Browse in DOpus.
{
ControlClick ,ToolbarWindow324, ahk_id %f_window_id% ; needed for SaveAs in Vista
ControlSetText, Edit2, %target%, ahk_id %f_window_id%
ControlSend, Edit2, {Enter}, ahk_id %f_window_id%
Return
}
Else If (f_Edit1Pos <> "" And f_Edit2Pos <> "" And Title = "Export Registry File")
; like Reg Export in XP and Vista
{
ControlGetText, text, Edit1, ahk_id %f_window_id% ; store filename
ControlSetText, Edit1, %target%, ahk_id %f_window_id%
ControlSend, Edit1, {Enter}, ahk_id %f_window_id%
Sleep, 100 ; needs extra time on some dialogs or in some cases.
ControlSetText, Edit1, %text%, ahk_id %f_window_id% ; reinstate stored filename
Return
}
Else If (f_Edit1Pos <> "" And f_Edit2Pos = "") ; has Edit1 but not Edit2
{
ControlGetText, text, Edit1, ahk_id %f_window_id% ; store filename
ControlSetText, Edit1, %target%, ahk_id %f_window_id% ; target folder into File Name
If (A_OSVersion = "WIN_VISTA")
Return
Else ; special treatment for XP
; Unlike 'SaveAs', Copy Items', 'Move Items', 'Browse' windows contain SysTreeView321
{
winget , ctrls , ControlList , ahk_id %f_window_id%
Loop, Parse, ctrls, `n
IfEqual , A_LoopField , SysTreeView321
{
WinGetText, FName, ahk_id %f_window_id% ; Name of file to be moved or copied
StringSplit, FName, FName, ' ; is between single quotes
WinGetTitle, Title , ahk_id %f_window_id%
StringSplit , Title , Title , %A_Space%
Message=You selected %Target%
IfEqual , Title2 , Items
Message=Will %Title1% '%FName2%' to %Target%
MsgBox, 1, , %Message%
IfMsgBox Cancel
return
}
ControlSend, Edit1, {Enter}, ahk_id %f_window_id% ; implement change of target folder
Sleep, 100 ; It needs extra time on some dialogs or in some cases.
ControlSetText, Edit1, %text%, ahk_id %f_window_id% ; reinstate stored filename
Return
}
}
}
; Microsoft Office application
Else IfInString, f_class, bosa_sdm_
{
; Retrieve any file name that might already be in the File name
; control, so that it can be restored after the switch to the new
; folder.
ControlGetText, text, RichEdit20W2, ahk_id %f_window_id%
ControlClick, RichEdit20W2, ahk_id %f_window_id%
ControlSetText, RichEdit20W2, %target%, ahk_id %f_window_id%
ControlSend, RichEdit20W2, {Enter}, ahk_id %f_window_id%
Sleep, 100 ; It needs extra time on some dialogs or in some case
ControlSetText, RichEdit20W2, %text%, ahk_id %f_window_id%
Return
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
All you do is right-click on the folder icon and then click on a new context menu item called ‘Send to Dialog Window’. This runs the script which then copies the folder’s path into the dialogue window.
The folder icon can be anywhere, say on the desktop or in Explorer, but it’s especially quick and easy if you navigate to folders via cascaded menus. An example of these is the My Documents cascade in the XP Classic Start Menu (after you’ve enabled 'Expand My Documents'). Better still are the popup toolbars from 'True Launch Bar'. With this you just mouse over a folder icon in a toolbar and a cascade of menus unfolds instantly. If you populate the toolbar with a selection of key folders you can get to any sub-folder very quickly indeed. (See screenshots for an illustration).
I’ve made the script work with all the dialog windows I've found so far in Windows XP and Vista, Office 2003, and Directory Opus. Some of the menus in Vista, such as ‘Save’, 'Move To', 'Copy To’, work differently to those in XP. The script handles both versions. It also works with the dialog windows 'Move Items' and 'Copy Items' from 'Move To' and 'Copy To'. These are optional context menu entries that are available once you make the small registry edits described here
http://technobabble.com.au/technobabble ... -menus.htm. I find them very useful and have had no problems using them.
If you have more than one dialog window open when you click ‘Send to Dialog Window’, a message asks you to close all except one.
Adding ‘Send to Dialog Window’ to the context menu requires adding a new subkey to the registry. If you’re comfortable about editing the registry you can do it manually using Regedit. Otherwise you can run the accompanying script ‘AddSDWtoRegistry.ahk’ and do it automatically. The script will also undo the change if required. I’ve tested it in W2k, XP and Vista, but that’s all.
Note: AddSDWtoRegistry assumes that you've stored SendToDialogWindow.ahk in the folder C:\AutoHotkey Scripts\. If not you'll need to edit the variable PathToScript as shown at the beginning of the script.
Code:
;;;;;;;;;;;;;;
; Title: AddSDWtoRegistry.ahk
; AutoHotkey Version: 1.0.47
; Language: English
; Platform: Win9x/NT
; Author: DAT 07-02-2009
;
; Apply registry changes to add new context menu item 'Send To Dialog Window'
#NoEnv
SendMode Input
;;;;;;;;;;;;;;;;;;;;;;;;;
; User input may be required here:
; The next line should show the location of the main script, 'SendToDialogWindow.ahk'.
; If yours is located somewhere other than 'C:\AutoHotkey Scripts\' you'll need to
; edit the line.
;
PathToScript = C:\AutoHotkey Scripts\SendToDialogWindow.ahk
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
WaitFor = 30 ; seconds
ResultMsg = Will wait %WaitFor%s for user input
Delay := (WaitFor*1000)
SetTimer , ButtonCancel , %Delay%
Gosub , GuiSetup
GuiEscape: ; User pressed escape.
GuiClose: ; User closed the window.
ButtonCancel: ; User clicked Cancel button.
gui , Destroy
ExitApp
ButtonGo:
SetTimer , ButtonCancel , off
Gui , Submit ; stores gui selection
gui , Destroy
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; !!!! Caution: The next section alters the registry, which is !!!!
; !!!! potentially harmful. Don't alter anything in RegWrite !!!!
; !!!! or RegDelete unless you know what you're doing. !!!!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
If (var1 = 1)
{
RegWrite , REG_SZ, HKEY_CLASSES_ROOT, Folder\shell\Send to Dialog Window ,, Send to Dialog Window
RegWrite , REG_SZ, HKEY_CLASSES_ROOT, Folder\shell\Send to Dialog Window\Command ,, "C:\Program Files\AutoHotkey\AutoHotkey.exe" "%PathToScript%" "`%1"
ResultMsg = Registry key added - waiting %WaitFor%s for more input
SoundBeep, 800, 25
SoundBeep, 1200, 25
SetTimer , ButtonCancel , %Delay%
Gosub , GuiSetup
}
If (var2 = 1)
{
RegDelete , HKEY_CLASSES_ROOT, Folder\shell\Send to Dialog Window
ResultMsg = Registry key removed - waiting %WaitFor%s for more input
SoundBeep, 1200, 25
SoundBeep, 800, 25
SetTimer , ButtonCancel , %Delay%
Gosub , GuiSetup
}
SetTimer , ButtonCancel , %Delay%
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set up the GUI
;
GuiSetup:
Gui, Font, S10 CDefault , Verdana
Gui, Add, Radio, x56 y132w320 h20 checked0 vvar1, Add registry key
Gui, Add, Radio, x56 y172 w320 h20 vvar2 , Remove registry key
Gui, Add, Button, x96 y222 w100 h30 Default, Cancel
Gui, Add, Button, x216 y222 w100 h30 , Go
Gui, Add, Text, x16 y22 w360 +Left, Will add or remove a new registry key to put 'Send to Dialog Window' in the context menu of folders.`n`nSelect which you want to do and then click 'Go'. To escape with no action click 'Cancel'.
Gui, Add, Text, x16 y272 w360 +Center, %ResultMsg%
Gui, Show, x318 y368 h316 w400,
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
To install the key manually,
1. Make a new registry key "HKEY_CLASSES_ROOT\Folder\shell\Send to Dialog window".
2. In the Default variable enter the label that you want to see in the context menu, eg, "Send to Dialog window".
3. Make a new subkey "HKEY_CLASSES_ROOT\Folder\shell\Send to Dialog Window\Command".
4. In its default variable enter ""C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\AutoHotkey Scripts\SendToDialogWindow.ahk" "%1"". [Don't type the outer quote marks and alter the paths to suit your own setup].
Disclaimer: Modifying the registry is potentially dangerous so don’t do it unless you know what you’re doing. I usually make a System Restore point first just in case.
Acknowledgement: I got the idea for this script after enjoying using ‘Easy Access to Favorite Shortcuts’ by Savage and ChrisM. This is great but restricts itself to a menu of shortcuts to favourite folders. I was wondering if I could make the shortcuts bring up a cascade of menus to ‘drill’ down further, but then realised I already had perfectly good cascades in my True Launch Bar menus. So adding the new context menu item to these seemed a better idea. It’s also handy if you already have the folder you want visible in Explorer.