Applescript quicklook:向下箭头键 1000 次

Applescript quicklook: arrow key down 1000 times

我是 apple 脚本的初学者。

我想打开一个包含数百张照片的文件夹目录,并快速查看每张照片 1 秒,然后转到下一张(假设使用向下箭头/键码“124”)。

我不知道如何构建脚本。我尝试从其他问题中编译一些公式或使用手动记录,但它不起作用。

谢谢!

尝试以下脚本。我延长了延迟时间,以便您有时间停止脚本(以测试它):

set timePerPreview to 5
set thisFolder to (choose folder with prompt "Pick the folder containing the files to process:") as string
tell application "Finder"
    activate
    open folder thisFolder
    select every item in folder thisFolder
    delay 2
    set fileCount to (count items in (get selection)) # (count files in folder thisFolder) is faster but counts also .DS_Store and other invisible files
    if fileCount = 0 then
        beep
        return
    end if
end tell

pressSpaceInFinder()

delay timePerPreview / 2 # first it has to open the window which seems to need a little time

repeat fileCount - 1 times # -1 because the first item is already displayed 
    delay timePerPreview
    # do shell script "sleep" & space & timePerPreview as text
    tell application "System Events"
        tell application process "Finder"
            set frontmost to true
            # cursor right = 124, left = 123
            key code 124
        end tell
    end tell
end repeat

delay timePerPreview

pressSpaceInFinder()

on pressSpaceInFinder()
    tell application "System Events"
        tell application process "Finder"
            set frontmost to true
            keystroke space
        end tell
    end tell
end pressSpaceInFinder

请注意,很难停止 script,因为 Finder 每秒都会被激活。将看看我是否可以添加检查以查看预览 window 是否打开,如果没有,则停止脚本。

另外:(没有那个检查)当预览 window 在 运行 之前打开时,脚本将关闭它,但您可以按 space 键打开它再次.

此外,第一部分(获取文件数)不是很好,当延迟很短时可能会失败。我们可以扫描整个文件夹中的图像,只计算 / select 个(它有一个扫描仪的文件模板,请参阅菜单 File)但是当然你可以删除整个计数的东西,然后做 repeat 1000 times.