Skip to content

Instantly share code, notes, and snippets.

@tiann
Created June 18, 2021 04:15
Show Gist options
  • Save tiann/dbb9f5850b16b3daa328947a15e307cd to your computer and use it in GitHub Desktop.
Save tiann/dbb9f5850b16b3daa328947a15e307cd to your computer and use it in GitHub Desktop.
Open selected file or directory in new Finder tab instead of window for macOS
#! /bin/bash
# Copyright (c) 2021, weishu
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Credits: https://apple.stackexchange.com/questions/349348/opening-a-new-finder-tab-from-command-line
function newtab() {
osascript <<EOF
tell application "Finder"
activate
set t to target of Finder window 1
set toolbar visible of window 1 to true
end tell
tell application "System Events"
keystroke "t" using command down
end tell
tell application "Finder"
set target of Finder window 1 to POSIX file "$1"
end tell
EOF
}
if [ $# -eq 0 ]
then
newtab `pwd`
else
for i in $*
do
newtab $(realpath $i)
done
fi
@tiann
Copy link
Author

tiann commented Jun 18, 2021

For Android Studio, Open Preferences -> Tools -> External Tools, and click Add

Set the "Program" to the path of this script (don't forget to chmod +x)
Set "Arguments" to $FileDir$
Set "Working directory" to /

And click OK.

Then you will see a context menu "External Tools" when you select a file, use this menu instead of builtin "Reveal in Finder"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment