 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
elbaso Guest
|
Posted: Sun Mar 09, 2008 11:54 pm Post subject: How to make file-chooser dialog navigate to specific folder? |
|
|
I'm writing an AHK script to automatically configure a complex program for not-so-sophisticated users. The idea is that instead of having the user navigate the menu structure and make several non-intuitive selections, he would just run the script and it would navigate the GUI and set all of the setting correctly.
I'm having trouble with a file-chooser dialog... The user is supposed to navigate to a folder in the dialog and select all the files of a specific extension (i.e. *.xslt), then click ok.
I'm at a loss as to how to do this via scripting. I can launch the file-chooser dialog, but I don't know how to navigate to the appropriate folder and pick the files with the correct extension.
I know the path ahead of time, so that can be in the script.
How Do I make the file-chooser dialog navigate to the folder I want?
Is there a way to select all files of a certain extension once I'm there?
Thanks for any help! |
|
| Back to top |
|
 |
Kellianjaxon
Joined: 04 Jan 2008 Posts: 39
|
Posted: Mon Mar 10, 2008 2:03 am Post subject: |
|
|
Here's a horrible way to start with in case you won't come up with anything better. This may need tweaking.
| Code: | /*
Set focus to a File name control.
Type a complete pathname including drive letter and press enter.
Type *.xslt and press enter.
Set focus to a List view (the control where all files and folders are listed).
Send Appskey and select "View" -> "List" in the context menu.
Send Appskey and select "Arrange Icons By" -> "Name" in the context menu.
Send Appskey and select "Arrange Icons By" -> "Type" in the context menu.
{
Send F2 to activate editing for the current selection in List view and send Ctrl-c to copy its name to clipboard. Send Esc to deactivate editing.
Retrieve File name edit control contents.
Compare clipboard contents with File name control contents.
If you get a match, you've reached the first file of chosen extension. If you don't get a match, the current List view selection is a folder or a special item and you need to send Down key and repeat this paragraph.
}
{
Once you get a match, send F2, then Ctrl-c.
Send Shift-Down key and compare File name control contents with clipboard contents. If you get a match, you've already selected the last file of preferred file type and you can click Open button. If you don't get a match, you need to repeat this paragraph.
}
*/ |
|
|
| Back to top |
|
 |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Mon Mar 10, 2008 2:05 am Post subject: |
|
|
| The "more professional" way to do this would be to use FileSelectFile. |
|
| Back to top |
|
 |
Kellianjaxon
Joined: 04 Jan 2008 Posts: 39
|
Posted: Mon Mar 10, 2008 2:30 am Post subject: |
|
|
Right...of course I never checked the command out before posting. Actually, if I understand correctly, using the command parameters helps only reducing the first three lines from my to-do listing. You'd still need to program the actual automation to select the files and press the Open button.
But hey, about this "complex program": is it a 3rd party application? If yes, then using FileSelectFile is useless because it's the application itself that needs to know the file names, not the AHK script. |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 10, 2008 3:19 am Post subject: Re: How to make file-chooser dialog navigate to specific fol |
|
|
This seems to work...
| Code: | ;//dir=C:\Some\Real\Path
dir=%A_Temp%
;//filemask=*.ahk
;//filemask=*.ahi
filemask=*.xslt
return
F7::Gosub, FileSelectFile_ForTesting
F8::Gosub, AutomateFileOpenDialogWithMultiselect
F9::Gosub, FullTest_DoBoth
FileSelectFile_ForTesting:
FileSelectFile, files, m, %A_MyDocuments%
msgbox, 64, , files(%files%)
return
AutomateFileOpenDialogWithMultiselect:
SetTimer, AutomateFileOpenDialogWithMultiselect, Off
SendInput, {Raw}%dir%\%filemask%
;//SendInput, {Enter}
SendInput, {Enter}+{Tab}^a{Enter}
return
FullTest_DoBoth:
SetTimer, AutomateFileOpenDialogWithMultiselect, 19
Gosub, FileSelectFile_ForTesting
return |
|
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 10, 2008 4:19 am Post subject: Re: How to make file-chooser dialog navigate to specific fol |
|
|
New version already...
| Code: | ;//dir=C:\Some\Real\Path
dir=%A_Temp%
;//filemask=*.ahk
;//filemask=*.ahi
filemask=*.xslt
;//method=SelectAll
method=SendFilenames
return
F7::Gosub, FileSelectFile_ForTesting
F8::Gosub, AutomateFileOpenDialogWithMultiSelect
F9::Gosub, FullTest_DoBoth
FileSelectFile_ForTesting:
FileSelectFile, FileSelectFile_files, m, %A_MyDocuments%
msgbox, 64, , FileSelectFile_files(%FileSelectFile_files%)
return
AutomateFileOpenDialogWithMultiSelect:
SetTimer, AutomateFileOpenDialogWithMultiSelect, Off
msgbox, 64, , method(%method%)
if (method="SelectAll") {
SendInput, {Raw}%dir%\%filemask%
SendInput, {Enter}+{Tab}^a{Enter}
;//SendInput, {Enter}+{Tab}^a
} else if (method="SendFilenames") {
Loop, %dir%\%filemask%
files.="""" A_LoopFileName """ " ;//double-quote hell!
;//msgbox, 64, , files(%files%)
SendInput, {Raw}%dir%
SendInput, {Enter}
SendInput, {Raw}%files%
SendInput, {Enter}
files=
}
return
FullTest_DoBoth:
SetTimer, AutomateFileOpenDialogWithMultiSelect, 19
Gosub, FileSelectFile_ForTesting
return |
|
|
| Back to top |
|
 |
