Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How would you get the "Get Info" window to appear from command line as you would if you were in Finder and hit Command-I? I could write it in applescript... but I stay away if I can.

share|improve this question

5 Answers 5

up vote 0 down vote accepted

Here is my updated version of the script (including attribution to the original source, as I found it a couple of years ago). The main change in functionality is that it will handle pathnames that include characters that are not encoded identically between MacRoman and UTF-8 (anything outside ASCII).

#!/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 (macdev@hayne.net)  March 2003

# Chris Johnsen <chris_johnsen@pobox.com> August 2007, December 2009
#   Include Unicode path in AppleScript code via "utxt" block(s).
#   Handle case where cwd ends in newline.

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

if ! test -e "$1"; then
    printf "%s: No such file or directory: %s\n" "$scriptname" "$1"
    exit 2
fi

if test "${1#/}" = "$1"; then set -- "$PWD/$1"; fi

set -- "$(printf %s "$1" | 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 $1 as alias
tell app "Finder" to open information window of macpath
EOF
share|improve this answer
    
I didn't get a chance to try it until now, but I'm getting this error which makes me laugh a little: ./getinfo.sh phBASE.sh execution error: Can’t make file ":⼀唀猀攀爀猀⼀洀眀漀漀搀猀⼀瀀栀䈀䄀匀䔀⸀猀栀" into type alias. (-1700) –  physicsmichael Dec 17 '09 at 16:41
    
If I take those characters, encode them as UTF-16LE, I get end up with the UTF-16BE encoding for “/Users/mwoods/phBASE.sh”. I had assumed that utxt was always big-endian, but I was wrong. I updated the script to use native byte order. –  Chris Johnsen Dec 18 '09 at 5:54
1  
I added another dump to /dev/null here: "...osascript - > /dev/null) <<EOF" since the output wasn't too useful and replaced it with a quick blurb. Great job on assembling/writing the codes that went into this answer. –  physicsmichael Dec 23 '09 at 18:20

I know that I am not truly answering your question, but I get alot of the info I need from using ls -l and the file command.

share|improve this answer

Try This out, I found this at http://forums.macosxhints.com/showthread.php?t=10149

#!/bin/sh

# This script opens the Finder's "Get Info" window
# for the file or folder specified as a command-line argument.

scriptname=`basename $0`
if [ $# -lt 1 ]; then
    echo "Usage: $scriptname file_or_folder"
    exit
fi

path=$1

if [ ! -e $path ]; then
    echo "$scriptname: $path: No such file or directory"
    exit
fi

case $path in
/*)     fullpath=$path ;;
~*)     fullpath=$path ;;
*)      fullpath=`pwd`/$path ;;
esac

if [ -d $fullpath ]; then
    file_or_folder="folder"
else
    file_or_folder="file"
fi

/usr/bin/osascript > /dev/null <<EOT
tell application "Finder"
    set macpath to POSIX file "$fullpath" as text
    open information window of $file_or_folder macpath
end tell
EOT
share|improve this answer
    
There is probably a bug in that code when it is used to reference a filename with a double quote in it. Also, when used on older systems before AppleScript 2.0 (in Leopard/10.5), it will probably break if a filename uses any characters outside the system's legacy encoding (usually MacRoman). –  Chris Johnsen Dec 11 '09 at 22:49

I tried several scripts to do this (i.e. pop an information window from the command line).

They all work

except

for aliases and regular files they show the right stuff for symbolic links (symlinks) the show the file information of the underlying file. this is NOT what selecting "Get Information" on a symlink in a finder shows.

I've been trying to play around with the applescript code to fix this, but no luck so far.

I did write a simple script to handle getting info for multiple files at once.

#!/bin/sh

# show_getinfo
# loop to use getinfo script copied from web on several files

if [ $# -lt 1 ]; then
    echo "Usage: `basename $0` file_or_folder"
    exit
fi

GETINFO_SCRIPT=$HOME/Dropbox/Unix/Scripts/getinfo2_quiet.sh

for F in $*
    do
    if ! test -e "$F"; then
        echo "`basename $0`: No such file or directory: $F"
        continue
    fi
    sh $GETINFO_SCRIPT "$F"
done
share|improve this answer

This also supports multiple files and make Finder active. The utxt method is only needed in 10.4 and earlier.

si() {
    osascript - "$@" <<-END > /dev/null 2>&1
    on run args
    tell app "Finder"
    activate
    repeat with f in args
    open information window of (posix file (contents of f) as alias)
    end
    end
    end
    END
}

STDOUT is redirected because osascript prints the result of the last expression and STDERR because 10.8 shows a warning like CFURLGetFSRef was passed this URL which has no scheme when a relative path is converted to an alias.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.