Navigate to Program Files (x86) properly

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

Navigate to Program Files (x86) properly

25 Nov 2018, 06:19

Hi guys,

I'm currently using the code below to open valid file directories or URLs directly. The only thing that doesn't work so far is the Program Files (x86) directory.

For example, if I #Q for "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe, it only navigates to C:\Program Files. How do I improve the code to include (x86) directories?

Code: Select all

; Go to anything that is in the currently selected text: URLs, email addresses, Windows paths, or just "Google it" USING WIN+Q
$#Q::
    ;Tip("Clipping...")  ;; include my mouse-tip library for this https://gist.github.com/2400547
    clip := CopyToClipboard()
    if (!clip) {
        return
    }
    addr := ExtractAddress(clip)
    if (!addr)
    {
        ; Google it
        ;Tip("Searching for [" SubStr(clip, 1, 50) "] ...")
        addr := "https://encrypted.google.com/search?q=" . clip
    }
    else {
        ; Go to it using system's default methods for the address
        ;Tip("Going to " Substr(addr, 1, 25) " ...")
    }

    Run %addr%
    return

Code: Select all

ExtractAddress(str)
{
    if (RegExMatch(str, "S)((http|https|ftp|mailto:)://[\S]+)", match))
        return match1
    if (RegExMatch(str, "S)(\w+@[\w.]+\.(com|net|org|gov|cc|edu|info))", match))
        return "mailto:" . match1
    if (RegExMatch(str, "S)(www\.\S+)", match))
        return "http://" . match1
    if (RegExMatch(str, "S)(\w+\.(com|net|org|gov|cc|edu|info))", match))
        return "http://" . match1
    if (RegExMatch(str, "S)([a-zA-Z]:[\\/][\\/\-_.,\d\w\s]+)", match))
        return match1
    if (RegExMatch(str, "S)(\\\\[\w\-]+\\.+)", match))
        return match1
			    return ""
}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Navigate to Program Files (x86) properly

25 Nov 2018, 12:06

S)([a-zA-Z]:[\\/][\\/\-_.,\d\w\s]+) u need to change this regexp
S)([a-zA-Z]:[\\/][^/:*?"<>|]+) could work, but cant say for sure, since idk what text ure running this on
reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

Re: Navigate to Program Files (x86) properly

10 Dec 2018, 22:23

I used this but it told me there's a missing close quote. It's weird because I don't see any. any idea why?

Code: Select all

if (RegExMatch(str, "S)([a-zA-Z]:[\\/][^/:*?"<>|]+)", match))
        return match1
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Navigate to Program Files (x86) properly

10 Dec 2018, 23:01

escape it

Code: Select all

RegExMatch(str, "S)([a-zA-Z]:[\\/][^/:*?""<>|]+)", match)
reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

Re: Navigate to Program Files (x86) properly

19 Dec 2018, 19:04

thank u guys! it worked.

is there also any way to make it work for appdata directories? For example,

Code: Select all

%APPDATA%\Notepad

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: roeleboele and 394 guests