Applescript quicklook: arrow key down 1000 times

680 views Asked by At

I'm a total beginner in apple script.

I would like to open a folder directory that contains hundreds of photos and to view each photo 1 second with quick look and then go to the next (suppose to use down arrow / key code '124').

I don't have any idea of how to build the script. I tried to compile some formulas from other questions or use the manual rec but it doesn't work.

Thanks!

1

There are 1 answers

2
AudioBubble On BEST ANSWER

Try following script. I made the delay longer so you have time to stop the script (to test it):

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

Be aware that it is hard to stop the script since the Finder gets activated every second. Will see if I can add a check to see if the Preview window is open and if not, stop the script.

Also: (without that check) the script will, when the Preview window is open before running, close it but you can just press the space key to open it again.

Also, the first part (getting the file count) isn't so great and may fail when the delay is to short. We could scan the whole folder for images and only count / select those (it has a file template for the scanner, see menu File) but of course you can remove the whole counting thing and just do repeat 1000 times.