How to Create a .Webloc File With a Given URL

I am trying to build a macro that grabs the url from the chrome browser and creates a webloc file on the desktop. Unfortunately the clipboard screws up the url while copying it seems. This is the true url:

and this is what arrives at the webloc file:

This little part can't be copied to the clipboard:

This is how the macro works:

if chrome browser at front
select url
copy url
create webloc file on desktop and append html before url
append url to file
append html after url to file

save browser link to desktop.kmmacros (4.9 KB)

Edit: OK I'm a bit confused, in this text editor the upper url does show amp; but after formatting (what you see) amp; is omitted. What's more confusing is that both urls seem to work although only the upper should.

1 Like

To get the URLs to show properly on this site, wrap them in "backticks", like this:


Try using the Token %ChromeURL%:



1 Like

I've replaced the clipboard with the %ChromeURL% token which made my macro much simpler. Unfortunately the problem persists. The URL gets copied without amp;.

I've been able to narrow down the problem. The original URL has & included. Copying the URL leads to omitting the amp; but not the &. The URL works with & or without it but it does not work when & is left in the URL.

Any idea why this is happening or how to solve this?

All I want is to grab the browser url and create a link with it on desktop. If you know of a better macro that works, I'll gladly replace mine.

This is the macro:

1 Like

This probably won't help, but let me clarify something. & is the HTML-encoding of the & character, so it's not really stripping the "amp;" from it - it's converting & to what it represents, which is an ampersand &.

BUT, why it's doing it for a URL, end better still, what is doing it for the URL, I have no idea.

Maybe someone else will have some ideas.

Not seeing that here. As @DanThomas explains, & is just the HTML entity encoding

Entity - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

of an "&" ampersand character.

Inspection of the file written out as below shows no decoding of that entity – the full & is preserved in the written text file.

Reported entity encoding issue.kmmacros (2.0 KB)

Screenshot 2022-01-03 at 10.11.06

Perhaps you have been opening the .webloc file in an editor which performs that conversion ?

Putting that theory aside

( The Chrome clipboard preserves the encoded form of that entity )

Expand disclosure triangle to view contents of Chrome clipboard
"public.utf8-plain-text as string": ""

What is the actual problem that you are encountering ?

PS, as you are embedding a URL in XML (the webloc plist), you will sometimes need an additional layer of entity encoding, which you can get with a KM filter action:

Creating a usable webloc.kmmacros (2.7 KB)

1 Like

@ComplexPoint Hey, your macro works! All other proposed approaches produced the same output (faulty url) but encoding the variable with HTML outputs a functional .webloc file. Thank you very much :slight_smile:

1 Like

I'm very glad to find this thread because I'm looking at automating the creation of over a hundred webloc files as part of an archive that I'm organizing.

It looks like @ComplexPoint's macro solves @Artur_exe's problem, and hopefully mine as well. May I suggest to Artur, would you please change the title to remove the first word, "Problems"? That way the title is more descriptive of the entire thread and will be more meaningful when it appears in search results.

I'll be going over the script one action at a time to really understand it because I won't have the URLs open in Chrome when I want to make the new weblocs, I will be constructing the URLs based on lists of variable values.

I've already learned how magical the token %ChromeURL% is. For example, just putting a Set Variable action into a macro shows that the current value of %ChromeURL% is the URL of this forum page, this comment, because that's the current "front" in Chrome.

Thanks, Artur, for the question and thanks, Complex, for a working solution.