2015-09-11 25 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命令可能是一個問題? –

相關問題