Monday, December 18, 2017

#1 2017-09-29 10:46:14 pm

ddinisco
Member
Registered: 2008-04-05
Posts: 27

Quick look using a defined filepath

I am attempting to write a script to have the finder preview a file with a defined path using quick look. It is opening a random file, not the one I have set.

Thanks
David


tell application "Finder"
    activate
    set filepath to "Users/david/Desktop/myfilehere"
    tell application "System Events" to key code 49
end tell


Filed under: quick look

Offline

 

#2 2017-10-03 03:08:55 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 211

Re: Quick look using a defined filepath

Applescript:

set filepath to "Users/david/Desktop/myfilehere"

isn't  doing anything. You're setting a variable to a file path, then not doing anything with that variable.

The only thing your script does is bring Finder to the front, then press the [space] key.

I think this is what you're trying to do:

Applescript:

tell application "Finder"
   activate
   reveal alias "Macintosh HD:Users:david:Desktop:myfilehere"
end tell
delay 0.1
tell application "System Events" to key code 49

Although you can avoid revealing the file in the Finder and the clumsiness of using keycodes, and go to Spotlight Preview directly using  qlmanage in the shell. Here's a proof of concept script I wrote testing that functionality to check with users if they've selected the correct files to upload, that you could update, if you want to use it.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set file1 to "[put a POSIX file path here]"
set file2 to "[put another POSIX file path here]"
set filelist to {file1, file2}
set rightFiles to quicklook(filelist, false)

on quicklook(filelist, dialogText)
   if dialogText is false then set dialogText to "Are these the right files?"
   set shellFileString to ""
   repeat with aFile in filelist
       set shellFileString to shellFileString & "'" & aFile & "' "
   end repeat
   -- run script "do shell script \"qlmanage -p '" & file1 & "' '" & file2 & "' > /dev/null 2>&1 &\""
   do shell script "qlmanage -p " & shellFileString & " > /dev/null 2>&1 &"
   set isFrontmost to false
   repeat until isFrontmost is true
       delay 0.1
       tell application "System Events"
           tell process "qlmanage"
               activate
               set frontmost to true
               set isFrontmost to frontmost
           end tell
       end tell
   end repeat
   tell application "System Events"
       keystroke return using command down
       tell process "qlmanage"
           display dialog dialogText buttons {"No, try again", "Yes, proceed"} default button "Yes, proceed"
           if button returned of the result is "No, try again" then
               set rightFiles to false
           else
               set rightFiles to true
           end if
       end tell
   end tell
   set isFrontmost to false
   repeat until isFrontmost is true
       delay 0.1
       tell application "System Events"
           tell process "qlmanage"
               activate
               set frontmost to true
               set isFrontmost to frontmost
           end tell
       end tell
   end repeat
   tell application "System Events"
       keystroke "q" using command down
   end tell
   return rightFiles
end quicklook


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Online

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)