52

How can I create a shortcut for URL in my desktop? I want to use them in Firefox or Chrome.

If a copy and paste didn't work.

What script I have to use?

0

13 Answers 13

66

In Ubuntu an URL shortcut is stored in a .desktop file as follow (for example):

[Desktop Entry]
Encoding=UTF-8
Name=Link to Ask Ubuntu
Type=Link
URL=http://www.askubuntu.com/
Icon=text-html

You can drag links from Firefox or Chrome and drop them on the Desktop or any other folder where you have permissions to save files.

Note: Link will appear on your Desktop or your file explorer (i.e. caja) under the name in the line Name=…, not by its actual filename. And without any ….desktop extension.

10
  • Ok, I did this vitor@vitor-HP:~$ vim atalho [Desktop Entry] Encoding=UTF-8 Name=Link to Ask Ubuntu Type=Link URL=askubuntu.com Icon=text-html But didn't appear in my Desktop. Oct 15, 2013 at 18:16
  • 2
    @VitorMazuco You should save that file on your desktop. The file must to have the extension .desktop. See UnityLaunchersAndDesktopFiles. Oct 15, 2013 at 18:42
  • I create vim atalho.desktop but nothing appear in my desktop. Oct 15, 2013 at 19:01
  • 2
    @VitorMazuco How to appear on your desktop if you didn't saved there. You must to save it in your ~/Desktop directory. Oct 15, 2013 at 19:15
  • 1
    In case drag & drop doesn't work, creating a text file with the example contents & saving it as <something>.desktop & making it executable should work
    – Xen2050
    Mar 13, 2017 at 14:38
24

This solution is multi-platform also:

  1. Create a new simple text file with an .html extension and whatever name you want.

  2. Edit the file with the program you want and add this content:

    <html>
        <head>
            <meta http-equiv="refresh" content="0; url=https://askubuntu.com" />
        </head>
        <body> </body>
    </html>
    
  3. Save the file.

1
  • 2
    Works well ! Note that you can simplify code and just keep the meta tag alone. Paste <meta http-equiv="refresh" content="0;url=https://askubuntu.com"> in a .html or .htm file and you're good to go.
    – TwystO
    Dec 29, 2021 at 13:20
9

I needed something like this, but Gnome (now?) requires *.desktop files to be in specific locations, so using those directly wouldn't solve my problem, as I wanted web-links for reference mostly in project folders. And they wouldn't be cross-platform compatible either.

Eventually I turned to Microsoft's .url files, which are easily constructed and look like this:

[InternetShortcut]
URL=https://askubuntu.com

(I read that the trailing line break is important, and probably should be \r\n for Windows compatibility)

And created a .desktop specification to handle them:

[Desktop Entry]
Type=Application
Name=URL Handler
MimeType=application/x-mswinurl;
Exec=bash -c "set -e; P=$(python3 -c 'import configparser,sys,urllib.parse; c=configparser.ConfigParser(); c.read(sys.argv[1])\ntry:\n    u=c[\"InternetShortcut\"][\"URL\"]\n    if not urllib.parse.urlparse(u).scheme in [\"http\",\"https\",\"ftp\",\"ssh\"]: raise Exception(\"Invalid scheme in URI\")\n    print(u)\nexcept Exception as e: print(e,file=sys.stderr); exit(3);' %f); xdg-open \"$P\""

Put that into a file in ~/.local/share/applications/<whatever>.desktop. In my case Gnome immediately bound *.url files to them.

