2

Similarly to running open "/Applications/Firefox.app", I would like to open the "Get Info" window of /Applications/Firefox.app using command line.

1
  • Can you explain your broader workflow? Why do you need to get info from a shell command? Do you need the actual data, or just the window?
    – benwiggy
    Commented Jan 8, 2021 at 12:34

1 Answer 1

6

I don't think you can do this with a shell command, but you can use a shell script to run AppleScript, which can do it. See here:

https://stackoverflow.com/questions/24421803/open-info-window-in-finder-by-applescript

https://stackoverflow.com/questions/37231942/open-get-information-window-in-finder-by-applescript-again

For example:

osascript -e "set aFile to (POSIX file \"/Applications/Firefox.app\") as text" \
          -e "tell application \"Finder\" to open information window of file aFile"

If you want to add in your bash or zsh profile:

getfileinfo() {
  local FILE="$1"

  if [[ -r "${FILE}" ]]; then
    osascript <<EOF
set aFile to (POSIX file "$FILE") as alias
tell application "Finder" to open information window of aFile
EOF
  fi
}
3
  • Brilliant indeed, so you can just add something like: osascript <<EOF set aFile to (POSIX file "$FILE") as alias tell application "Finder" to open information window of aFile EOF in your dotfiles
    – Rakib Fiha
    Commented Jan 8, 2021 at 13:31
  • 2
    @RakibFiha I've changed the condition in the if, -f is always false for applications.
    – nohillside
    Commented Jan 8, 2021 at 15:02
  • 2
    @RakibFiha -f basically tests for existance of a file, things like Firefox.app are always directories. Using -r works, as would -e.
    – nohillside
    Commented Jan 8, 2021 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .