ResetArray() , ExtractURLDomain(), GetChromeURL()

Get help with using AutoHotkey and its commands and hotkeys
Uhuhseo

ResetArray() , ExtractURLDomain(), GetChromeURL()

02 Mar 2017, 05:18

Hi guys,

Any idea how these functions can be created?

ResetArray()
GetChromeURL()
ExtractURLDomain()
User avatar
Nextron
Posts: 1337
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

Re: ResetArray() , ExtractURLDomain(), GetChromeURL()

02 Mar 2017, 05:28

Code: Select all

ResetArray(){
}
GetChromeURL(){
}
ExtractURLDomain(){
}
There you go, so you want them to do something as well?
User avatar
jeeswg
Posts: 5942
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ResetArray() , ExtractURLDomain(), GetChromeURL()

02 Mar 2017, 22:38

for GetChromeURL():
Get the URL of the current (active) browser tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=3702

for ExtractURLDomain()

Code: Select all

vUrl := "https://autohotkey.com/"
vPos1 := InStr(vUrl, "://")+3
vPos2 := InStr(vUrl, "/", 0, vPos1)-1
MsgBox % vDomain := SubStr(vUrl, vPos1, vPos2-vPos1+1)

;I believe this to be correct:
MsgBox % vDomain := RegExReplace(vUrl, "^.*?//|/.*$", "")
for ResetArray():
Not sure what you mean, but also not sure I'd know the answer anyhow.

[EDIT:]
You can add / to the end of the url before performing text operations on it, in case it doesn't have one. You may or may not wish to remove the www. also.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
uhuhseo

Re: ResetArray() , ExtractURLDomain(), GetChromeURL()

13 Mar 2017, 01:42

jeeswg wrote:for GetChromeURL():
Get the URL of the current (active) browser tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=3702
Thank you. I'm surprised such a long code is required to get the url! I ultimately settled with this for chrome

Code: Select all

GetChromeURL()
{
        WinGetClass, ActWinClass, A
        if (ActWinClass = "Chrome_WidgetWin_1")
        {
                tempclip1:=clipboard
                sleep,12 ;8eg3w
                blockinput, on
                
                send, !{d}
                sleep,12 ;8eg3w
                send, ^{c}
                sleep,12 ;8eg3w
                tempclip2:=clipboard
                sleep,12 ;8eg3w
                clipboard:=tempclip1
                sleep,12 ;8eg3w
                
                blockinput, off
                return tempclip2
        }
}
jeeswg wrote: for ExtractURLDomain()

Code: Select all

vUrl := "https://autohotkey.com/"
vPos1 := InStr(vUrl, "://")+3
vPos2 := InStr(vUrl, "/", 0, vPos1)-1
MsgBox % vDomain := SubStr(vUrl, vPos1, vPos2-vPos1+1)

;I believe this to be correct:
MsgBox % vDomain := RegExReplace(vUrl, "^.*?//|/.*$", "")
That works perfect! but what is this code intended to do?
MsgBox % vDomain := RegExReplace(vUrl, "^.*?//|/.*$", "")
jeeswg wrote:
for ResetArray():
Not sure what you mean, but also not sure I'd know the answer anyhow.
Lets say I have an array that is filled in 3x5 dimension, and want to clear it out to have a 0x0 size array, what can I do?
User avatar
jeeswg
Posts: 5942
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ResetArray() , ExtractURLDomain(), GetChromeURL()

13 Mar 2017, 10:43

The RegEx needle, "^.*?//|/.*$", is basically in 2 parts:

The '|' essentially means OR.

^.*?//
Replace anything from the start of the string to the end of the first '//'.
The '.' is any non-linefeed character (or it can be set to mean any character).
The '*' means 0 or more of the previous character(/class/subpattern).
The '?' has a special role here meaning 'ungreedy'.
Normally '?' means 0 or 1 of the previous character(/class/subpattern).
Perhaps this part could just be this, i.e. without the '?':
Replace anything from the start of the string to the end of the last '//'.
^.*//

/.*$
Then, replace anything from the first '/' to the end of the string.
Perhaps this part could just be this, without the '$':
/.*

Anyhow always test RegExMatch/RegExReplace lines and double-check the documentation.

Re. 'ungreedy':
Regular Expressions (RegEx) - Quick Reference
https://autohotkey.com/docs/misc/RegEx-QuickRef.htm

See also:
RegEx handy examples (RegExMatch, RegExReplace) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?t=28031

==================================================

I've recently done a lot of reading on objects, here are some tests regarding deleting keys, and on how to 'reset' or clear an array:

Basically the key line is: oArray := {}. Which can also be used to create an empty array.

Code: Select all

q::
oArray := {}
oArray[1,2,3,4,5] := 1
oArray[1,2,3,4,6] := 2
oArray[1,2,3,4,7] := 3
oArray[2,2,3,4,5] := 1
oArray[2,2,3,4,6] := 2
oArray[2,2,3,4,7] := 3
MsgBox % vCount := NumGet(&oArray + 4*A_PtrSize)
MsgBox % vCount := NumGet(&oArray[1,2,3,4] + 4*A_PtrSize)

oArray[1,2,3,4].Delete(5)
oArray[1,2,3,4].Delete(6)
MsgBox % vCount := NumGet(&oArray[1,2,3,4] + 4*A_PtrSize)

oArray[1,2,3].Delete(4)
MsgBox % vCount := NumGet(&oArray[1,2,3,4] + 4*A_PtrSize)

oArray := {}
MsgBox % vCount := NumGet(&oArray + 4*A_PtrSize)
MsgBox % vCount := NumGet(&oArray[1,2,3,4] + 4*A_PtrSize)
Return
==================================================

I tested this just now, and it worked, but such code can regularly break when programs update. It uses the Acc library.

Code: Select all

JEE_ChromeGetUrl2(hWnd)
{
oAcc := Acc_Get("Object", "window.client.client.client2.tool_bar2.grouping1.editable_text", 0, "ahk_id " hWnd)
vUrl := oAcc.accValue(0)
oAcc := ""
Return vUrl
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: ah_sis90, AviationGuy, electrone77, futuretech85, israelss, MannyKSoSo, scriptor2016, sinkfaze, SOTE and 163 guests