2015-09-11 24 views
1

我需要Firefox在保存文件的另存为对话框中始终打开桌面,因此我可以在桌面上输入文件夹的名称并将文件保存在我想要的位置。这将是一种简单且非常有效的分组下载文件的方式。问题在于Firefox会在另存为对话窗口中打开最后一个保存文件夹,并且我无法通过合理的步骤执行此操作。若要桌面会自动在保存的对话,我能想到的最好的就是这个AutoHotkey的脚本打开了,我与它的问题: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)。输入命令“Input,L,V L1”的附加行是脚本需要暂停并等待输入文件夹的名称。我使用了MouseClick命令和协调工作的监视器来确认对话框。使用Enter确认对话框(4次)出于某种原因无法在我的计算机上正确工作。编辑2:增加两行,为了使用下拉列表文件夹名称建议,所以整个文件夹名称不需要键入英寸

+0

在T之后,你有'1.4'这是1和0.4秒。不是很低? *从AHK文档引用* =>'T:Timeout(例如T3)。在终止Input并将ErrorLevel设置为Timeout字之前等待的秒数。如果输入超时,OutputVar将被设置为用户有时间输入的任何文本。这个值可以是一个浮点数,如2.5。“#: – TechJS

+0

嗨TechJS,我怎么解释它不应该是,它代表了输入文件夹名称中的字符之间的时间。一旦这个时间通过,脚本应该执行下一个命令。字符之间有足够的时间等待,直到我输入下一个 –

+0

即使没有输入命令,该脚本也不起作用。到目前为止,它完成了我使用鼠标所做的一切,但是当我点击保存时说:找不到桌面文件。问题在于,左键单击时,窗口中的焦点将丢失,文件夹的名称将无法识别。 –

回答

0

使用控件* - 命令将是一个更可靠这样做的方法:

!+^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 
+0

Hi Forivin!我试过你的脚本,但它不适用于我,它只是删除框中的文件名。你测试过它,它适合你吗? –

+0

正如我所说的,这个脚本只负责在另存为对话框中安全地导航到桌面。 – Forivin

+0

我了解到Forivin,但我已经尝试过了,它不会在另存为对话框中导航到桌面。我不知道为什么,也许homepath命令可能是一个问题? –

相关问题