用于书签到特定文件夹

时间:2015-09-02 16:32:32

标签: autohotkey

我正在使用Firefox,而我正在寻找一个自动按键脚本,当我将特定文件夹中的页面加入书签并用一个键盘快捷键替换它时,我可以跳过整个系列的点击。

虽然我已经阅读了Autohotkey论坛上的论坛帖子,但在这里我仍然不知道如何制作一个可以减少书签页面的工作脚本来点击键盘快捷键和我要存储的文件夹的首字母那个页面。使用KeyWait命令我已经使它适用于单个文件夹,并且不知道如何使它适用于我可能用作书签文件夹名称的任何字母或数字。假设我有一个名为XXXX的文件夹,此脚本在点击指定的快捷方式和字母x后需要将网页发送到XXXX文件夹(需要使用MouseClick命令将窗口与文件夹对话框中的书签聚焦在窗口中):

!+^w::
Send,^d
Sleep,400
MouseClick,Left,864,304
Sleep,400
KeyWait, x ,D    
Sleep, 400
Send,^{Enter}
return

我不知道如何使这个脚本适用于任何字母或数字,而不仅仅是单个字母或数字。此脚本的一个大问题是它会阻止键盘,直到我按下X键。如果我已将该页面添加为书签,则点击“转义”以删除书签窗格将阻止键盘,只有在我重新运行autohotkey脚本时才能取消阻止它。

我也尝试使用Input命令作为Autohotkey论坛页面建议的贡献者,但它也不起作用,因为我不明白Input命令是如何工作的。我确实使用KeyWait将其作为上述脚本用于单个字母,但这是我能做的最好的。此脚本还会阻止键盘,直到命中该字母:

!+^w::
Send,^d
MouseClick,Left,864,304
Sleep,400
Input, Character, L1
If Character = t
Send, t
Sleep,400
Send,^{Enter}
return

希望有人可以帮助我,这样可以方便地简化Firefox中的书签处理。

2 个答案:

答案 0 :(得分:1)

我有个好主意。这将打开添加书签对话框并导航到文件夹选择部分并展开所有文件夹。 您需要做的就是输入文件夹名称(或其中的一部分),它将自动被选中。完成后,只需按Enter键。

!+^w::                      ;Hotkey: Ctrl+Alt+Shift+w
    Send, ^d                ;send Ctrl+d to open the add-bookmark dialog
    Sleep, 500              ;wait for the dialog to open
    Send, {Tab}{Tab}{Enter} ;navigate into the folder selection
    Sleep, 300              ;wait to make sure we are there
    Send,{Home}             ;select the first item in the list
                            ;The following line should expand all the folders so that you can just type the folders name to search for it
    Loop, 100 {             ;Increase the number if it doesn't expand all folders
        SendInput, {Right}{Down} ;expand folders
    }
    Send, {Home}            ;navigate to the first item in the list again
    Input, L, V L1 T2       ;wait until you start typing a folder name (if you just wait 2 seconds, the bookmark won't be created)
    If (ErrorLevel =  "Timeout") {
        Send, {Tab 5}       ;press tab 5 times to navigate to the cancel button
        Send, {Enter}       ;cancel the bookmark
        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
    }
    Send, {Tab 4}           ;press tab 4 times to navigate to the enter button
    Send, {Enter}           ;save the bookmark
Return

答案 1 :(得分:0)

我的变种。 按f1在文件夹test1中创建书签。 按f2在文件夹test2中创建书签。

SetBatchLines, -1
Folders := {F1: "test1", F2: "test2"}
#IfWinActive, ahk_class MozillaWindowClass
F1::
F2::
Folder := Folders[A_ThisHotkey]
Send, ^d
AccFirefox := Acc_ObjectFromWindow(WinExist("ahk_class MozillaWindowClass"))
AccElem := SearchElement(AccFirefox, ROLE_SYSTEM_LISTITEM := 0x22, Folder, "")
AccElem.accDoDefaultAction(0)
sleep 100
Send {Enter}
msgbox done
return
#IfWinActive

SearchElement(ParentElement, params*)
{
   found := 1
   for k, v in params  {
      (k = 1 && ParentElement.accRole(0) != v && found := "")
      (k = 2 && ParentElement.accName(0) != v && found := "")
      (k = 3 && ParentElement.accValue(0) != v && found := "")
   }
   if found
      Return ParentElement

   for k, v in Acc_Children(ParentElement)
      if obj := SearchElement(v, params*)
         Return obj
}

Acc_Init()
{
    Static  h
    If Not  h
        h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}

Acc_ObjectFromWindow(hWnd, idObject = 0)
{
    Acc_Init()
    If  DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
    Return  ComObjEnwrap(9,pacc,1)
}

Acc_Query(Acc) { ; thanks Lexikos - www.autohotkey.com/forum/viewtopic.php?t=81731&p=509530#509530
    try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}

Acc_Error(p="") {
    static setting:=0
    return p=""?setting:setting:=p
}

Acc_Children(Acc) {
    if ComObjType(Acc,"Name") != "IAccessible"
        ErrorLevel := "Invalid IAccessible Object"
    else {
        Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]
        if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
            Loop %cChildren%
                i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
            return Children.MaxIndex()?Children:
        } else
            ErrorLevel := "AccessibleChildren DllCall Failed"
    }
    if Acc_Error()
        throw Exception(ErrorLevel,-1)
}