Applescript逐个打开文件夹中的所有文件

时间:2013-01-18 14:16:22

标签: applescript

如果我的问题看起来很愚蠢,我只是个初学者。

现在我正在尝试编写一个将我的.webarchive转换为.html的脚本,所以我最终使用名为“iCab”的应用程序来打开.webarchive并将其保存到.html

这是我在保存文件夹中的所有.webarchive的问题,我需要一个循环来逐个打开它,所以我可以将这段代码放在循环中

tell application "iCab" to open file file_name
tell application "iCab" to activate
delay 1
tell application "System Events"
    tell process "iCab"
        click menu item "Save As…" of menu "File" of menu bar 1
        key code 76
        click menu item "Close Window" of menu "File" of menu bar 1
    end tell
end tell

提前谢谢

2 个答案:

答案 0 :(得分:5)

您还需要将文件从Finder文件对象转换为别名。

tell application "Finder"
    set fl to files of folder POSIX file "/Users/username/Folder/" as alias list
end tell
repeat with f in fl
    tell application "iCab"
        open f
        activate
    end tell
    tell application "System Events"
        tell process "iCab"
            click menu item "Save As…" of menu "File" of menu bar 1
            keystroke return
            click menu item "Close Window" of menu "File" of menu bar 1
        end tell
    end tell
end repeat

答案 1 :(得分:1)

尝试:

tell application "Finder" to set myFiles to every file of folder "Mac OS X:Users:Angeloid:Desktop:yourFolder"
repeat with aFile in myFiles
    --insert your code here
end repeat

编辑以包括选择文件夹:

tell application "Finder" to set myFiles to every file of (choose folder)
repeat with aFile in myFiles
    tell application "iCab"
        open file file_name
        activate
    end tell
    delay 1
    tell application "System Events"
        tell process "iCab"
            click menu item "Save As…" of menu "File" of menu bar 1
            key code 76
            click menu item "Close Window" of menu "File" of menu bar 1
        end tell
    end tell
end repeat