有没有办法用Applescript触发Finder的"快速浏览"窗口?

e.J*_*mes 4 macos applescript quicklook

我正在使用Applescript自动执行OSX Finder中的某些任务.该脚本打开一个文件夹并选择该文件夹中的第一个图像.我希望它也能打开"快速查看"窗口(就像用户按下空格键一样).

我确实找到了一种方法,可以使用qlmanage从命令行启动快速查看,但这会打开一个静态快速查看窗口,它不再与查找程序选择相关联.

代码到目前为止:

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
Run Code Online (Sandbox Code Playgroud)

Cla*_*ark 11

如果您不想通过编写Finder脚本来执行此操作,则可以运行以下shell命令

qlmanage -p thefile
Run Code Online (Sandbox Code Playgroud)

在Applescript中你可能会这样做

do shell script "qlmanage -p " & "thepath/thefile"
Run Code Online (Sandbox Code Playgroud)

根据您的工作情况,这可能会更容易.特别是如果你主要只有一组路径.

如果您有一个现有的Applescript路径,您可以像这样发送它

set p to POSIX path of  mypath
do shell script "qlmanage -pr " & quoted form of p
Run Code Online (Sandbox Code Playgroud)


e.J*_*mes 5

更新(感谢 Kevin Ballard):

tell application "System Events" to keystroke "y" using command down
Run Code Online (Sandbox Code Playgroud)

注意:这要求在"Universal Access"控制面板中选择"启用辅助设备访问".