Search code examples
macosapplescriptquicklook

Is there a way to trigger Finder's "quick look" window with Applescript?


I am using Applescript to automate some tasks in the OSX Finder. The script opens up a folder and selects the first image in that folder. I would like it to also bring up the "quick look" window (exactly as if the user had pressed the space bar).

I did find a way to fire up quick look from the command line using qlmanage, but that brings up a static quick look window, which is no longer tied to the finder selection.

Code so far:

property folderPath : "/Volumes/Media/Images"

on run {}
    tell application "Finder"
        activate
            set imageFolder to folder (folderPath as POSIX file)
            set imageFile to first item of imageFolder
            select imageFile
            -- show quick look?
    end tell
end run

Solution

  • Updated (with thanks to Kevin Ballard):

    tell application "System Events" to keystroke "y" using command down
    

    Note: this requires that "enable access for assistive devices" is selected in the "Universal Access" control panel.