Request for script assistance

Issue #17 closed
Winter Laite created an issue

Definitely a back-burner ticket. I have a non-GUI script working in v2, but cannot properly port it. I marked it as a bug but it may well not be.

This script sets, clears, jumps to or queries a “Save” folder in several Office applications, Thunderbird, and File Explorer, depending on which of four hotkeys is pressed.

The problem for me appears to be in the ‘SaveHere()’ function, but I haven’t been able to debug it. It crashes (occasionally it has worked) at that function. Additionally, a small, empty GUI window appears when I press any of the hotkeys (^#s, ^#j, ^#c, ^#q).

Thanks very much for any help, I realize this is probably me getting ahead of myself.

Comments (7)

  1. Winter Laite reporter

    I believe a commit may have fixed this script. The only change I made was substituting ‘Alt’ for ‘Ctrl’. If this in fact works, please mark resolved and close.

    SetTitleMatchMode 2
    
    saveFolder := ""
    ;MsgBox("Initial save folder is " saveFolder, "INITIAL SAVE FOLDER", "T2")
    
    ;FOR NOW ...
    ;Ctrl-Win-S will set the open/save folder from an open/save dialog or from an open Explorer window.
    ;Ctrl-Win-J will jump to that folder in an open/save dialog or in Explorer
    ;Ctrl-Win-C clears the folder setting.
    ;Ctrl-Win-Q queries the set folder.
    ;Shift+Escape bails.
    ;
    
    !#j::{
    global saveFolder
    ;If an Explorer window or an open/save dialog is open, set the jump/save folder
    If (saveFolder == "" && (WinActive("ahk_class #32770") || WinActive("ahk_class CabinetWClass"))) {
        MsgBox("No SAVE/JUMP folder set - defaulting to Documents", "No Folder Set", "T2")
        saveFolder := ("C:\Users\HP6300\Documents")
        }
    saveHere()
    }
    
    !#s::{
    setSaveFolder()
    }
    
    !#c::{
    global
    saveFolder := ""
    MsgBox("SAVE/JUMP FOLDER CLEARED!", "Clear", "T2")
    }
    
    !#q::{
    global saveFolder
        If (saveFolder == "")
        {
            MsgBox("No Jump/Save Folder Set!", "NO FOLDER SET", "T2")
        }
        else
        {
            MsgBox("Jump/Save folder is:`n" saveFolder, "CURRENT FOLDER", "T2")
        }
    }
    
    setSaveFolder() {
    global saveFolder
        ;Word, Excel or Powerpoint deviations from standard #32770 behavior
        ;Thunderbird is particularly irksome. It is slow, so long delays are necessary.
        ;At least my present machine :)
    If (WinActive("ahk_class #32770") && WinActive("ahk_exe thunderbird.exe"))
    {
        ;More T-bird workarounds, March 28, 2018
        If (WinActive("Attach file\(s\) ahk_class #32770") || WinActive("Save Message As ahk_class #32770")) { ;begin interior "If"
            MsgBox("in attach or save", "CURRENT FOLDER", "T2")
            ControlFocus("DirectUIHWND2", "ahk_class #32770")
        }
        Else {
            ControlFocus("Edit2", "ahk_class #32770")
        }
        Sleep(300)
        Send("!d")
        Sleep(300)
        ControlGetText(saveFolder, "Edit2", "ahk_class #32770")
        Sleep(300)
        MsgBox("Open/Save/Attach folder is:`n" saveFolder " in Thunderbird", "T2")
    }
    Else if WinActive("ahk_class #32770"){
        If (WinActive("ahk_exe WINWORD.EXE") || WinActive("ahk_exe EXCEL.EXE") || WinActive("ahk_exe POWERPNT.EXE"))
        ; Annoyingly enough, there are different Edit class numbers for Open and Save As. This section deals with it.
        {
        ControlFocus("DirectUIHWND2", "ahk_class #32770")
        Send("!d")
            If (WinActive("Open ahk_class #32770")) {   ; Begin interior "If"
            ControlGetText(saveFolder, "Edit2", "ahk_class #32770")
            }
            Else {
        ControlGetText(saveFolder, "Edit3", "ahk_class #32770")
            } ; End interior If
        MsgBox("Open/Save folder is:`n" saveFolder " in Office Open/Save Dialog", "CURRENT FOLDER", "T2")
        } ; End surrounding "If"
        else
        ;Acrobat, Notepad, Scite, Outlook, probably lots of others work with this.
        {
        Send("!d")
        Sleep(100)
        ControlGetText(saveFolder, "Edit2", "ahk_class #32770")
        MsgBox("Open/Save folder is:`n" saveFolder " in Save", "CURRENT FOLDER", "T2")
        ;the delay above (2 seconds) is probably too long.
        }
    }
    else if (WinActive("ahk_class CabinetWClass")) {
        Send("!d")
        Sleep(100)
        saveFolder := ControlGetText("Edit1", "ahk_class CabinetWClass")
        MsgBox(saveFolder, "CURRENT FOLDER", "T2")
        ;MsgBox("Jump/Save folder is:`n" saveFolder " in Explorer", "CURRENT FOLDER", "T2")
        ;the delay above (2 seconds) is probably too long.
    }
    else {
        MsgBox("No Explorer - no open or save dialog activated", "ERROR", "T1")
    }
    }
    
    saveHere() {
    global saveFolder
    
        If (WinActive("ahk_class #32770"))  {
            ;CRASHES HERE
    
            Send("!d")
            Sleep(1000)
            Send(saveFolder)
            Sleep(100)
            Send("{ENTER}")
            ;Send("{ENTER}")
        }
        else if (WinActive("ahk_class CabinetWClass")) {
    
            ;MsgBox("Got this far")
            ;CRASHES HERE
            Send("!d")
            Sleep(1000)
            ControlSetText(saveFolder, "Edit1",  "ahk_class CabinetWClass")
            Sleep(100)
            Send("{ENTER}")
        }
        else {
        MsgBox("No Explorer - no open or save dialog activated", "ERROR", "T1")
        }
    }
    

  2. Matt Feemster repo owner

    What is the status of this? Can you please test again to see if our recent fixes accidentally fixed the problem? If it’s still buggy, let’s fix it, else let’s close it. Let me know.

  3. Winter Laite reporter

    A small, empty GUI appears when a hotkey is pressed. Nonetheless, it works fine.

    If you feel that is worth fixing, perfect. I can certainly live with it as is.

  4. Winter Laite reporter

    There’s a bug, but it’s with MsgBox, related to the Options. At least “T2” in options will cause the small GUI to show. I’m going to post that as a separate issue.

  5. Log in to comment