This requires xdg-utils package (for xdg-open, it's likely there if you have a desktop-environment) and python 3.

I really really didn't want to use python, but doing unchecked parsing on something like this didn't suit me. The largest parts of the python script are to avoid infinite loops among other dangers -- in case someone gets funny ideas and puts a file name in a .url file. It ensures that a scheme is present and is one of http(s), ftp, ssh. I guess that list can be easily extended, but I actually don't know which schemes Windows supports.

4
  • 1
    I found a package that works the same: github.com/valerytschopp/ubuntu-mswinurl
    – pzmarzly
    Dec 22, 2020 at 23:46
  • @pzmarzly I hope that doesn't make it into a live distro like this, xdg-open can handle much more than URLs, they should really make sure that there is only an actual URL in that file before running.
    – dualed
    Dec 23, 2020 at 1:11
  • 1
    This works really really well! I was having issues for ages, where the .desktop file just wasn't showing up in my launcher no matter what I tried. Eventually I figured it out - I hadn't copied the Exec command fully, and presumably this was stopping the file being read properly. Mar 13, 2021 at 13:34
  • This is a brilliant solution! Well done @dualed
    – erwin
    Jun 24, 2021 at 6:05
6

Add this to your ~/.bashrc:-

function createUrlShortcut {
    if [ "$#" -ne 3 ]; then
        echo "Illegal number of parameters. Usage : createUrlShortcut Name Url FileBaseName"
    fi
    printf "[Desktop Entry]\nEncoding=UTF-8\nName=$1\nType=Link\nURL=$2\nIcon=text-html" > ~/Desktop/$3.Desktop
}

To create a shortcut, do as follows:-

createUrlShortcut RGB-Dataset https://vision.in.tum.de/data/datasets/rgbd-dataset/download RGBD-Dataset-Link

The first argument is the name you want to be displayed in nautilus.
The second argument is the url.
The third argument is the actual name of the file which will be appended by .Desktop extension.

Note that this will create a file with name RGBD-Dataset-Link.Desktop but will be displayed as RGB-Dataset in nautilus.

4
  • Note the desktop link is created in your current directory. So you need to cd ~/Desktop first or hard code full path into the function. eg change end of line to ~/Desktop/$3.Desktop Nov 8, 2019 at 14:21
  • @WinEunuuchs2Unix Thanks. Completely forgot that user actually asked for putting shortcut in desktop. I will update the answer once I am free. Nov 8, 2019 at 14:49
  • Can confirm this works great. Only enhancement would be to bind it to a short cut key that reads the clipboard of highlighted text (the URL) and prompts for nautilus name and default .desktop file name. Nov 9, 2019 at 0:07
  • @WinEunuuchs2Unix LOL. Above my paygrade(just kidding) :D. Sorry, but sincerely speaking, I am too busy. Will look into this in future. Creating shortcuts is anyways a versatile and beneficial skill ;) Nov 9, 2019 at 17:28
5

Try this. Install Gnome Panel, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo apt-get install gnome-panel

Once installed type this:

gnome-desktop-item-edit --create-new ~/path/to/shortcut

(location of shortcut). In the example below, I will create a shortcut for Ubuntu.com and place it inside the Documents folder. Once I hit Enter a window will open with the properties. See images below.

gnome-desktop-item-edit --create-new ~/Documents

enter image description here

enter image description here

Once done, just click on them newly created shortcut.

2
  • 1
    why all this desktop shortcuts send me to google?
    – user334407
    Mar 7, 2015 at 20:54
  • As of Feb 2020, there's a new package to add cli functionality to gnome-panel called 'gnome-panel-control' that must be installed manually (gnome-panel is installed by default). Jan 31, 2020 at 18:35
4

Additionally, like all solutions that involve a command line, one can do it with a the mouse in three steps in a Chromium like browser :

  1. Click on the menu (the three vertical dots on top right).
  2. Click on "more tools…"
  3. Click on "create application shortcut" to create a shortcut on your desktop
  4. (depending on your configuration) : You could need to right click on the shortcut and add execution permissions

Afterward, one .desktop file shall be added to the desktop of the creator.

2
  • 1
    These are instructions for Chrome by the way. The missing step at the end is to right-click the new icon and choose Allow launching. This is the easiest solution in my experience. Jan 30, 2022 at 23:30
  • @LinuxDisciple : on my computer, I dont need to add the step : Allow launching
    – sangorys
    Feb 11, 2022 at 17:01
2

You can just copy the following into a text file and save it with a .desktop file extension in the desktop folder

[Desktop Entry]
Type=Application
Exec=google-chrome http://google.com
Name=the name of the shortcut
Icon=/path/to/your/photo

This works for me on Ubuntu 20.04. It uses the terminal for launching a URL. you can change google-chrome to firefox if you like that browser more.

I tried different things but this was the one that helped me out.

1
  • This works great for URL shortcuts on the desktop for 20.04. Look no further. But unsure if adding gnome-tweak-tool that I did earlier today was a prerequisite. Also, for me being relatively new to Ubuntu, once the icon appeared on the desktop, I had to right click on it and select 'Allow Launching'. Looking at the permissions alone (ls -la) on the file residing under my Desktop folder did not help me.
    – Alz
    Apr 23, 2021 at 15:01
1

Edit: using Type=Link is superior (see accepted answer).

As some others suggested, a desktop file launching the browser with the url as an argument works really well. I would like to add that you can pass it to xdg-open (installed by default) instead of firefox or google-chrome, to open up the default browser instead of having the browser hardcoded into the file.

Something like:

[Desktop Entry]
Name=Shortcut name
Exec=xdg-open https://example.com/
Type=Application
Icon=applications-internet

Don't forget to include the protocol (https:// in this case), or xdg-open will be looking for a directory instead.

Then, make sure to right click the file on the desktop and select "Allow Launching" (Ubuntu 20.04) to turn it into a desktop icon.

1
  • What extension?
    – Vitalicus
    Mar 22, 2022 at 18:02
0

Wow this was sticky! So many answers with such complexity, here is a clean solution -

Solution

        QuickCut - Add a context menu to quickly save shortcut files (url, desktop, webloc)

Procedure

  1. Navigate to Add-Ons Page
  2. Select '+ Add to Firefox'
  3. Select the QuickCut icon on upper right of toolbar to generate a link to the active page
  4. Navigate to Downloads/ to retrieve your new shortcut

Done! 🙏🏻

0

I had the same problem with creation shortcuts from chromium, and I found how to fix it for myself: for example -

#!/usr/bin/env xdg-open
Desktop Entry
Version=1.0
Terminal=false
Type=Application 
Name=Free Rice App
Exec=/snap/chromium/1424/usr/lib/chromium-browser/chrome --profile- 
directory=Default --app-id=pjnkpknhgjomoapaopdalojkjohlheic
Icon=chrome-pjnkpknhgjomoapaopdalojkjohlheic-Default
StartupWMClass=crx_pjnkpknhgjomoapaopdalojkjohlheic

I just add "chromium" to exec, and now it's work for me, and the final code looks like -

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=Free Rice App
Exec=chromium /snap/chromium/1424/usr/lib/chromium-browser/chrome --
profile-directory=Default --app-id=pjnkpknhgjomoapaopdalojkjohlheic
Icon=chrome-pjnkpknhgjomoapaopdalojkjohlheic-Default
StartupWMClass=crx_pjnkpknhgjomoapaopdalojkjohlheic
0

I'm using Ubuntu 20.04 and most the answers didn't work for me.

What worked for me is creating a .desktop file in the Desktop with below code (you can change firefox to google-chrome and add icon if you want to).

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=clickup - Google Search
Exec=firefox https://www.google.com/search?q=clickup&oq=clickup&aqs=chrome..69i57j0i512l9.1847j0j7&sourceid=chrome&ie=UTF-8

and then right click the file and select Allow Launching:

Allow launching

If the Allow Launching option is not there:

  • Click Properties and click the Permission tab.
  • Change Others access to read only and group,owner access to read and write, and;
  • Don't forget to tick Allow executing file as a program.

Properties

Allow Launching should be visible now so click it and there you have your shortcut.

0

This way will work in All OS {Android, Linux, Windows, Mac}

  1. Create a File With your shortcut name with extension .html e.g. google.html

  2. open in text editor and paste

<script>
window.location.href='URL of Website with HTTPS://'
</script>
  1. Thats it...
0

I'm using Zorin Core + Chrome. In Chrome, go to More Tools/Create Shortcut (just like in Windows). This will create a file on your desktop but it doesn't do anything so delete it. Look in Start/Google Apps. There it is! Right click on it and choose to add to Favorites (taskbar) or desktop. These shortcuts have the web site's icon, BTW. You can delete them from Start/Google Apps using the Main Menu app in Zorin.

1
  • ZorinOS is off-topic here. Zorin specific desktop features are therefore irrelevant for the question. Dec 6, 2022 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.