How to create Firefox (browser) website shortcuts (.desktop files) in Nautilus?

Issues related to applications and software problems and general support
Post Reply
jimj
Posts: 93
Joined: 2014/10/01 05:34:57

How to create Firefox (browser) website shortcuts (.desktop files) in Nautilus?

Post by jimj » 2024/03/07 13:07:08

I've recently migrated from CentOS 7 to CentOS 9 Stream. In CentOS 7 I could follow the Create a desktop shortcut to a website | Firefox Help instructions to create a shortcut to a a website in Nautilus (aka Files). Basically you just drag the padlock icon (left of the URL in the address bar) to open space in a Nautilus (Files) window and it'd create a .desktop shortcut to that website. Now by double clicking that .desktop file Gnome would open Firefox to that website. (These same steps also work for other browsers, like Chrome.)

With CentOS 9 Stream, dragging a URL into Nautilus doesn't do anything. Additionally, all of my old CentOS 7 .desktop files don't work either (they now just launch my text editor).

Here is an example of the contents of a website .desktop file:

Code: Select all

cat Bufferbloat.net.desktop 
[Desktop Entry]
Encoding=UTF-8
Name=Link to What Can I Do About Bufferbloat? - Bufferbloat.net
Type=Link
URL=https://www.bufferbloat.net/projects/bloat/wiki/What_can_I_do_about_Bufferbloat/
Icon=text-html

Does anyone know how to get website .desktop shortcuts working in CentOS 9 Stream?
Last edited by jimj on 2024/03/10 22:06:10, edited 1 time in total.

jimj
Posts: 93
Joined: 2014/10/01 05:34:57

Re: How to create Firefox (browser) website shortcuts (.desktop files) in Nautilus?

Post by jimj » 2024/03/10 22:04:49

Overview
I've done some more research and found a workaround. I really hope Gnome restores this functionality (that it removed in Nautilus 3.30). If CentOS 10 Gnome doesn't fix this I may need to find a different desktop environment. My workaround solutions work, but they're aren't as easy and convenient to use as the old native Gnome functionality.

The single best problem and solution description I found is by Vivek Gani here. Unfortunately, the two parts of his workaround don't work for me, since WeblocOpener doesn't have an RPM for me to install (yes, it's a Java program I could probably get working eventually, but I'm lazy) and the QuickCut
Firefox extension isn't currently working due to a Firefox bug.

Therefore I had to come up with my own solution. This loss of functionality is really two separate problems:
  1. I can no longer create .desktop website link files by dragging the Firefox address into a Nautilus (Files) window
  2. I can no longer open .desktop website link files by double clicking them
Solution 1
To solve problem 1 (create .desktop link files) I used the bookmarklet that HappyPony posted here. I've copied his bookmarklet here to keep this solution all in a single post:

Code: Select all

javascript:(function() { function copyToClipboard(text) {    if (window.clipboardData && window.clipboardData.setData) {        /*IE specific code path to prevent textarea being shown while dialog is visible.*/        return clipboardData.setData("Text", text);    } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {        var textarea = document.createElement("textarea");        textarea.textContent = text;        textarea.style.position = "fixed";  /* Prevent scrolling to bottom of page in MS Edge.*/        document.body.appendChild(textarea);        textarea.select();        try {            return document.execCommand("copy");  /* Security exception may be thrown by some browsers.*/        } catch (ex) {            console.warn("Copy to clipboard failed.", ex);            return false;        }finally {            document.body.removeChild(textarea);        }    }} var DEntryLine = '[Desktop Entry]\n'; var EncodingLine = 'Encoding=UTF-8\n'; var NameLine = 'Name='; var TypeLine = 'Type=Link\n'; var URLLine = 'URL='; var IconLine = 'Icon=gnome-panel-launcher\n'; var CommentLine = 'Comment=\n'; var KeywordsLine = 'Keywords='; var dewDesktopItem = DEntryLine + EncodingLine + NameLine + document.title + "\n" + URLLine + window.location.href + "\n" + IconLine  + CommentLine + KeywordsLine; copyToClipboard(dewDesktopItem); })();
To use this bookmarklet:
  1. Go to a page you want to create a desktop link to
  2. Click the bookmarklet favorite you created in Firefox (this bookmarklet didn't work for me in Chrome)
  3. Create a new text file in Files (Nautilus)
  4. Open the new text file and paste in the text that the bookmarklet generated
  5. Close and save the text file
  6. Rename the text file giving it a ".desktop" extension
Solution 2
To solve problem 2 (open .desktop website link files) I created my own desktop file launcher by creating a file here

Code: Select all

~/.local/share/applications/webLinkFileLauncher.desktop
with this text:

Code: Select all

[Desktop Entry]
Type=Application
Exec=sh -c "xdg-open $(sed -n 's/URL=//p' %f)"
Name=Web link file launcher (.desktop or .URL)
Terminal=false
# Works without the MimeType line, not sure if there's any reason to have this line:
MimeType=application/x-desktop;application/x-mswinurl

You'll notice in the comment in webLinkFileLauncher.desktop that I don't really know what I'm doing, so if someone has a better desktop entry please share it and I'd be happy to copy your work. :) All this "app" does is use sed to pull the URL from the file and pass that to xdg-open which launches the URL in your default browser.

