Safari2OPML source code
Home page > OS X Portable Applications > Safari2OPML source code
Safari2OPML script source code:
Shell script (release 2.0)
Safari2OPML.app is packaged using the Platypus script wrapper from http://sveinbjorn.sytes.net/platypus
CocoaDialog included by Mark A. Stratman.
Safari2Firebird.xslt included by K.O. Koyeung.
#!/bin/sh
##########################################################################
#
# Safari2OPML
# $Revision: 2.0
#
# The Contents of this file are made available subject to the terms
# of the following license
#
# - GNU General Public License Version 2.1
#
# Carlo Gandolfi, November 2006 <crgand@users.sourceforge.net>
#
# GNU General Public License Version 2.1
# =============================================
# Copyright 2006 by:
# Carlo Gandolfi - crgand at users.sourceforge.net
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License version 2.1, as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
##########################################################################
#
# CocoaDialog is Copyright © 2004,
# Mark A. Stratman <mark@sporkstorms.org>
# and is licensed under the GNU General Public License.
#
##########################################################################
#
# SafariFeeds2OPML.xslt is Copyright © 2006,
# King-On Yeung <koyeung@gmail.com>
# Homepage: http://koyeung.blogspot.com/
# and is licensed under the GNU General Public License.
#
##########################################################################
CD="$1/Contents/Resources/CocoaDialog.app/Contents/MacOS/CocoaDialog"
appicon="$1/Contents/Resources/appIcon.icns"
cautionicon="$1/Contents/Resources/S2O_Caution.icns"
BOOKMARK_BIN="$HOME/Library/Safari/Bookmarks.plist"
BOOKMARK_XML=`mktemp -t Bookmarks`
OPML_XSL="$1/Contents/Resources/SafariFeeds2OPML.xslt"
function beep {
/usr/bin/osascript << EOT
tell application "Finder"
beep
end tell
EOT
}
# ========================================================
# osx_version_check
# Check that the user is running Mac OS X 10.4 or higher
# ========================================================
function version_check_msg {
message1="You are running OS X version $version.\n\
Safari2OPML can only be opened on Mac OS X 10.4 or higher."
button=`/usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message1" buttons {"Quit"} \
with icon caution default button "Quit"
set result to button returned of result
end tell
EOT`
if test "$button" == "Quit"; then
exit 1
fi
}
function osx_version_check {
if [ -x "/usr/bin/sw_vers" ] ; then
version=`/usr/bin/sw_vers | grep '^ProductVersion:' | awk '{ print $2 }'`
case "$version" in
10.[0123]) version_check_msg ; exit 1;;
10.[0123].*) version_check_msg ; exit 1;;
esac
fi
}
# ========================================================
# export_opml_sqlite
# Export Safari RSS to OPML
# ========================================================
function export_opml_xml {
NOW=`date "+%y-%m-%d_%H.%M.%S"`
BOOKMARK_OPML="$filepath/Safari_$NOW.opml"
plutil -convert xml1 "$BOOKMARK_BIN" -o "$BOOKMARK_XML"
xsltproc -o "$BOOKMARK_OPML" "$OPML_XSL" "$BOOKMARK_XML"
rm -f "$BOOKMARK_XML"
if [ -f "$BOOKMARK_OPML" ] ; then
"$CD" bubble --title "Export Safari RSS to OPML" --text \
"Safari_$NOW.opml saved with success." --icon-file "$appicon" &
else
beep
$CD ok-msgbox --icon-file "$cautionicon" \
--text "Export Safari RSS to OPML Error" \
--informative-text "An error occour while export Safari_$NOW.opml. Now quit."\
"--no-cancel" > /dev/null
exit 0
fi
}
# ========================================================
# safari_2_opml
# Export Safari RSS to OPML
# ========================================================
function safari_2_opml {
folderpath=` "$CD" fileselect --title "Export Safari RSS to OPML" --text \
"Please select destination folder to save \"Safari.opml\" file." \
--select-only-directories --with-directory $HOME `
filepath="$folderpath"; export filepath
if [ -n "$folderpath" ]; then
rv=` $CD msgbox --icon-file "$appicon" \
--text "Export Safari RSS to OPML" \
--informative-text "You have selected \"$filepath/\" folder to save \"Safari.opml\" file." \
--button1 "Save & Quit" --button2 "Cancel" --button3 "Quit" `
if [ "$rv" == "1" ]; then
export_opml_xml
elif [ "$rv" == "2" ]; then
safari_2_opml
elif [ "$rv" == "3" ]; then
exit 0
fi
else
exit 0
fi
}
osx_version_check
safari_2_opml
exit 0
EOF