Convert favorites from *.desktop to *.url for MS Windows on Ntfs

Post tutorials, HOWTO's and other useful resources here.
Rapha_
Shogun
Shogun
Posts: 238
Joined: 12 Jun 2021, 21:59
Distribution: Xfce 4.12 - 5.rc3 - x86_64
Location: France

Convert favorites from *.desktop to *.url for MS Windows on Ntfs

Post#1 by Rapha_ » 15 Feb 2022, 20:21

Hello,

Favorites can be saved on the fly by dragging the cadena from a web page address to a folder (this doesn't always work, but I don't know why)


I had 2 problems of compatibility between Linux and Windows:

- The *.desktop favorites files could not automatically open a web page on Internet (only the text content of the file)
- Some files were not readable with Ms Windows on Ntfs disk, because of unauthorized characters ( : " * / : < > ? \ | reserved characters )


I found the solutions

( beware, the *.desktop file name on Linux will not necessarily be the same as the one displayed in Windows: it depends on the text content in the file )





> The first thing to do is to move the "*.desktop" files to an empty folder.

There you place the file conversion script convert_desktop2url.bash :

Code: Select all

#!/bin/bash
#case-insensitive
# source - https://www.linuxquestions.org/questions/programming-9/bash-script-convert-ms-url-files-to-linux-desktop-links-4175483877/
shopt -s nocaseglob
#give folder as argument or execute in current directory
[ -n "${1}" -a -d "${1}" ] && cd "${1}"
for file in *.desktop
do
	URLLINE=$(grep -Ei url= "$file")
	FILENAME=`echo $(basename "$file") | cut -d'.' -f1`
echo -ne "[InternetShortcut]\n$URLLINE" > "$FILENAME.url"
done
Inspired from the source :
https://www.linuxquestions.org/question ... 175483877/

To convert "*.desktop" to "*.url" files :

Code: Select all

$ bash convert_desktop2url.bash



> The second phase is to make compatible some files not recognized because of forbidden characters


So this command line will substitute the characters that are not letters of the alphabet, uppercase [A-Z], lowercase [a-z], digits [0-9], accented characters [àáâäôèéêëçîïùúû] (* but you can add those associated with your language!) , the dot or the dash [.-], by a space "/ /"


Code: Select all

for f in *.url; do nf=$(echo "$f" |sed -e 's/[^A-Za-z0-9àáâäôèéêëçîïùúû.-]/ /g'); test "$f" != "$nf" && mv "$f" "$nf" && echo "$nf"; done
Source :
https://serverfault.com/questions/34848 ... 581#987581



This time it should work !

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Convert favorites from *.desktop to *.url for MS Windows on Ntfs

Post#2 by Rava » 08 Apr 2022, 00:11

The file name conversion one-liner is a neat trick, thanks for finding it.

Did you leave out all upper case accented characters and all German Umlauts on purpose?
The umlauts are ÄÖÜäöü and also ß. (Not sure your ä is the same as the German Umlaut ä, in the font I use both look the same)

Also, the underscore "_" character is also a valid part of VFAT (Long names) or NTFS filenames.

I guess including these would look like so

Code: Select all

for f in *.url; do nf=$(echo "$f" |sed -e 's/[^A-Za-z0-9ÄÖÜàáâäôöèéêëçîïùúûü.-_]/ /g'); test "$f" != "$nf" && mv "$f" "$nf" && echo "$nf"; done
(I am not sure how to include the other upper case accented characters since I am too lazy to look that up and I have no clue if my keyboard would give me some (the standard No Dead keys German keyboard setup has more characters using the AltGr than it is printed on the keys itself…))

E.g. AltGr + h gives me ħ or AltGr + o gives ø - both are NOT German umlaut characters. :) And none of these are printed on the keyboard itself. :roll:
Cheers!
Yours Rava

rych
Warlord
Warlord
Posts: 622
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

Convert favorites from *.desktop to *.url for MS Windows on Ntfs

Post#3 by rych » 17 Apr 2022, 16:02

If you prefer a portable html shortcut, you could use a url2html script as follows

Code: Select all

#!/bin/bash
echo '<head><meta http-equiv="refresh" content="0;'$(grep -iF -m1 url= "$1"| tr -d '\012\015')'"/></head>'>"$1.html"
gio trash "$1"

Post Reply