Next you need to associate .desktop files with the new "Web link file launcher (.desktop or .URL)" app we just created by following these steps in Nautilus (Files):
  1. Right click on a .desktop or .URL file
  2. Go to "Open With Other Application > View All Applications"
  3. Scroll down to and select "Web link file launcher (.desktop or .URL)"
  4. Click the "Select" button
Now you can open .desktop or .URL web link files simply by double clicking them (or select the file and press ENTER or "Right click > Open With Web link file launcher (.desktop or .URL)"). Note, in addition to Gnome's native .desktop files this solution also works for Windows' .URL files. That's one small bonus of having to recreate this functionality myself. Thanks to Evan Langlois whose post here gave me the idea of creating this launcher.

George99
Posts: 74
Joined: 2013/09/08 17:01:05
Location: Germany

Re: How to create Firefox (browser) website shortcuts (.desktop files) in Nautilus?

Post by George99 » 2024/03/11 14:13:38

1) Disable the "Desktop Icons" extension
2) Install the "Desktop Icon NG" (DING) extension. This is a (superior) replacement for the original one.
https://extensions.gnome.org/extension/ ... s-ng-ding/

Now you can drag and drop the padlock icon in FF to the desktop/background and create a html bookmark there. Open Nautilus and move this bookmark from the Desktop folder to the desired one. Double clicking in Nautilus now opens the bookmark in FF.

jimj
Posts: 93
Joined: 2014/10/01 05:34:57

Re: How to create Firefox (browser) website shortcuts (.desktop files) in Nautilus?

Post by jimj » 2024/03/25 14:31:12

George99 wrote:
2024/03/11 14:13:38
1) Disable the "Desktop Icons" extension
2) Install the "Desktop Icon NG" (DING) extension. This is a (superior) replacement for the original one.
https://extensions.gnome.org/extension/ ... s-ng-ding/
Thanks for the reply George99, I like the DING solution better than manually creating .desktop link files (solution 1 above). I wished DING would work to any folder in Nautilus, but dragging to the desktop first isn't too bad. I noticed that some URLs don't work correctly (for example dragging a Google Doc heading URL to the desktop doesn't work), so I'll probably keep my solution 1 around as a backup.

While DING is easier to use, I don't like the filename it creates (DOMAINNAME-DATETIME). I prefer to use the web page's title as the base for the filename. Therefore I ran HappyPony's bookmarklet through this Online JavaScript beautifier and modified it to copy a modified version of the page title to the clipboard. Now after dragging the URL to my desktop I simply:
  1. Click my new Firefox bookmarklet which I named "CTL - Copy Title Link"
  2. Select the HTML link file and press F2 to rename it
  3. Paste in the new filename generated by the CTL bookmarklet
  4. Press ENTER to accept the new filename
The code to my new bookmarklet is:

Code: Select all

javascript: (function() {
	function copyToClipboard(text) {
		if (window.clipboardData && window.clipboardData.setData) {
			/*IE specific code path to prevent textarea being shown while dialog is visible.*/
			return clipboardData.setData("Text", text);
		} else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
			var textarea = document.createElement("textarea");
			textarea.textContent = text;
			textarea.style.position = "fixed"; /* Prevent scrolling to bottom of page in MS Edge.*/
			document.body.appendChild(textarea);
			textarea.select();
			try {
				return document.execCommand("copy"); /* Security exception may be thrown by some browsers.*/
			} catch (ex) {
				console.warn("Copy to clipboard failed.", ex);
				return false;
			} finally {
				document.body.removeChild(textarea);
			}
		}
	}

	/* Replace some characters I don't like with a regular hyphen (-)
		Note I've only tested a few of these characters, so I'm not sure all of my replacements below actually work */
	var myTitle = document.title.replace(/\*|\:|\\|\/|\<|\>|\||\"|²|”|@|·|«|»|®|™| |&|Ü|ü|–/g, "-");

	/* Simply remove these characters */
	myTitle = myTitle.replace(/\?|�|‎/g, "");

	/* Append ".link" to the title name */
	myTitle = myTitle + ".link";

	copyToClipboard(myTitle);
})();

Post Reply