5

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

2 Answers 2

12

If you don't want to do it by scripting the Finder you can run the following shell command

qlmanage -p thefile

In an Applescript you might do this like

do shell script "qlmanage -p " & "thepath/thefile"

Depending upon what you are doing this might be much easier. Especially if you primarily just have a set of paths.

If you have an existing Applescript path you can send it like this

set p to POSIX path of  mypath
do shell script "qlmanage -pr " & quoted form of p
2
  • I tried qlmanage but it does not work as desired (see the second paragraph in my question)
    – e.James
    Feb 23, 2011 at 19:25
  • Doh. Missed that somehow. Then using GUI scripting is the way to go.
    – Clark
    Feb 23, 2011 at 20:54
5

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.

4
  • It might be better to do something like keystroke "Y" using command down instead. Feb 22, 2011 at 3:37
  • @Kevin Ballard: What does that do?
    – e.James
    Feb 22, 2011 at 4:11
  • 1
    It presses ⌘Y, which is the keyboard shortcut corresponding with the File->Quick Look menuitem. Of course, it might be even better to use Universal Access to invoke that menuitem directly instead of trying to type the shortcut. Feb 22, 2011 at 4:39
  • That's perfect. The "y" had to be lower case for it to work, but it works like a charm. Thank you!
    – e.James
    Feb 22, 2011 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.