1

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.

  • 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.` – Amir Hossein Baghernezad Sep 11 '15 at 15:45
  • 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 next –  Sep 11 '15 at 16:19
  • 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. –  Sep 11 '15 at 16:53
  • BTW I myself prefer not to use loop so please you do so, cause loop has some unexpected behavior. Use `SetTimer` Instead. – Amir Hossein Baghernezad Sep 11 '15 at 19:29
  • 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 procedure –  Sep 11 '15 at 19:48

1 Answers1

0

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
Forivin
  • 14,780
  • 27
  • 106
  • 199
  • Hi Forivin! I've tried your script and it doesn't work for me, all it does is delete the file name in the box. You tested it and it worked for you? –  Sep 12 '15 at 10:13
  • As I said, this script only takes care of safely navigating you to the desktop in the save as dialog. – Forivin Sep 12 '15 at 10:27
  • I understood that Forivin but I've tried it and it doesn't navigate to Desktop in the Save as dialogue. I don't know why, maybe the homepath command might be a problem? –  Sep 12 '15 at 10:41
  • Okay, I edited my code. If I understood you correctly, the code does everything you wanted now. – Forivin Sep 12 '15 at 11:01
  • I've run your script Forivin, but something doesn't quite work. It is what I needed but it doesn't work accurately for some reason, I still can't put my finger on what it might be but will figure it out I think. The obvious problem with the script is that it doesn't focus the file name box, and you can't actually type in the name of the folder you want to save the file to. That is essential thing the script needs to do - go to desktop and wait for me to type in the name of the folder, or even better start typing and auto complete and save the file to the desired folder. –  Sep 12 '15 at 11:13
  • It focuses the the folder list! not the file name box. So you can just go and type the folder name and it will work fine. – Forivin Sep 12 '15 at 11:18
  • I changed a line in my code, to ensure it really focuses the current folder list. – Forivin Sep 12 '15 at 11:23
  • I made some more changes because it didn't always work for me, now it seems to work every time. :) – Forivin Sep 12 '15 at 11:39
  • I've followed you Forivin, and as you said it doesn't work every time. When it works it does the job, but even then there's a problem with the focus in the folder list. I think that it focuses the folder list every time but there's a lag before it highlights the folder and then there's a lag when I start typing the name of another folder, so I never know if I mistyped the name or what happened. Also, sometimes the script doesn't navigate to the Desktop folder but instead saves the file in the folder at hand. I'll try to identify if some special situation triggers disfunction of the script. –  Sep 12 '15 at 11:50