Created
September 20, 2013 16:52
-
-
Save donatj/6640486 to your computer and use it in GitHub Desktop.
Displays the OS X Finder "Get Info" dialog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Requires a POSIX-ish shell. | |
# | |
# Originally From: http://hayne.net/MacDev/Bash/show_getinfo | |
# | |
# show_getinfo | |
# This script opens the Finder's "Get Info" window | |
# for the file or folder specified as a command-line argument. | |
# Cameron Hayne ([email protected]) March 2003 | |
# Chris Johnsen <[email protected]> August 2007, December 2009 | |
# Include Unicode path in AppleScript code via "utxt" block(s). | |
# Handle case where cwd ends in newline. | |
# Jesse Donat added the ability to loop over multiple files. | |
utf8_to_AppleScript_utxt() { | |
o="$(printf '\302\253')" # UTF-8 LEFT-POINTING DOUBLE ANGLE QUOTATION MARK | |
c="$(printf '\302\273')" # UTF-8 RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK | |
# AppleScript utxt: | |
# <http://lists.apple.com/archives/applescript-implementors/2007/Mar/msg00024.html> | |
# <<data utxtXXXX>> where | |
# << is actually U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK | |
# >> is actually U+00BB RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK | |
# XXXX are the hex digits of UTF-16 code units | |
# If a BOM is present, it specifies the byte order. | |
# The BOM code point will not be a part of the resulting string value. | |
# If no BOM is present, the byte order interpreted as native. | |
# The iconv invocation below *MUST* | |
# include a BOM | |
# or produce native byte ordering | |
# or include a BOM and produce native byte ordering. | |
# In my testing, iconv to UTF-16 includes a BOM and uses native ordering. | |
iconv -f UTF-8 -t UTF-16 | | |
( printf '("" as Unicode text' | |
hexdump -ve "\" & ${o}data utxt\" 63/2 \"%04x\" \"$c\"" | |
printf ')\n' ) | | |
sed -e 's/ *\('"$c"')\)$/\1/' | |
} | |
scriptname="${0##*/}" | |
if test "$#" -lt 1; then | |
printf "usage: %s file-or-folder\n" "$scriptname" | |
exit 1 | |
fi | |
for var in "$@" | |
do | |
echo "$var" | |
if ! test -e "$var"; then | |
printf "%s: No such file or directory: %s\n" "$scriptname" "$var" | |
continue | |
fi | |
if test "${var#/}" = "$var"; then var="$PWD/$var"; fi | |
var="$(printf %s "$var" | utf8_to_AppleScript_utxt)" | |
# 10.4 requires script text to be in the primary encoding (usually MacRoman) | |
# 10.5+ supports UTF-8, UTF-16 and the primary encoding | |
(iconv -f UTF-8 -t MACROMAN | osascript -) <<EOF | |
set macpath to POSIX file $var as alias | |
tell app "Finder" to open information window of macpath | |
EOF | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment