webloc2url.sh – Convert webloc to url files

webloc2url.sh

View your links anywhere. Converts .webloc to .url

Have a lot of webloc (stored hyperlinks) files and want them share with your
Windows colleagues? No problem. Just convert them all to url (Windows) files.

webloc2url-introI like Bookmarks, but... Working with Links, URL, etc. in a Project

On a Mac: You find an interesting page on the Internet. Instead of bookmarking it, you can also drag & drop the current site URL from your default Web Browser to a folder in Finder. This will create a .webloc file. Later on you can easily open that link again by just double click on the .webloc file.

On Windows: Just drag & drop the URL from web browser to Windows File Manager in a directory. This will create a .url file. You can later on double click this .url file to open up the site stored in the dot url file.

Why do I need this?

Why you should do that? Well, for example if you are working on a project with others, and you all store files on a local network drive. If you are working an a Mac, your links will be .webloc files.

webloc2url.sh can add to any .webloc file a .url file as well. So Mac and Windows users will be happy again.

Download

See: https://github.com/flagsoft/webloc2url

Example Usage

1. Just copy webloc2url.sh to sub folder

2. cd to sub folder

3. run it!

4. For every .webloc file in the current folder and all sub folders webloc2url.sh will create a new .url file.

Example:

[code language="bash"]
cd ./top_path_to_webloc_dir/
bash ./webloc2url.sh
[/code]

What does it?

Sample webloc file:

[code language="xml"]
<?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>http://www.google.com</string>
</dict>
</plist>
[/code]

Get's converted to url file like this:

[code]
[InternetShortcut]
URL=http://www.google.com
[/code]

 

Source Code

(Latest version is on Github. See Download title.)

[code language="bash"]
#!/bin/bash
##
## webloc2url.sh - Converts webloc (Mac) to url (Windows) files.
##
## Copyright (c) 2015 by mzm
##
## License:
## GPL
##
## Description:
## Converts .webloc Mac files in current folder and all subfolders to .url
##  files for Windows.
##
## Usage:
## cd ./top_path_to_webloc_dir/
## bash ./webloc2url.sh
##
## Details:
##
## Input: "link.webloc" (Mac):
## ---------------------------------------------------------------------------------------
## <?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>http://www.google.com</string>
## </dict>
## </plist>
## ---------------------------------------------------------------------------------------
##
## Output "link.url" (Windows):
## ---------------------------------------------------------------------------------------
## [InternetShortcut]
## URL=http://www.google.com
## ---------------------------------------------------------------------------------------
##
## Misc:
##
## URL aus .webloc-Datei auslesen
## Getestet mit: Mac OS X 10.4.8 und AppleScript 1.10.7
## Wenn man den URL aus einer .webloc-Datei (wird erstellt wenn man aus Safari den URL
## zum Beispiel auf den Schreibtisch zieht) auslesen möchte, dann kann man dies wie folgt tun:
##
## set the_file to choose file
## try
##  tell application "Finder"
##  set the_location to location of file the_file
##  display dialog the_location buttons {"OK"} default button 1
##  end tell
## end try
##

echo ""
echo "webloc2url.sh Copyright (C) 2015 by mzm"
echo "This program comes with ABSOLUTELY NO WARRANTY; for details see file LICENSE."
echo "This is free software, and you are welcome to redistribute it"
echo "under certain conditions; see file LICENSE for details."
echo ""

TEMP_LIST="webloc2url-list.txt.$$.tmp"

find . "(" -name "*.webloc" ")" > $TEMP_LIST

while read p; do

echo "Found webloc: $p"
## $p: ./some/dir/link.webloc
DIR=$(dirname "${p}") ## ./some/dir
FILENAME=$(basename "${p}") ## link.webloc
FILENAME_BASE=$(basename "$FILENAME" .webloc) ## link

TEMP_FILE=$DIR/temp_link.url.$$.tmp ## ./some/dir/temp_link.url.2342343.tmp

FILEPATH_url="${DIR}/${FILENAME_BASE}.url" ## ./some/dir/link.url

## remove any "._XY" files - AppleDouble encoded Macintosh file
## see: http://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_formats
dot_clean -m $DIR

LINK=`cat "$p" | grep "string" | sed "s/<string>//" | sed "s/<\/string>//" | sed "s/ //"`
echo " - Link is: $LINK"

#FILEPATH_url_q=$(printf %q "$FILEPATH_url")
#echo "** FILEPATH_url_q: $FILEPATH_url_q"

echo " - Create Windows url file"

echo "[InternetShortcut]" > ${TEMP_FILE}
echo "URL=$LINK" >> ${TEMP_FILE}

#echo "${TEMP_FILE} -> ${FILEPATH_url}"
mv ${TEMP_FILE} "${FILEPATH_url}"

echo ""

done < $TEMP_LIST

rm -f $TEMP_LIST

echo "all done."

## EOF.
[/code]

Q&A

Q: What about Ubuntu / Linux?

A: I did not test that. Maybe the .url file is compatible with Ubuntu Linux.

Q: What are .webloc files?

A: .webloc files are Mac only files (Mac Finder will interpret it and open default Web browser with URL)

Q: What are .url files?

A: .url files are from Windows but works also on Mac (These .url files can be interpreted by Windows and Mac OS X)

Support

Just leave a comment below!

Helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *