Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leob/80bbce762e704997eecc8deeda0c26aa to your computer and use it in GitHub Desktop.
Save leob/80bbce762e704997eecc8deeda0c26aa to your computer and use it in GitHub Desktop.
#!/bin/bash
# A script which can be useful if you have a large collection of Ubuntu Linux "desktop" files pointing to web links (URLs),
# and you want to convert these to "webloc" files which can be used on Apple OSX.
#
# How to use:
#
# - open a terminal on your Ubuntu Linux machine, navigate to your ~/desktop folder (or wherever you have your ".desktop"
# files stored), and make a copy of the files/directories/directory tree. I do it with "tar", for instance:
#
# tar cvfz my_desktop_files.tar.gz ~/desktop
#
# - copy the tar.gz file to your OSX machine
#
# - open a terminal on your OSX machine, create a new directory, and unpack the tarball there:
# tar xvfz my_desktop_files.tar.gz
#
# - from the root of the newly created directory, run this shell script. This will convert all of the ".desktop" files
# containing URLs to OSX-style ".webloc" files (it does this in all of the subdirectories too). The ".desktop" files are
# not deleted but renamed.
#
# Modified from:
# http://apple.stackexchange.com/questions/237391/google-chrome-on-osx-will-not-open-desktop-files-created-in-ubuntu
f="$1"
dir=$(dirname "$f")
file=$(basename "$f")
bak="$dir/_bak"
if [[ ! -d "$bak" ]]; then
mkdir "$bak"
fi
#echo "dir: $dir"
#echo "file: $file"
#echo "bak: $bak"
url="$(awk -F '=' '/^URL=/{print $2}' "$f")"
if [[ -z $url ]]; then
url="$(awk -F ' ' '/new-window/{print $3}' "${f}.processed")"
fi
if [[ ! -z $url ]]; then
cat <<EOF >"${f%.*}.webloc"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>URL</key>
<string>$url</string>
</dict>
</plist>
EOF
mv "$f" "$bak"
else
echo " No URL found in $f file."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment