]> code.delx.au - monosys/commitdiff
Utility to reload documents in Preview.app
authorJames Bunton <jamesbunton@fastmail.fm>
Tue, 25 Sep 2007 09:45:27 +0000 (19:45 +1000)
committerJames Bunton <jamesbunton@fastmail.fm>
Tue, 25 Sep 2007 09:45:27 +0000 (19:45 +1000)
scripts/osx_preview [new file with mode: 0755]

diff --git a/scripts/osx_preview b/scripts/osx_preview
new file mode 100755 (executable)
index 0000000..61ab2c4
--- /dev/null
@@ -0,0 +1,25 @@
+#!/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}"
+