Get Info of a hidden file (to change its default app)
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.
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
"GetFileInfo" is not a separate app, but a process inside the Finder, therefore you cannot use open
on it. But you could use the following Applescript:
tell application "Finder" to activate
set thePath to POSIX file "/path/to/file"
tell application "Finder" to reveal thePath
delay 1
tell application "System Events" to keystroke "i" using command down
Now the problem is, that you can not select a file in the Finder that you can not see, making the whole script solution useless if you "do not want to make my hidden files visible. Even temporarily."
But: if you would specify what exactly you're looking for inside the "Get Info" window (e.g. change permissions, get metadata), chances are there's a command line solution for it that works right away.
EDIT:
To open .htaccess or similar dot-files with a specific editor you would have to re-define wich application is the handler for the text/plain
mime type or the public.plain-text
UTI (for more on the topic of UTIs, see this article for example).
This means that unfortunately .htaccess is viewed the same as .txt by the system and thus both will open with the same editor.
In any case, a comfortable tool to change default file handlers is the preference pane RCDefaultApp which is covered in a lot of questions here on stackexchange.
Unhide hidden files
The OP does not want to make hidden files visible, I'll keep my answer for the people who do
Use this oneliner to 'un-hide' all hidden files:
defaults write com.apple.finder AppleShowAllFiles TRUE; killall Finder
Now you can do a GetFileInfo the way you are used to. Commandi, or File -> Get Info
Hide the hidden files like this:
defaults write com.apple.finder AppleShowAllFiles FALSE; killall Finder
Edit: fixed the missing ;
sign which resulted in the "Unexpected argument killall; leaving defaults unchanged" error