How Do I Display a File using macOS Quick Look in a Popup Window?

Hello

Please kindly let me know how to make the macro for below.
I want to open(popup such as quicklook) specified file like a txt or jpg for instant reference.
I don't want to open with it by text editor or photo viewer, want to see it by quicklook.

Try this, basically just passes space hotkey to a selected file.

You can use Quick Look from the Command line with qlmanage:

More infos:

3 Likes

Thank you for your response.
I've tried it but I'm really beginner.
So I couldn't find how to designate a file.
I would appreciate if you could let me know how.

Thank you for your help.
It works but the dialog of "Shell Script Result" displayed after quicklook.
Can I stop this dialog come up?

Try this.

Simply select "ignore results" in the "Execute AppleScript" macro:

Edit: In fact, I meant in the "Execute Shell Script" and not in the "Execute AppleScript" but I think you understood :sweat_smile:

1 Like

Thank you very much.
It works very well!

Thank you for your help.
Mr. Carycrusiau's advice was easier for me.

1 Like

Why not just:

tell application "Finder"
	set pathFile to selection as text
	set pathFile to get POSIX path of pathFile
	do shell script "qlmanage -p \"" & pathFile & "\""
end tell

Looks much simpler

2 Likes

Hey @Ilya,

Good call.

Here it is in less simple form with more canonical AppleScript and basic error-checking.

-Chris

try
   
   tell application "Finder" to set finderSelectionList to selection as alias list
   
   if length of finderSelectionList ≠ 1 then
      error "Problem with number of files selected in Finder!"
   else
      
      set filePath to get POSIX path of item 1 of finderSelectionList
      set shCMD to "qlmanage -p  " & quoted form of filePath
      do shell script shCMD
      
   end if
   
on error e number n
   set e to e & return & return & "Num: " & n
   if n ≠ -128 then
      try
         tell application (path to frontmost application as text) to set ddButton to button returned of ¬
            (display dialog e with title "ERROR!" buttons {"Copy Error Message", "Cancel", "OK"} ¬
               default button "OK" giving up after 30)
         if ddButton = "Copy Error Message" then set the clipboard to e
      end try
   end if
end try
2 Likes

@llya and Chris @ccstone: Great script. Thanks for sharing.

Do you know how to make to display the same buttons in the header like the Finder does:

image

Hey JM,

I'm fairly sure you can't when using the qlmanage Unix executable.

See qlmanage -h and man qlmanage in the Terminal.

-Chris

Nice trick with "quoted form", thanks!
Updated my snippets

1 Like

Just another script:

activate application "Finder"

tell application "System Events"
	key code 49
end tell
1 Like

I'm trying to stick a long filepath that includes spaced text strings into "qlmanage -p" to make it do a quicklook preview of the document at the path. First, I get the filepath into a variable. In an AppleScript, I tell Finder to get POSIX path of the filepath in the variable and make a new variable with the POSIX path. I then tell Keyboard Maestro Engine to grab the "quoted form" of the POSIX path and put it in a KM variable for export back into KM. I then stick the KM variable with the quoted form of the POSIX path into the shell script, i.e., qlmanage -p %quickPath%. Throws error. What am I missing? Do I need to encode the filepath to deal with the spaces?

You can try it
qlmanage -p "%quickPath%"

Thank you. When I stick the %variable% in the Execute Shell Script action, it throws error "no job control" but when I write out qlmanage -p "/Path/To/File.txt", it works and shows me the preview. I can't get the shell script action to unpack the variable.

You really need to post your macro -- or at least the relevant actions. As the Tip says, showing more helps get the best answer.

You're absolutely right, apologies.

I finally solved the problem by using @ccstone's Applescript, above.

1 Like