Mac OS X의 명령 줄에서 파일에 대한 “정보 입수”실행 당신이 찾기에

당신이 찾기에 있었다 명중 경우처럼 어떻게 명령 줄에서 표시 할 수있는 “정보 입수”창을 얻을 것 CommandI? 나는 그것을 애플 스크립트로 쓸 수는 있지만 가능하다면 멀리 떨어져 있습니다.



답변

다음은 스크립트의 업데이트 된 버전입니다 (2 년 전에 찾은 원본 소스에 대한 속성 포함). 기능의 주요 변경 사항은 MacRoman과 UTF-8 (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


답변

또한 여러 파일을 지원하고 Finder를 활성화합니다. utxt 방법은 10.4 이하에서만 필요합니다.

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
}

osascript가 마지막 표현식의 결과를 인쇄하기 때문에 STDOUT이 경로 재 지정되고 10.8은 CFURLGetFSRef가이 URL을 전달한 것처럼 상대 경로를 별명으로 변환 할 때 스키마가없는 경고를 표시하므로 STDERR로 경로 재 지정됩니다.


답변

나는 당신의 질문에 진정으로 대답하지는 않지만, 내가 사용하는 데 필요한 정보 ls -lfile명령을 많이 얻었습니다 .


답변

이것을보십시오, 나는 이것을 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


답변

이 작업을 수행하기 위해 여러 스크립트를 시도했습니다 (예 : 명령 줄에서 정보 창을 표시).

그들은 모두 작동

별명 및 일반 파일의 경우 기본 링크의 파일 정보를 표시하는 기호 링크 (symlink)에 적합한 항목을 표시합니다. 이것은 파인더의 심볼릭 링크에서 “정보 얻기”를 선택하는 것이 아닙니다.

나는 이것을 해결하기 위해 애플 스크립트 코드를 가지고 놀고 있었지만 지금까지 운이 없다.

한 번에 여러 파일에 대한 정보를 얻는 것을 처리하는 간단한 스크립트를 작성했습니다.

#!/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


답변