--- /dev/null
+#!/bin/bash
+# $ pdflatex somefile.tex && preview.sh somefile.pdf
+# Preview.app will close the file and reopen it
+# You must run this command first to update your Preview.app bundle to support
+# basic AppleScript
+# $ defaults write /Applications/Preview.app/Contents/Info NSAppleScriptEnabled -bool YES
+
+filename="${1}"
+if [ ! -r "${filename}" ]; then
+ echo "Error, could not read ${filename}"
+ exit 1
+fi
+
+osascript <<EOF
+tell application "Preview"
+ repeat with theWindow in windows
+ if name of theWindow starts with "$(basename "${filename}")" then
+ close theWindow
+ end if
+ end repeat
+end tell
+EOF
+
+open "${filename}"
+