How to send website URL to clipboard besides showing a Msgbox

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
pgeugene
Posts: 38
Joined: 27 Jun 2019, 04:36

How to send website URL to clipboard besides showing a Msgbox

08 May 2024, 06:00

Below is the script which capture website url and shows its result using Msgbox after pressing hotkey (!c)
However what I want is to send the result to clipboard.
Below is my attempt to send the result to clipboard but failed.
Thank you for your help.

Code: Select all

!c::
{Msgbox GetUrl()
url := GetUrl()
A_Clipboard := ""
A_Clipboard := "url"
}


Full script

Code: Select all

#Requires AutoHotkey v2.0
; test purpose only

!c::Msgbox GetUrl()

; Version: 2023.10.05.1
; https://gist.github.com/7cce378c9dfdaf733cb3ca6df345b140

GetUrl() { ; Active Window Only
    static S_OK := 0, TreeScope_Descendants := 4, UIA_ControlTypePropertyId := 30003, UIA_DocumentControlTypeId := 50030, UIA_EditControlTypeId := 50004, UIA_ValueValuePropertyId := 30045
    hWnd := WinGetID("A")
    IUIAutomation := ComObject("{FF48DBA4-60EF-4201-AA87-54103EEF594E}", "{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}")
    eRoot := ComValue(13, 0)
    HRESULT := ComCall(6, IUIAutomation, "Ptr", hWnd, "Ptr*", eRoot)
    if (HRESULT != S_OK) {
        throw Error("IUIAutomation::ElementFromHandle()", -1, HRESULT)
    }
    winClass := WinGetClass("A")
    ctrlTypeId := (winClass ~= "Chrome" ? UIA_DocumentControlTypeId : UIA_EditControlTypeId)
    value := Buffer(8 + 2 * A_PtrSize, 0)
    NumPut("UShort", 3, value, 0)
    NumPut("Ptr", ctrlTypeId, value, 8)
    condition := ComValue(13, 0)
    if (A_PtrSize = 8) {
        HRESULT := ComCall(23, IUIAutomation, "UInt", UIA_ControlTypePropertyId, "Ptr", value, "Ptr*", condition)
    } else {
        HRESULT := ComCall(23, IUIAutomation, "UInt", UIA_ControlTypePropertyId, "UInt64", NumGet(value, 0, "UInt64"), "UInt64", NumGet(value, 8, "UInt64"), "Ptr*", condition)
    }
    if (HRESULT != S_OK) {
        throw Error("IUIAutomation::CreatePropertyCondition()", -1, HRESULT)
    }
    eFirst := ComValue(13, 0)
    HRESULT := ComCall(5, eRoot, "UInt", TreeScope_Descendants, "Ptr", condition, "Ptr*", eFirst)
    if (HRESULT != S_OK) {
        throw Error("IUIAutomationElement::GetRootElement()", -1, HRESULT)
    }
    propertyValue := Buffer(8 + 2 * A_PtrSize)
    HRESULT := ComCall(10, eFirst, "UInt", UIA_ValueValuePropertyId, "Ptr", propertyValue)
    if (HRESULT != S_OK) {
        throw Error("IUIAutomationElement::GetCurrentPropertyValue()", -1, HRESULT)
    }
    ObjRelease(eFirst.Ptr)
    ObjRelease(eRoot.Ptr)
    try {
        pProperty := NumGet(propertyValue, 8, "Ptr")
        return StrGet(pProperty, "UTF-16")
    }
}
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: How to send website URL to clipboard besides showing a Msgbox

08 May 2024, 06:24

Hello,

To refer to a variable, you would use url instead of "url".

Explained: Storing values in variables
User avatar
xMaxrayx
Posts: 203
Joined: 06 Dec 2022, 02:56
Contact:

Re: How to send website URL to clipboard besides showing a Msgbox

11 May 2024, 08:14

are using chrome? no way you can get the url title with default settings , in my case I use "URL to title addo" then I do regex clean operation to get the url from title.
I use this addon work well in chrome and Vivaldi
https://chromewebstore.google.com/detail/add-url-to-window-title/ndiaggkadcioihmhghipjmgfeamgjeoi

I read you can use forced accessibility mode in chrome.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/
User avatar
xMaxrayx
Posts: 203
Joined: 06 Dec 2022, 02:56
Contact:

Re: How to send website URL to clipboard besides showing a Msgbox

11 May 2024, 08:19

ok I have test the script it works in chrome but idk why it failed with vavilda?
it's reporting this with all website

Code: Select all

chrome url get test.ahk
---------------------------
chrome-extension://mpognobbkildjkofajifpdfhcoklimli/window.html
---------------------------
OK   
---------------------------
anyway why you want declare a variable that only used with clipboard? just use like with full scripts unless you want mainplate the text.
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: niCode, qltel, reddyshyam and 21 guests