Created
June 18, 2021 04:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)$FileDir$
Set "Arguments" to
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"