Apparently my Blog space here has become more of a list of Ubuntu/Linux tips and tricks. Probably mostly for me to reference in the future more than anything, but I'm sure other people might find this useful and interesting.
Anyway, this evening I was looking to install some new fonts into my machine. I tried GNOME Font Viewer, which was supposed to give the ability to install new fonts in addition to previewing existing ones. The main thing I wanted to do was get the files into the right place. Unfortunately, although GNOME Font Viewer, did the viewing part just find, installation options were no where to be seen. Drag-and-drop onto it didn't work... and other reviews complained about that feature not working anymore either, so I went out to search for a simple command line method.
I found a method on
https://www.unixtutorial.org/how-to-install-ttf-fonts-in-linux/ which worked easily enough. Then I decided to make a Bash script out of it. Then I wanted to make it so I could just double-click an icon on my desktop and run it. Well... now I have all that working. Here's how it goes.
My Bash script, install-fonts.sh was created. This file will be saved in my home directory. I was using echo to display the messages in the terminal, but after creating the Desktop file to run with, I decided to use notify-send for pop-up messages on the desktop. This way works with both, and depending on which option is used on the Desktop file, the option to view the terminal could set to either true or false depending on preferences since it's not necessary.
Filename: install-fonts.sh
Permissions: 751
#!/bin/bash
MSG="Installing fonts from Downloads:"
echo "$MSG"
notify-send "$MSG"
MSG=`ls ~/Downloads/*.ttf`
echo "$MSG"
notify-send "$MSG"
cp ~/Downloads/*.ttf ~/.local/share/fonts/
fc-cache -f
MSG="Installation complete."
echo "$MSG"
notify-send "$MSG"
The second file needed is the Desktop file, install-fonts.desktop.
Filename: install-fonts.desktop
Permissions: 751
[Desktop Entry]
Name=Install Fonts
Comment=Install new fonts from Downloads
Exec=/home/dragon/install-fonts.sh
Terminal=false
Type=Application
The first time that you double-click this icon, you'll probably get a warning prompt that says "Untrusted application launcher" with two buttons, "Cancel" and "Trust and Launch". If you only get a Cancel button, you probably haven't added execute privileges to the Desktop file. That can be done by right-clicking, selecting Permissions, and the check the box to Execute: Allow executing file as program... or you could run "chmod +x install-fonts.desktop" in your terminal.
If you want to see the script run in the terminal when you double-click this Desktop file, simply change that "Terminal=false" line to "Terminal=true". Also, if you want to change the icon to an image of your own, simply add something like "Icon=/home/username/image.png" to this Desktop file. Otherwise, it will use whatever the default is for the system.
There's another issue that you might see if you're trying to use a relative path to your home directory also. Write out the path instead of using the tilde (~). It works fine in the Bash script, but not in the Desktop file.