MacOS – Get Info of a hidden file (to change its default app)

command linemacos

I have a hidden file (.htaccess). When I double click it I would like it to open with a certain app (Sublime Text for this particular file type). In order to set the default app I have to open the "Get Info" window for that file (Cmd+I).

However, that file is hidden. So I can't right button click (two-finger tap) it to select the "Get Info" option from the context dropdown menu.

So the question is how do I open the "Get Info" window for a hidden file? The goal is to be able to change the default app for that file type.

p.s. I do not want to make my hidden files visible. Even temporarily.

Best Answer

You can use the following shell function. This uses open information window which is much better than GUI scripting or keyboard shortcut scripting which relies on the file shown in Finder.

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
}

Source: https://superuser.com/a/509080/

Run with

si /path/to/file