我想在更新後在預覽中重新加載文件(.png,.pdf)。這如何實現?如何在mac預覽10.7中重新加載文件?
在OS X 10.5和10.6中,它與切換到預覽一樣簡單 - 它會自動重新加載新文件。或者,您可以使用open -a Preview *.png
或類似的東西。在10.7中,自動重新加載不起作用(請參閱this post)。
我第一次嘗試是在命令行中運行AppleScript腳本:
/usr/bin/osascript -e 'tell application "Preview.app" to activate
tell application "Preview.app" to open "'$PWD/$*'"'
這適用於單個文件,但失敗,原因是顯而易見的多個文件。我做了一些更多的研究和使用更復雜的AppleScript涉及set
和列表試過了,但是這會導致權限錯誤:
這裏的Python腳本我用(我的bash腳本技能是不達字符串解析的任務): - 沒有看到一個灰色的屏幕重裝圖片 - 我甚至不能確定這個腳本會解決我原來的問題
#!/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))
,但我想知道是否有任何的方式來簡單地用osascript
打開文件列表而不是open
。
編輯:試圖修復AppleScript的,但是這個代碼被「遺漏值」的錯誤:
tell application "Preview.app" to activate
set myListOfImages to {":Users:adam:work:code:test.png"}
tell application "Preview.app" to open myListOfImages
謝謝,這是一個很大的AppleScript的我一無所知。有什麼方法可以修改您的腳本以僅接受目錄中的一部分文件和/或搜索多個擴展?我試圖修改我的代碼來使用:而不是/,但現在得到「缺失值」的錯誤...請參閱編輯示例 – keflavich 2011-12-29 16:51:29
請參閱我的編輯以獲取上述問題的答案。 – regulus6633 2011-12-30 09:28:35