2013-11-24 106 views
0

我的PDF閱讀器是Skim.app,我使用下面的蘋果腳本代碼來要求它重新讀取它從磁盤上打開的所有文檔,我經常需要它。問題在於Skim.app有點兒缺陷,多於一種。它的一個缺點是,當它重新加載一個現有的文檔時,它會造成一些干擾。幸運的是縮放一次,並且一次性縮放解決了這個瑕疵問題,但是手動操作非常煩人。AppleScript的菜單按鈕

縮放按鈕位於菜單項「PDF」 - >「放大」中,縮放按鈕爲「PDF」 - >「縮小」。每次運行它時,可以讓蘋果代碼對我進行縮放和縮放。如果是這樣如何?

#!/bin/bash 
/usr/bin/osascript << EOF 
    set theFile to POSIX file "$1" as alias 
    set thePath to POSIX path of theFile 
    tell application "Skim" 
    activate 
    set theDocs to get documents whose path is thePath 
    try 
     if (count of theDocs) > 0 then revert theDocs 
    end try 
    open theFile 
    end tell 
EOF 

回答

0

您可以使用系統事件單擊菜單項。您也可以通過添加顯式運行處理程序來傳遞參數。

#!/usr/bin/osascript 

on run argv 
    tell application "Skim" 
     activate 
     revert (documents where path is item 1 of argv) 
     open POSIX file (item 1 of argv) as alias 
    end tell 
    tell application "System Events" to tell process "Skim" 
     click menu item "Zoom In" of menu 1 of menu bar item "PDF" of menu bar 1 
     click menu item "Zoom Out" of menu 1 of menu bar item "PDF" of menu bar 1 
    end tell 
end run