Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 258
e.James Avatar asked Feb 22 '11 03:02

e.James


People also ask

Does Apple still use AppleScript?

AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system automation tools.

What is tell in AppleScript?

Description. The tell compound statement identifies the target of an AppleScript command or Apple event (as in tell app "Photoshop 5.5" ) followed by other AppleScript statements and an end tell .


1 Answers

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
like image 116
Clark Avatar answered Oct 21 '22 21:10

Clark