How Do I Use Current Browser URL and Title To Create a WebLoc file? and How Do I Rename Forklift Files?

Hi Chris, it's been a while...

Is there any easy way of updating the macro so that is creates an HTML shortcut on the desktop instead of a webloc file?

I'm asking as with Ventura 13.1 Apple are at the moment forcing any links saved on the desktop to be opened in Safari and this can't be changed. The only work around is to 'right click and select open with' which is rather a pain to work with.

If the shortcuts were HTML links then it truly makes them browser agnostic.

Any thoughts would be appreciated.

Hey Daron,

Do you have a working example of one of these HTML link files?

I'm not familiar with them.

I’m still running macOS 10.14.6 Mojave, so if it's anything to do with the new Shortcuts App I can't help.

Strange that Apple would enforce .webloc files opening in Safari. Microsoft got in quite hot water over similar highhandedness a number of years ago.

It might be better to work with standard .webloc files, since that's what is formed by drag and drop.

See if this works to open the selected .webloc file in Google Chrome:

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/12/16 05:23
# dMod: 2022/12/16 05:23 
# Appl: Finder
# Task: Open Selected WebLoc File in the Given Web Browser.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Open, @Selected, @WebLoc, @Web, @Browser
--------------------------------------------------------
# Safari's ID ⇢ com.apple.Safari
--------------------------------------------------------
property browserAppIDStr : "com.google.Chrome"

try
   
   tell application "Finder"
      set finderSelectionList to selection as alias list
      if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
      set weblocFileAlias to item 1 of finderSelectionList
      
      if class of (file weblocFileAlias) = internet location file then
         
         set appRef to application file id browserAppIDStr
         open weblocFileAlias using appRef
         
      else
         
         error "The Selected File Was NOT a WebLoc File!"
         
      end if
      
   end tell
   
on error errMsg number errNum
   set errMsg to errMsg & linefeed & linefeed & "Num: " & errNum
   if errNum ≠ -128 then
      try
         tell application (path to frontmost application as text) ¬
            to set ddButton to button returned of ¬
            (display dialog errMsg with title ¬
               "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
               default button "OK" giving up after 30)
         if ddButton = "Copy Error Message" then set the clipboard to errMsg
      end try
   end if
end try

--------------------------------------------------------

-Chris

Hi Chris,

Attached should be a zip file containing a HTML file.

On the script file you've provided how would I change it to see if it worked with Brave? (I don't / won't ) have Chrome on my machines :slight_smile: I assume it's an AppleScript file?

There are a lot of folks complaining about this issue here.


How Do I Use Current Browser URL and Title To Create a WebLoc file and How Do I Rename Forklift Files Questions Suggestions Keyboard Maestro Discourse.html.zip (1.3 KB)

Brave's ID:

com.brave.Browser

Interesting. I don't recall seeing a file exactly like this before...

Just open the file in BBEdit and look it over. You can easily adapt my original macro to manufacture these sorts of files.

Hi Chris I've just tried the script and changed the ID to brave and if I run it I just get an error message saying "The Selected File Was NOT a WebLoc File! Num: -2700" I wasn't given any option to select a file? Also tried it with compiling it as an application, still nothing.

Okay I'll have a look at the macro, I guess I need to work out how wrap the URL in the HTML and then save it out as a 'HTML' extension instead of 'webloc'?

# Task: Open Selected WebLoc File in the Given Web Browser.

It operates on the selected file in the Finder...

I've already done all the work.

All I'm doing is taking the XML and replacing a string of "•••••" with the URL.

So all you have to do is change the webloc XML to the HTML XML and then change the file extension.

Simple.

Ah ha right thanks for both. So from what you've said I replace

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>URL</key>
	<string>•••••</string>
</dict>
</plist>

with:

<!DOCTYPE html>
<html>
<body onLoad="go();">
<script>

function go() { location.assign("<key>URL</key>"); }
</script>
</body>
</html>

and change:

~/Desktop/%Variable%local_PageName%.webloc

to

`~/Desktop/%Variable%local_PageName%.html`

Hmm that doesn't do anything.... Sorry I must be missing the obvious.

Look at what I'm finding and replacing...

<!DOCTYPE html>
<html>
<body onLoad="go();">
<script>

function go() { location.assign("•••••"); }
</script>
</body>
</html>

I missed changing the other extension, I've now got it creating a file containing:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>URL</key>
	<string>https://www.bbc.co.uk/weather/m24</string>
</dict>
</plist>

But with no extension....

I think I'll give up, I don't want to trouble you further, but it's obvious I've no ideas what I'm doing :slight_smile:

I've updated the macro to work with the Front Browser, so it will work with Safari, Brave, Google Chrome, and several others.

It works for me on macOS 10.14.6 Mojave with Safari and Google Chrome. I'm not going to bother to test anything else.

It now uses the front-browser text token instead of AppleScript, since Peter has improved things under-the-hood a bit.

Create WebLoc File in Finder from Front Browser v3.00.kmmacros (6.9 KB)
Keyboard Maestro Export

1 Like

Brilliant Chris my thanks. I've looked to change the output to '~/Desktop/%Variable%local_PageName%.html to get it to save to the desktop, but that doesn't work. Any ideas?

There are two places you have to change the path.

I've altered this macro to use the Desktop.

Create WebLoc File in Finder from Front Browser v3.01.kmmacros (7.7 KB)

Display-Macro-Image

Keyboard Maestro Export

1 Like

Chris you are a star as always, that is perfect. Many many thanks.

1 Like