Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Autohotkey v2 script | copy, open an application, paste

I would like to select text, press a hotkey to trigger an application open, paste the selected text into the newly opened application. In my case, my application is called everything, a file locator on windows. It was stored under D drive, and updated to the latest version.

Here is my code:

#f::
{
    A_Clipboard := ""
    ; Copy selected text to clipboard
    Send "^c"
    ClipWait ; Wait for 2 seconds for clipboard to contain text
    SetTitleMatchMode 2
    
    if WinExist("*everything*")
        {
        WinActivate 
        MsgBox "Everything was found."
        }
        ; Use the window found by WinExist.
    else {
        Run "D:\Downloads\everything\Everything.exe"
        Sleep 1000  
        SendInput A_Clipboard
        Send "^v"
        MsgBox "Everything was not found."
        }    
}

This script copies the selected text, opens the application.
The problem is that it does not paste the selected text into Everything.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If I press ctrl+V manually, the selected text will paste into the search window in Everything. WinExist can not find Everything, I tested with a message box. The winTitle of Everything is "everything.exe".

Please help. Thank you.

>Solution :

Try it this way:

#Requires AutoHotkey v2.0

#f::
{
    A_Clipboard := ""
    ; Copy selected text to clipboard
    Send "^c"
    if !ClipWait(2)
    {
        MsgBox "The attempt to copy text onto the clipboard failed."
        return
    }
    Run "D:\Downloads\everything\Everything.exe" " -s " A_Clipboard
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading