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?
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?
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.
This solution is multi-platform also:
Create a new simple text file with an .html extension and whatever name you want.
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>
Save the file.
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.
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=%s\nType=Link\nURL=%s\nIcon=text-html\n' "$1" "$2" > ~/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.
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 :
Afterward, one .desktop file shall be added to the desktop of the creator.
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


Once done, just click on them newly created shortcut.
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.
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.
This way will work in All OS {Android, Linux, Windows, Mac}
Create a File With your shortcut name with extension .html e.g. google.html
open in text editor and paste
<script> window.location.href='URL of Website with HTTPS://' </script>
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:
If the Allow Launching option is not there:
Allow Launching should be visible now so click it and there you have your shortcut.
Still an actual problem ...
Most browsers will create a .desktop file, if the internet-address will be dragged from the browser to the file manager or the desktop. A double click on this file opens the address in the default browser.
The main problem with these .desktop files: Mostly these are containing the address data as the file name. If saved on NTFS drives, this can cause conflicts and troubles for system maintenance, backups, system crashes and more, because these names are containing illegal characters for the NTFS file system.
So don't use it on NTFS drives.
This is my experience on:
Operating System: Ubuntu Studio 22.04 KDE Plasma Version: 5.24.7 KDE Frameworks Version: 5.92.0 Qt Version: 5.15.3 Kernel Version: 6.5.0-26-lowlatency (64-bit) Graphics Platform: X11 Processors: 16 × 13th Gen Intel® Core™ i7-13700K Memory: 62.5 GiB of RAM Graphics Processor: NVIDIA GeForce RTX 3060/PCIe/SSE2
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
Done!
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
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.
I added a function in ~/.bashrc so I can create a shortcut from the terminal with:
wlink "https://fabsite.net"
Here's the code.
url_to_filename() {
echo "${1/@/AT}" |
tr '/' '-' |
tr '.' '_' |
tr ':' '_' |
tr '=' '_' |
tr -d '"' |
tr -d "'" |
tr -d '\\' |
tr -d '$' |
tr -d '%' |
tr '?' '_' |
tr '&' '-'
}
wlink() {
wlink_dir="$(pwd)"
[ -n "$2" ] && wlink_dir="$2"
! [ -d "$wlink_dir" ] && echo "not a directory '$wlink_dir', abort" && return
wlink_url="$1"
wlink_url="$(echo "$wlink_url" | sed 's/\//g')" # remove backslashes
sanitized_url="$(url_to_filename "$wlink_url")"
sanitized_url="${sanitized_url#https_--}" # remove https:// segment from filename
wlink_file="${wlink_dir}/${sanitized_url}.desktop"
echo "[Desktop Entry]" >> "$wlink_file"
echo "Encoding=UTF-8" >> "$wlink_file"
echo "Name=$wlink_file" >> "$wlink_file"
echo "Type=Link" >> "$wlink_file"
echo "URL=$wlink_url" >> "$wlink_file"
echo "Icon=text-html" >> "$wlink_file"
echo "created shortcut for url:"
echo "${wlink_url}"
echo "at:"
echo "${wlink_file}"
}