1

From firefox, if I highlight the address and drag it to the desktop a .desktop file is created that links to that page. The name has the form "Link to ...". Is there a setting to get rid of the "Link to " part?

EDIT: To clarify, I like to drag webpage links to the desktop (or another directory) where a .desktop file is created. However, I don't like the "Link to ..." naming scheme. I realize I could rename the files as a second step, but I'm asking if there's a way to avoid that step.

2
  • 1
    Can't you just right click it and rename it? Sep 16, 2015 at 23:19
  • Yes I can rename it, but that's an extra step. :-)
    – CrazyApe84
    Sep 16, 2015 at 23:26

1 Answer 1

1

The naming is probably coded in nautilus, and hard to change.

What can be done however is to automatically fix it, either without any action from your side, or with a shortcut key. The only limitation is that it would work with a specific set of directories, such as the desktop and an arbitrary number of additional directories (of your choice).

enter image description here

automatically becomes:

enter image description here

What it does

The proposed solution is, at your choice, either:

  • a background script, automatically looking for "faulty" -named .desktop files and renaming them immediately and automatically, or:
  • a script, called by a shortcut key combination, doing exactly the same, but only whenever you press the key(s)

The script; background version

I tested the script on processor load, and I could not notice any extra activity (using system monitor) on my elderly system (at least 6-7 years old).

Background version

#!/usr/bin/env python3
import time
import os
import sys

dirs = sys.argv[1:]
# ---you might need to edit the string below to your local (language) version
edit_out = "Link to"
# ---

def edit_link(dr, newfiles):
    for f in newfiles:
        file = dr+"/"+f; text = open(file).read().splitlines()
        for i, l in enumerate(text):
            if all([l.startswith("Name="), edit_out in l]):
                text[i] = text[i].replace(edit_out+" ", "")
                open(file, "wt").write("\n".join(text))

files1 = []
while True:
    time.sleep(2)
    for dr in dirs:
        files2 = os.listdir(dr)
        newfiles = [f for f in files2 if all([not f in files1, f.endswith(".desktop")])]
        edit_link(dr, newfiles)
        files1 = files2
  1. Copy it into an empty file
  2. Save it as rename_links.py
  3. Change if necessary in the line:

    edit_out = "Link to"
    

    the string "Link to" by the localized string in your language ("Verwijzing naar" in Dutch)

  4. Test- run it by the command:

    python3 /path/to/rename_links.py <directory_1> <directory_2> (etc.)
    

    where you can add as many directories as you like (use quotes if the directory contains spaces)

  5. If all works fine, add it to your startup applications: Dash > Startup Applications > Add the command:

    python3 /path/to/rename_links.py <directory_1> <directory_2>
    

Shortcut version

#!/usr/bin/env python3
import os
import sys

dirs = sys.argv[1:]
edit_out = "Link to"

def edit_link(dr):
    files = os.listdir(dr)
    for f in files:
        if f.endswith(".desktop"):
            file = dr+"/"+f; text = open(file).read().splitlines()
            for i, l in enumerate(text):
                if all([l.startswith("Name="), edit_out in l]):
                    text[i] = text[i].replace(edit_out+" ", "")
                    open(file, "wt").write("\n".join(text))

for dr in dirs:
    edit_link(dr)

The set up is exactly the same as the background version, apart from [5.]:

  1. If all works fine, add the script to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/rename_links.py <directory_1> <directory_2>
    

Explanation

The name, as it appears on your desktop, is not the file -name, but the name, as defined in the Name= line of the .desktop file.

The script looks into possible .desktop files in the directories, you used as an argument. If it finds a line, starting with Name=Link to, it replaces (removes) Link to + one space, effectively renaming the visible name of the launcher on your desktop.


Edit

Looking for a "native" solution, I tried Mozilla's add-on Deskcut to see what it does with the name of the link. On both 14.04 and 15.04 it did totally nothing however.

4
  • It's disappointing that there's no option to get rid of the "Link to" at the source (so to speak). Maybe I'll request it of the Nautilus team. I remember a similar thing with Windows, but there was a setting somewhere to get rid of it.
    – CrazyApe84
    Sep 17, 2015 at 17:53
  • 1
    @CrazyApe84 I'll sneak around as well, will post if I find something "at the source", but I think it will be difficult... Sep 17, 2015 at 17:56
  • 1
    Hi @CrazyApe84 I reduced the load even more. The script's presence in the load is practically none now. Sep 18, 2015 at 10:00
  • That's some fine programming, my friend. I've installed it and it works great. I was looking into a "native" solution and considered modifying a .po file to translate "Link to %s" to simply "%s", which would presumably work, but I don't even know where to find the .po files (or if they're even installed for American English). I perused the "Canadian English" .po file from launchpad.
    – CrazyApe84
    Sep 18, 2015 at 14:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .