You may be out of luck with Preview (see, e.g., this question and this question on our Apple sister site). The fact is that Preview is not really designed for this type of situation.
This question on StackOverflow offers a solution that may work, by adding a script to forcibly close and then re-open the PDF when it is updated. Since Preview remembers the last location used, this may work, but it may run into a timing issue (does the script get the file event before or after Preview?) and seems to require having a terminal window open.
Alternatively, since TeXStudio can send file and line information to an external program, it wouldn't be impossible to write a script that takes this information, finds the corresponding PDF position using the synctex
utility (included with MacTeX) and use something like the osascript commands in this script to at least get Preview to the right page. Something like this (this doesn't do any error checking and I haven't really tested it):
#!/bin/sh
PDFFILE=$1
TEXFILE=$2
LINE=$3
PAGE=$(synctex view -i "$LINE:0:$TEXFILE" -o "$PDFFILE" | grep 'Page' | head -n 1 | sed 's/Page://g')
if [$PAGE -eq '']; then PAGE=1; fi
open -a Preview "$PDFFILE"
sleep .5
osascript -e 'tell application "Preview" to activate' \
-e 'delay 0.25' \
-e 'tell application "System Events" to tell process "Preview" to click menu item "Go to Page…" of menu "Go" of menu bar 1' \
-e 'delay 0.25' \
-e "tell application \"System Events\" to keystroke \"$PAGE\"" \
-e 'delay 0.25' \
-e 'tell application "System Events" to key code 36'
Which could be save somewhere as open_preview
, marked executable (chmod u+x open_preview
) and then used from TeXStudio by setting the viewer command to:
</path/to/open_preview> ?am.pdf ?c:am.tex @
This won't keep the scroll position, but it should at least open the same page as the one you're working on in TeXStudio.
The sanest thing to do, however, is install Skim and use that for previewing the documents, as it implements the reload and stay in place feature and TeXStudio includes instructions for integrating with it.