Skip to content

Instantly share code, notes, and snippets.

@juandesant
Last active December 18, 2025 21:11
Show Gist options
  • Select an option

  • Save juandesant/8c288d7ac7d8578b53799fadfe34dfa8 to your computer and use it in GitHub Desktop.

Select an option

Save juandesant/8c288d7ac7d8578b53799fadfe34dfa8 to your computer and use it in GitHub Desktop.
Bash or Zsh function that uses `osascript` para revelar multiples archivos en el Finder
reveal_files () {
num_files=0 # Number of already processed files
for file in $@ # Iterate over all entries after the `reveal_files` command.
do
# for each $file...
# does $file not start with "/"?
if [ ! "${file:0:1}" = "/" ]
then {
file="$(pwd)/$file"
# echo "Rebased file: $file"
} else { # Nothing to do if it does start with /
}
fi
# If this is not the first iteration ($num_files > 0)...
if [ $num_files -gt 0 ]
then {
# Check if the file starts with /
# ... add the new file ($file) after the existing list ($file_list)
# separated by a comma (",")
file_list="$file_list, \"$file\" as POSIX file"
} else { # But if this is the first iteration ($num_files == 0)...
# ... add the first file ($file) after the opening bracket ("{")
file_list="{ \"$file\" as POSIX file"
} # Note the usage of \" inside of quotes for literal quotes.
fi # continue with the next steps
# Increase the number of files processed
num_files=$(($num_files+1))
done
# Add the final closing bracket ("}")
file_list="$file_list }"
# Display number of processed files ($num_files) and the command ($file_list)
# echo "$num_files files: $file_list"
# Create the reveal command for `osascript`
reveal_command="tell application \"Finder\" to reveal $file_list"
# echo "Reveal AppleScript command:\\n$reveal_command"
# Run the reveal command; returns the AppleScript formatted list of files
osascript -e "$reveal_command"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment