我需要Firefox在保存文件的保存对话框中始终打开桌面,因此我可以在桌面上输入文件夹的名称并将文件保存到我想要的位置。这将是一种简单而有效的分组下载文件的方法。问题是Firefox在“另存为”对话窗口中打开了最后一个保存文件夹,我无法以合理的步骤执行此操作。要在“另存为”对话框中自动打开桌面,我能想到的最好的是这个autohotkey脚本,我遇到了问题:
!+^s::
MouseMove, %A_CaretX%, %A_CaretY%
CoordMode, Mouse, Screen
MouseGetPos, xpos, ypos
SetMouseDelay, 2
MouseMove,445,46
Click Left
Send,Desktop
Send,{Enter}
MouseMove, %xpos%, %ypos%
Click Left
CoordMode, Mouse, Screen
MouseGetPos, xpos, ypos
SetMouseDelay, 2
MouseMove,445,46
Click Left
MouseMove,%xpos%, %ypos%
Click Left
Input, L, V L1
Loop {
Input, L, V L1 T1.4
If (ErrorLevel = "Timeout")
Break
}
Send,^{Down}
Send,{Enter}
MouseClick,Left,720,473
MouseClick,Left,720,473
return
此脚本的问题是输入命令 - 它不会等我输入文件夹的名称,而是立即执行以下命令。
编辑:脚本现在完全正常工作(感谢Forivin)。需要输入comamand“Input,L,V L1”的附加行,以便脚本暂停并等待输入文件夹的名称。我使用了MouseClick命令和可用于我的监视器的坐标来确认对话框。由于某种原因,使用回车(4次)确认对话框在我的计算机上无法正常工作。 EDIT2:添加了两行,以便使用下拉列表文件夹名称建议,因此不需要输入整个文件夹名称。
答案 0 :(得分:0)
使用Control * -commands是一种更可靠的方法:
!+^s::
WinGet, hWnd, ID, A ;Get handle of active window
;Navigate the the users desktop folder
ControlFocus, ToolbarWindow324, ahk_id %hWnd%
ControlClick, ToolbarWindow324, ahk_id %hWnd%,,,2, NA
ControlSetText, Edit2, `%HOMEPATH`%\Desktop\, ahk_id %hWnd%
ControlSend, Edit2, {Enter}, ahk_id %hWnd%
;Set focus to the folder list
Sleep, 100
ControlFocus, DirectUIHWND2, ahk_id %hWnd%
Input, L, V L1 T2 ;wait until you start typing a folder name (if you just wait 2 seconds, the download will be canceled)
If (ErrorLevel = "Timeout") { ;if you waited too long:
ControlClick, Button2, ahk_id %hWnd%,,,, NA ;click the Cancel button
Return ;end of the hotkey
}
Loop { ;wait until you haven't typed a new letter for 0.4 seconds
Input, L, V L1 T0.4
If (ErrorLevel = "Timeout")
Break
}
ControlGetText, button1Text, Button1, ahk_id %hWnd%
If (button1Text = "&Open") { ;If your windows isn't English, you need to replace the word "Open", if you're confused remove the if statement (but leave the content)
ControlClick, Button1, ahk_id %hWnd%,,,, NA ;click the Open button
Sleep, 100
}
ControlClick, Button1, ahk_id %hWnd%,,,, NA ;click the Save button
Return