Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to create .webloc files without mousing in big sur? For x-callback & local files

A post from earlier this year....


How to create .webloc files without mousing in big sur?

https://discussions.apple.com/thread/252254646?answerId=254293035022#254293035022


...included an AppleScript that generates a .webloc file for the browser's current window (thank you Vikingmacos). This is very useful for keeping files of URLs so that they can be stored in project folders and avoids having to drag the URL to the Finder to generate the .webloc file.


This works perfectly for URLs (i.e., normal web pages) but does not seem to work for x-callback links or local links (file://...), although both will work by dragging the link from the search field in safari.


Does anyone know if vikingmacos' script can be modified to achieve these extra link types?


TIA!


Posted on Oct 11, 2021 5:55 AM

Reply
Question marked as Best reply

Posted on Oct 12, 2021 4:04 AM

Thank you VikingOSX,


Yes, sorry—you are quite right. This does work for local files. I don't know what happened when I was testing your script with local files yesterday.


BTW, in case anyone is interested; I use a hotkey-triggered Automator to generate local links and prepend 'file://'. It gets copied to the clipboards and can be pasted into text/note files, or into Safari to run with your script.


This JavaScript is the important bit & there is a screenshot of the Automator Quick Action below.


function run(input, parameters) {
	
		input = "file://" + input;
		input=input.replace(/ /g,"%20");
					
	return input;
}






I tried again—but failed—to get some other links to run. I tested on some links to Bear notes, which look a bit like this:


bear://x-callback-url/open-note?new_window=yes&id=0684........


and an OmniFocus link...


omnifocus:///task/dl1j.....


What happens is: If I run your script with the path in Safari I get a webloc of the original page for Safari (e.g., my home page). Makes sense. This happens irrespective of hitting return.


If I do hit return, I'm immediately prompted to open the link in Bear/OmniFocus. I can't see anything in your script that would care about the path's format so I'm guessing that this is a glitch that's created by Safari being helpful! 🙃️


Anyways—this is a very useful script & I can see that I'm going to use it often. Thank you!






Similar questions

3 replies
Question marked as Best reply

Oct 12, 2021 4:04 AM in response to VikingOSX

Thank you VikingOSX,


Yes, sorry—you are quite right. This does work for local files. I don't know what happened when I was testing your script with local files yesterday.


BTW, in case anyone is interested; I use a hotkey-triggered Automator to generate local links and prepend 'file://'. It gets copied to the clipboards and can be pasted into text/note files, or into Safari to run with your script.


This JavaScript is the important bit & there is a screenshot of the Automator Quick Action below.


function run(input, parameters) {
	
		input = "file://" + input;
		input=input.replace(/ /g,"%20");
					
	return input;
}






I tried again—but failed—to get some other links to run. I tested on some links to Bear notes, which look a bit like this:


bear://x-callback-url/open-note?new_window=yes&id=0684........


and an OmniFocus link...


omnifocus:///task/dl1j.....


What happens is: If I run your script with the path in Safari I get a webloc of the original page for Safari (e.g., my home page). Makes sense. This happens irrespective of hitting return.


If I do hit return, I'm immediately prompted to open the link in Bear/OmniFocus. I can't see anything in your script that would care about the path's format so I'm guessing that this is a glitch that's created by Safari being helpful! 🙃️


Anyways—this is a very useful script & I can see that I'm going to use it often. Thank you!






Oct 11, 2021 8:04 AM in response to Seabeethree

You manually open a File URI (file:///) in Safari from its File menu and then run my previous script against it. It will create a .webloc with that File URI in it, and at that point, you are done. Double-clicking a .webloc containing a File URI results in two simultaneous events: 1) a new Finder window opens with that .webloc selected, and Safari opens a blank window. You would need to perform the first sentence again to open that File URI .webloc, so only web-based URL are a practical consideration for .webloc content.

Oct 12, 2021 4:56 AM in response to Seabeethree

Safari supports only a small selection of URI helpers such as (dict://cat and x-man-page://ditto) to name a couple. It would have to be purposely designed to understand bear:// and omnifocus:// URI helpers. Many years ago, one had the ability to add their own URI helpers to Safari, but I no longer have the code example to do that, nor do I expect after years of Safari versions that the capability remains in user hands.

How to create .webloc files without mousing in big sur? For x-callback & local files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.