【问题标题】:Autohotkey script to download to a specific folder on the computer自动热键脚本下载到计算机上的特定文件夹
【发布时间】:2015-12-08 04:24:10
【问题描述】:

我需要 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)。脚本需要额外的一行输入命令“Input, L, V L1”来暂停并等待输入文件夹的名称。我使用了 MouseClick 命令和适用于我的显示器的坐标来确认对话框。由于某种原因,使用 Enter(4 次)确认对话框在我的计算机上无法正常工作。 EDIT2:添加了两行,以便使用下拉列表文件夹名称建议,因此不需要输入整个文件夹名称。

【问题讨论】:

  • 在 T 之后你有 1.4 ,即 1 和 0.4 秒。是不是很低? 引自 AHK 文档 => 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.
  • 嗨 TechJS,我怎么解释它不应该,它代表文件夹名称中字符输入之间的时间。一旦这个时间过去,脚本应该执行下一个命令。字符之间有足够的时间等到我输入下一个
  • 即使没有输入命令,脚本也无法工作。到那时,它完成了我使用鼠标所做的所有事情,但是当我单击保存时,它说:找不到桌面文件。问题是左键单击窗口中的焦点会丢失,并且无法识别文件夹的名称。
  • 顺便说一句,我自己不喜欢使用循环,所以请你这样做,因为循环有一些意想不到的行为。请改用SetTimer
  • 请随意添加您认为可以改进脚本 TechJS 的任何调整。我很高兴我最终弄明白了,它就像一个魅力:) 如果想取消等待在文件名框中输入某些内容并简单地将文件下载到桌面,可以添加另一个循环.也可以在脚本的开头添加一个简单的 Enter 并从下载管理器对话框中运行它。我能找到的唯一可以做类似事情的 Firefox 插件是保存文件到,但我认为他们的方法不会保存任何点击,而是使过程复杂化

标签: firefox autohotkey


【解决方案1】:

使用 Control* 命令将是一种更可靠的方法:

!+^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,但我已经尝试过了,但它没有在另存为对话框中导航到桌面。不知道为什么,可能是homepath命令有问题?
  • 好的,我编辑了我的代码。如果我理解正确的话,代码现在可以完成你想要的一切。
  • 我已经运行了你的 Forivin 脚本,但有些东西不太奏效。这是我需要的,但由于某种原因它不能准确地工作,我仍然无法确定它可能是什么,但我想会弄清楚。该脚本的一个明显问题是它没有关注文件名框,并且您实际上无法输入要将文件保存到的文件夹的名称。这是脚本需要做的重要事情 - 转到桌面并等待我输入文件夹的名称,或者更好地开始输入并自动完成并将文件保存到所需的文件夹。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多