1
votes

I need Firefox to always open Desktop in the Save as dialogue on saving files, so I can type in the name of the folder on the Desktop and save the file where I want. That would be a simple and very efficient way of grouping downloaded files. The problem is that Firefox opens the last save folder in the Save as dialogue window, and I can't do this in a reasonable number of steps. To get Desktop automatically opened in the Save as dialogue the best I could think of is this autohotkey script, and I have a problem with it:

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

The problem with this script is the Input command - it doesn't wait for me to type in the name of the folder but executes the following command immediatelly.

EDITED: The script is now fully working (thanks to Forivin). An additional line with Input comamand "Input, L, V L1" was required for the script to pause and wait for the name of the folder to be typed in. I've used MouseClick command and coordinates that work for my monitor to confirm the dialogue box. Confirming the dialog box with Enter (4 times) doesn't work accurately on my computer for some reason. EDIT2: Added two lines, in order to make use of the drop down list folder name suggestions, so the whole folder name doesn't need to be typed in.

1
after T you have 1.4 which is 1 and 0.4 of a second. isnt it low? Quoted From AHK Documentation => T: Timeout (e.g. T3). The number of seconds to wait before terminating the Input and setting ErrorLevel to the word Timeout. If the Input times out, OutputVar will be set to whatever text the user had time to enter. This value can be a floating point number such as 2.5.AmirHossein
Hi TechJS, how I was explained it shouldn't be, it stands for the time between the input of characters in the name of the folder. Once this time is passed the script should execute the next command. It is plenty of time between the characters to wait until I type in the nextuser5280114
The script doesn't work even without the Input command. Up to that point it does everything that I do using the mouse but when I click save it says : Desktop file not found . The problem is that with left clicks the focus in the window is lost and the name of the folder is not recognized.user5280114
BTW I myself prefer not to use loop so please you do so, cause loop has some unexpected behavior. Use SetTimer Instead.AmirHossein
Please be free to add any tweaks that you think can improve the script TechJS. I'm glad I've figured it out in the end, it works like a charm :) It is possible to add another loop if one wants to cancel waiting for something to be typed in the filename box and simply download the file to desktop. It is also possible to add a simple Enter at the beginning of the script and run it from the Download manager dialogue. The only Firefox add-on that I could find which can do anything similar is Save file to, but I don't think their method saves any clicks, it rather complicates the procedureuser5280114

1 Answers

0
votes

Using the Control*-commands would be a much more reliable way of doing this:

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