Skip to content

Instantly share code, notes, and snippets.

@wisq
Created October 21, 2022 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wisq/d955fbe8e8002ad8cc9cfc4b47a2c8df to your computer and use it in GitHub Desktop.
Save wisq/d955fbe8e8002ad8cc9cfc4b47a2c8df to your computer and use it in GitHub Desktop.
MacOS "Quick Look" from the command line, with full editing capability, unlike `qlmanage -p`
on run argv
if (count of argv) = 1 then
set p to (item 1 of argv) as text
else
log "(development mode)"
set p to "/tmp/test.png"
end if
# Reveal the file in Finder.
# If QuickLook is already open, this will change it to the new file.
tell application "Finder"
reveal POSIX file p as text
activate
end tell
# Open QuickLook if needed.
# If already open, the menu item becomes "Close Quick Look", so we do nothing here.
tell application "System Events" to tell process "Finder"
try
click menu item "Quick Look" of menu 1 of menu bar item "File" of menu bar 1
on error number -1728
end try
end tell
return
end run
#!/bin/sh
error() {
echo "$1" 1>&2
exit 1
}
test "$#" -eq 1 || error "Usage: $0 <file>"
FILE="$1"
test -e "$FILE" || error "File not found: $FILE"
test -f "$FILE" || error "Not a regular file: $FILE"
exec osascript ~/bin/quicklook.scpt "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment