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?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityIn 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.
.desktop
. See UnityLaunchersAndDesktopFiles.
Oct 15, 2013 at 18:42
~/Desktop
directory.
Oct 15, 2013 at 19:15
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.
<meta http-equiv="refresh" content="0;url=https://askubuntu.com">
in a .html or .htm file and you're good to go.
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.
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.
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.
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
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.
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.
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.
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 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.
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 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.