Text with embedded hyperlink Topic is solved
Text with embedded hyperlink
I've searched the documentation and the forum, but I can't seem to find a way to create Text with an embedded hyperlink.
For example, I would like my output to be the below:
"Some Text" as a clickable hyperlink. The hyperlink won't display, just "some text". I'm new to v2, so please be kind.
I appreciate your time and knowledge.
For example, I would like my output to be the below:
"Some Text" as a clickable hyperlink. The hyperlink won't display, just "some text". I'm new to v2, so please be kind.
I appreciate your time and knowledge.
Re: Text with embedded hyperlink
Welcome to this AutoHotkey forum!
Code: Select all
; This script copies HTML to the clipboard
#Requires AutoHotkey v2.0
#Include d:\utils\WinClipV2\WinClip.ahk ; https://github.com/TheArkive/WinClip_ahk2
#Include d:\utils\WinClipV2\WinClipAPI.ahk
wc := WinClip()
wc.Clear()
wc.SetHTML('<a href="http://www.autohotkey.com/">Some text</a>')
Re: Text with embedded hyperlink
Thank you for your response and warm welcome.
This might go beyond my needs. I just simply want to type the hotkey name and end up the the "Text" with embedded hyperlink (which will never change) in a email. Is this still the best way?
Maybe I should explain more. If I was to type something like "cal" I'd like to end up with "Click HERE to schedule time on my calendar". I'm trying to automate a work email that has my scheduling link in the signature.
This might go beyond my needs. I just simply want to type the hotkey name and end up the the "Text" with embedded hyperlink (which will never change) in a email. Is this still the best way?
Maybe I should explain more. If I was to type something like "cal" I'd like to end up with "Click HERE to schedule time on my calendar". I'm trying to automate a work email that has my scheduling link in the signature.
Re: Text with embedded hyperlink
Code: Select all
; This script copies HTML to the clipboard
#Requires AutoHotkey v2.0
#Include d:\utils\WinClipV2\WinClip.ahk ; https://github.com/TheArkive/WinClip_ahk2
#Include d:\utils\WinClipV2\WinClipAPI.ahk
url := 'http://www.autohotkey.com/'
::cal:: {
wc := WinClip(), wc.Clear()
wc.SetHTML('<a href="' url '">Click HERE to schedule time on my calendar</a>')
ClipWait(1, True) ? Send('^v') : MsgBox('An error occurred while waiting for the clipboard.', 'Error', 48)
}
-
- Posts: 4344
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Text with embedded hyperlink
Why not the link control?
Re: Text with embedded hyperlink
Sounds perfect, can you expand? Maybe some complete code?
Re: Text with embedded hyperlink
I'm seeing this error when trying to use the WinClip?mikeyww wrote: ↑18 Mar 2023, 13:47There could be better or worse ways. You can be the judge!Code: Select all
; This script copies HTML to the clipboard #Requires AutoHotkey v2.0 #Include d:\utils\WinClipV2\WinClip.ahk ; https://github.com/TheArkive/WinClip_ahk2 #Include d:\utils\WinClipV2\WinClipAPI.ahk url := 'http://www.autohotkey.com/' ::cal:: { wc := WinClip(), wc.Clear() wc.SetHTML('<a href="' url '">Click HERE to schedule time on my calendar</a>') ClipWait(1, True) ? Send('^v') : MsgBox('An error occurred while waiting for the clipboard.', 'Error', 48) }
Re: Text with embedded hyperlink
Did you save the html source of the github page that contains the AHK code as WinClip.ahk rather than the AHK code itself? Can you paste the contents of your WinClip.ahk file here? Put it between [code][/code] tags.
Re: Text with embedded hyperlink Topic is solved
This idea from a recent post requires no external files.
Code: Select all
; This script copies HTML to the clipboard (alternative to WinClip)
#Requires AutoHotkey v2.0
url := 'http://www.autohotkey.com/'
#HotIf WinActive('ahk_exe OUTLOOK.exe')
::cal:: { ; Paste HTML into Outlook message
A_Clipboard := ''
HTMLtoClipboard('<a href="' url '">Click HERE to schedule time on my calendar</a>')
If ClipWait(1, True) {
wEditor := ComObjActive('Outlook.Application').ActiveInspector.WordEditor
wEditor.Application.Selection.Paste
} Else MsgBox 'An error occurred while waiting for the clipboard.', 'Error', 48
}
#HotIf
HTMLtoClipboard(html) {
; Idea from https://www.autohotkey.com/boards/viewtopic.php?p=513124#p513124
htmlFile := ComObject('HTMLfile')
htmlFile.write(html)
bodyRange := htmlFile.body.createTextRange()
bodyRange.select(), bodyRange.execCommand('Copy')
bodyRange := htmlFile := ''
}
Re: Text with embedded hyperlink
@mikeyww, that second piece of code does it! Thank you so much!
Re: Text with embedded hyperlink
Thanks for that example, @mikeyww. I'd like to learn more about why it's necessary to use ClipWait after HTMLtoClipboard. In a single-threaded script, is this necessary? Won't HTMLtoClipboard not finish until the HTMLFile Comobject has completed it's action? Are you just being extra cautious because it's easier to just add the ClipWait code than check whether it's necessary?mikeyww wrote: ↑19 Mar 2023, 06:22Code: Select all
HTMLtoClipboard('<a href="' url '">Click HERE to schedule time on my calendar</a>') If !ClipWait(1, True) MsgBox 'An error occurred while waiting for the clipboard.', 'Error', 48 }
I ask because I've been using WinClip to put HTML into the clipboard and I've been having some issues. I wonder if I should be adding ClipWait. At the same time, I love simple and blazingly fast code, so I don't want to add anything extra. I'll likely try replacing my WinClip code with this code, so I want to know how to optimize my usage of both HTMLtoClipboard and WinClip (in terms of whether I need to add "ClipWait").
Re: Text with embedded hyperlink
I use ClipWait because the Windows clipboard can be slow. I do not know whether execCommand('Copy') has a built-in wait; you can try it and see. I have assumed that it simply executes a copy action without any additional action. In any case, ClipWait waits only until the clipboard is populated or the timeout occurs, so if the clipboard is populated immediately, there is no wait.
The effect of not using ClipWait when it matters is that immediately accessing the clipboard may use the clipboard's previous contents, which would be null in this case, or whatever the previous contents are, if the clipboard is not cleared before setting it again.
The question can be answered quickly. Try it, and see if the problem disappears.I wonder if I should be adding ClipWait.
The effect of not using ClipWait when it matters is that immediately accessing the clipboard may use the clipboard's previous contents, which would be null in this case, or whatever the previous contents are, if the clipboard is not cleared before setting it again.
Re: Text with embedded hyperlink
Thanks! I've had intermittent problems, and they've been hard to debug, because I don't know which part of my toolchain is failing (or if there's a bug elsewhere in my own codebase).
I'll start using Clipwait for all clipboard operations just in case.
I'll start using Clipwait for all clipboard operations just in case.
Re: Text with embedded hyperlink
You can also learn the value of the clipboard by displaying it after you set it!
You can quickly see different results by clipping something in Microsoft Excel.
When I tested with execCommand, I did not see this problem, but I do not have a way to test across different CPUs & conditions.
You can quickly see different results by clipping something in Microsoft Excel.
Code: Select all
#Requires AutoHotkey v2.0
^F3:: {
A_Clipboard := '', Send('^c'), noWait := A_Clipboard
ClipWait(1)
MsgBox '#' noWait '#`n`n#' A_Clipboard '#', 'Result', 64
}
When I tested with execCommand, I did not see this problem, but I do not have a way to test across different CPUs & conditions.