Pasting the path of a file as hyperlink

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Pasting the path of a file as hyperlink

15 Oct 2017, 04:52

Hi all,

I need to develop a script which pastes the path of a file as an hyperlink rather than simple text which could works at least in word and onenote. Is there any way to do it?
TygerByte
Posts: 96
Joined: 12 Aug 2016, 05:22

Re: Pasting the path of a file as hyperlink

15 Oct 2017, 05:08

Here is some documentation you can read on file hyperlinkshttps://msdn.microsoft.com/en-us/librar ... S.85).aspx

For example you could paste the following into your web address and get a link to your c drive

Code: Select all

file:///C:/
At this point you can use https://autohotkey.com/docs/commands/StringReplace.htm for all the replacement you would need to do it.
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Re: Pasting the path of a file as hyperlink

15 Oct 2017, 10:43

I made it. What I would like to improve is the control of the displayed text. Is it possible?
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: Pasting the path of a file as hyperlink

15 Oct 2017, 17:17

You can use WinClip. It has a SetHTML function which allows you to easily put an HTML-formatted link onto the clipboard.
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Re: Pasting the path of a file as hyperlink

26 Dec 2017, 14:18

TygerByte wrote:Here is some documentation you can read on file hyperlinkshttps://msdn.microsoft.com/en-us/librar ... S.85).aspx

For example you could paste the following into your web address and get a link to your c drive

Code: Select all

file:///C:/
At this point you can use https://autohotkey.com/docs/commands/StringReplace.htm for all the replacement you would need to do it.
I made this script:

Code: Select all

^+c:: ; { <--  ~ Copy the path of a file and paste it as hyperlink ~
SendInput, ^c
Sleep 100

Clipboard := Clipboard
Prova := Clipboard
StrBeg := "file:///"
Clipboard :=  StrBeg . Clipboard

Return


The file protocol has some problems for this link, where all the following text is pasted, but link ends at the string effect.

file:///d:\Documenti\Universita\Materiale_per_articoli\Mitas\M - Papers\Effect of inflating pressione on tractive performance of bias-ply tires.PDF

Therefore, the link is not effective. Is there any character which should be added to specify which is the text to include in the link? In the file protocol link you provided, there is no information about it.

Thanks

Best regards
Guest

Re: Pasting the path of a file as hyperlink

26 Dec 2017, 14:54

you may need to do additional steps to make it it a working link, replacing the spaces with %20 for example:

Code: Select all

; ...
StringReplace, Clipboard, Clipboard,\,/,All ; replace \ with /
StringReplace, Clipboard, Clipboard,%A_Space%,`%20,All ; replace \ with /
Clipboard:=StrBeg . Clipboard
; ...
See https://en.wikipedia.org/wiki/Percent-encoding for more information and codes if need be
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Re: Pasting the path of a file as hyperlink

26 Dec 2017, 16:19

Guest wrote:you may need to do additional steps to make it it a working link, replacing the spaces with %20 for example:

Code: Select all

; ...
StringReplace, Clipboard, Clipboard,\,/,All ; replace \ with /
StringReplace, Clipboard, Clipboard,%A_Space%,`%20,All ; replace \ with /
Clipboard:=StrBeg . Clipboard
; ...
See https://en.wikipedia.org/wiki/Percent-encoding for more information and codes if need be
that is perfect! thanks!
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Pasting the path of a file as hyperlink

26 Dec 2017, 16:20

egocarib wrote:You can use WinClip. It has a SetHTML function which allows you to easily put an HTML-formatted link onto the clipboard.
I also usual turn to WinClip for any fancy clipboard manipulation.

Here are some examples:

Code: Select all

; https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/

#Include <WinClipAPI>
#Include <WinClip>

#f12::
	WinClip.Clear()
	WinClip.SetText("www.ahkscript.org")
	WinClip.SetHTML("<a href=""http://www.ahkscript.org"">Linky to AHK</a>")
	WinClip.Paste()
return

#f11::
	WinClip.Clear()
	WinClip.SetBitmap(A_Desktop "\Temp\1024x1024.jpg")
	WinClip.Paste()
return

#f10::
	Picture := A_Desktop "\Temp\1024x1024.jpg"
	html=
	(
	<font size="2" face="Calibri" color="black">
	<p>Best Regards,<br>Have a nice day!<br>More Greetings and e-mails and that sort of stuff<br><br>
	<b><font size="2">
	Your Name</b><br>
	<a href="mailto:[email protected]">[email protected]</a><br>
	<img src=%Picture% alt="My picture";">
	)
	WinClip.SetHTML(html)
	WinClip.Paste()
return

::OS::
	WinClip.Clear()
	WinClip.SetText("Best Regards,`nHave a nice day!`nMore Greetings and e-mails and that sort of stuff`n`n")
	WinClip.Paste()
	WinClip.Clear()
	WinClip.SetBitmap(A_Desktop "\Temp\1024x1024.jpg")
	WinClip.Paste()
return

Esc::ExitApp
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen and 312 guests