2013-06-04 45 views
0

我有一个看起来像这样一个AppleScript:AppleScript的关闭窗口PDF

repeat 
    tell application "Adobe Reader" 
    open "filepath/name.pdf" 
    end tell 

    delay (60) 

    tell application "Adobe Reader" 
    open "filepath/name1.pdf" 
    end tell 

    delay (60) 

    tell application "Adobe Reader" 
    open "filepath/name2.pdf" 
    end tell 

    delay (60) 

end repeat 

我希望能够在被打开后关闭PDF窗口。问题在于这些pdf位于共享上,用户有能力更新它们。如果脚本停止并重新启动,脚本将只显示更新的pdf。我不想手动执行此操作。我怎样才能做到这一点?

+0

关闭一个窗口应该很容易。 “窗口1”通常是前(活动)窗口,因此“关闭窗口1”应关闭该窗口(或“告诉窗口1关闭”)。如果你这样做,窗口关闭,下一个窗口将变为“窗口1”(如果有的话)等等。 – 2013-06-05 03:33:40

+0

为什么在Adobe Reader中这样做?难道你不认为预览更容易编写脚本吗? – Mark

回答

0

下面是一个解决方案,它使预览脚本,然后继续打开和关闭您选择的文件。

-- http://www.macworld.com/article/1053391/previewscript.html 
on addAppleScriptFeatures() 
    try 
    tell application "Finder" 
     set the Preview_app to (application file id "com.apple.Preview") as alias 
    end tell 
    set the plist_filepath to the quoted form of ¬ 
     ((POSIX path of the Preview_app) & "Contents/Info") 
    do shell script "defaults write " & the plist_filepath & space ¬ 
     & "NSAppleScriptEnabled -bool YES" with administrator privileges 
    do shell script "chmod -R 755 " & the quoted form of (POSIX path of the Preview_app) with administrator privileges 
    return true 
    on error myErr number MyNr 
    display dialog myErr & " (" & MyNr & ")." buttons {"OK"} default button "OK" with icon 0 
    return false 
    end try 
end addAppleScriptFeatures 

if addAppleScriptFeatures() then 
    set f to choose file 
    tell application "Preview" 
    activate 
    open f 
    delay 5 -- short for testing 
    close window 2 
    end tell 
end if