elbaso Guest
|
Posted: Mon Mar 10, 2008 6:12 am Post subject: |
|
|
The built-in file chooser is useless, since it is a 3rd party application.
I kind of like the idea of looking through each file in the chooser, copying it to the clipboard, and checking it's extension there. It is a bit cumbersome, though, and there's no guarantee that the list file in the list is one with a different extension.
Still, I'll probably try it out. I'll post how it goes.
Thanks for the advice!  |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Mon Mar 10, 2008 6:46 am Post subject: |
|
|
Rather than send, I find it is more reliable to set the path text using ControlSetText, then navigate to it by activating the Open/Send button with ControlClick or ControlSend.
| Code: | Run, Notepad,,, pid
WinWait, ahk_pid %pid% ; Wait for Notepad.
WinMenuSelectItem,,, File, Open ; File -> Open
WinWait, ahk_class #32770 ahk_pid %pid% ; Wait for Open dialog.
ControlSetText, Edit1, %A_ScriptDir% ; Set path.
ControlSend, Button1, {Enter} ; Navigate. |
|
|
| Back to top |
|
 |
Kellianjaxon
Joined: 04 Jan 2008 Posts: 39
|
Posted: Tue Mar 11, 2008 12:55 am Post subject: |
|
|
| lexiKos wrote: | Rather than send, I find it is more reliable to set the path text using ControlSetText, then navigate to it by activating the Open/Send button with ControlClick or ControlSend.
|
That's probably very true.
I already came up with a better and - what's best - completely "silent" solution:
| Code: | FileDir = c:\windows\system32
FileExt = sys
FileNameString := ""
Loop
{
IfNotExist, filetype%A_index%.txt ; Find a file name that doesn't already exist
{
; Send dir output to a file
Runwait, cmd.exe /c dir *.%FileExt% > %A_ScriptDir%\filetype%A_index%.txt, %FileDir%, Hide
; Go through file's contents, line by line
Loop, Read, filetype%A_index%.txt
{
If (A_index <= 5) ; At least first five lines won't contain file name information (Windows XP SP2 command prompt)
Continue
; Make sure the current line is not blank and that it doesn't have a leading space
If StrLen(A_LoopReadLine) and (SubStr(A_LoopReadLine, 1, 1) <> " ") ; If true, there's a file name in the current line
{
; Removing first 36 characters leaves us with only the file name
StringTrimLeft, CurrentFile, A_LoopReadLine, 36
FileNameString .= """" CurrentFile """ " ; Create a string => "Filename1" "Filename2" "Filename3" etc.
}
}
FileDelete, filetype%A_index%.txt ; The file is not needed anymore
Break
}
}
Msgbox % FileNameString
; Open the file select dialog
; Automate going to the %FileDir% folder as instructed by lexiKos
; Use ControlSend to send FileNameString contents to File name field and again ControlSend to click Open button |
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Tue Mar 11, 2008 4:19 am Post subject: |
|
|
Rather than outputing "dir" to a temporary file, why not use a file-reading loop?  |
|
| Back to top |
|
 |
Kellianjaxon
Joined: 04 Jan 2008 Posts: 39
|
Posted: Tue Mar 11, 2008 5:06 am Post subject: |
|
|
| lexiKos wrote: | Rather than outputing "dir" to a temporary file, why not use a file-reading loop?  |
Argh, I'm a complete moron. You probably meant to link to this page instead? |
|
| Back to top |
|
 |
BoBoĻ Guest
|
Posted: Tue Mar 11, 2008 5:27 am Post subject: |
|
|
Will modify the first icon (position ='0') at the dialogs PlaceBar to route to your/a specific path. Here, d:\temp
| Code: | !y:: ; ALT+y (press before you call the "Save As..."-dialog)
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Policies\ComDlg32\PlacesBar, Place0, D:\temp
Return |
|
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Tue Mar 11, 2008 6:40 am Post subject: |
|
|
| Kellianjaxon wrote: | | Argh, I'm a complete moron. You probably meant to link to this page instead? | There you go, you're not a complete moron. (Yes, I did.) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|