I'd like to reload files (.png, .pdf) in Preview after they have been updated. How can this be accomplished?
In OS X 10.5 and 10.6, it was as simple as switching to Preview - it would automatically reload the new file. Alternatively, you could use open -a Preview *.png
or something similar. In 10.7, auto-reloading doesn't work (see this post).
My first attempt is an applescript script run from the command line:
/usr/bin/osascript -e 'tell application "Preview.app" to activate
tell application "Preview.app" to open "'$PWD/$*'"'
This works for a single file, but fails with multiple files for obvious reasons. I did a little more research and tried using a more complicated applescript involving set
and a list, but this results in permissions errors:
Here's the python script I used (my bash scripting skills were not up to the task of string parsing):
#!/usr/bin/env python
import optparse
import os
parser=optparse.OptionParser()
options,args = parser.parse_args()
pwd = os.getcwd()
cmd = '/usr/bin/osascript -e '
scriptcmd = "tell application \"Preview.app\" to activate\n"
flist = [ fn if fn[0]=='/' else pwd+"/"+fn for fn in args]
scriptcmd += "set myList to {\"%s\"}\n" % ( '","'.join(flist) )
scriptcmd += "tell application \"Preview.app\" to open myList"
print("%s \'%s\'" % (cmd,scriptcmd))
os.system("%s \'%s\'" % (cmd,scriptcmd))
I'm not even sure this script would have solved my original problem - reloading images without seeing a gray screen - but I'd like to know if there's any way to simply open a list of files with osascript
instead of open
.
EDIT: Attempted to fix applescript, but this code gets "missing value" errors:
tell application "Preview.app" to activate
set myListOfImages to {":Users:adam:work:code:test.png"}
tell application "Preview.app" to open myListOfImages