简单的脚本不再适用于Lion

时间:2012-07-09 20:50:55

标签: osx-lion applescript

我有一个简单的Applescript,它会在您选择的文件夹中获取大量图像,然后使用Graphic Converter镜像图像。如果我将它放在一个新的AS文件中,它将运行;但是,如果我第二次尝试运行它,我会收到以下错误“无法获取应用程序的窗口1”GraphicConverter“。索引无效。”

此脚本始终在OSX 10.6上运行

我正在运行OSX 10.7.4和Graphic Converter 8.1(最新版本)。

这是脚本

tell application "Finder"
   activate
   set loopFinish1 to 0
   set pathName to (choose folder with prompt "Choose Folder Containing Images")
   set fileList1 to every file of folder pathName
   set loopFinish1 to count of items of fileList1
end tell

tell application "GraphicConverter"
   activate
   repeat with i from 1 to loopFinish1
       set currentFile to item i of fileList1
       open currentFile as alias
       mirror window 1 in horizontal
       close window 1 saving yes
   end repeat
end tell

这让我发疯了!

1 个答案:

答案 0 :(得分:2)

GraphicConverter 有其他窗口(可见和不可见),最好使用该文档来获取正确的窗口。 此外,可能图像未打开,因此没有窗口,使用try块。

activate
set pathName to (choose folder with prompt "Choose Folder Containing Images")
tell application "Finder" to set fileList1 to (document files of folder pathName) as alias list

tell application "GraphicConverter"
    activate
    repeat with tFile in fileList1
        set currentDoc to open tFile
        set CurrWindow to (first window whose its document is currentDoc)
        mirror CurrWindow in horizontal
        close currentDoc saving yes
    end repeat
end tell