Try this, basically just passes space hotkey to a selected file.
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?
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
Thank you very much.
It works very well!
Thank you for your help.
Mr. Carycrusiau's advice was easier for me.
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
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
@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:
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
Just another script:
activate application "Finder"
tell application "System Events"
key code 49
end tell
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.
Excellent!
You still might want to post your problem version, though -- especially if you are thinking of doing more "Execute Shell Script" actions. Moving paths cleanly between AS alias
es, KM text variables, and shell script arguments can be a bit of bear, never mind the whole "getting the shell's environment right" problem... But once you've cracked it you can usually apply the same methods to your future macros.