Created
May 9, 2025 16:52
-
-
Save dzogrim/8a4c50e7a24dbe93ca57abc41f086fe1 to your computer and use it in GitHub Desktop.
Finds macOS Finder aliases in the current directory, resolves their targets using `resolve-alias`, and for valid folder targets offers to replace each alias with a Unix symlink
This file contains hidden or 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
#!/usr/bin/env bash | |
# This script finds macOS Finder aliases in the current directory, | |
# resolves their targets using `resolve-alias`, and for valid folder targets, | |
# offers to replace each alias with a Unix symlink to the original folder. | |
# Ensure resolve-alias is available | |
if ! command -v resolve-alias &> /dev/null; then | |
echo "β Error: 'resolve-alias' is not in your PATH." | |
echo "Please visit https://github.com/mattieb/resolve-alias and compile it first." | |
exit 1 | |
fi | |
# Known document bundles (used *after* resolving) | |
BUNDLES_EXTENSIONS="pages app rtfd key numbers" | |
is_bundle() { | |
for ext in $BUNDLES_EXTENSIONS; do | |
[[ "$1" == *.$ext ]] && return 0 | |
done | |
return 1 | |
} | |
# Process all alias files | |
find . -type f -exec file '{}' + | grep -i "Alias" | cut -d: -f1 | while read -r alias; do | |
echo "π Checking: $alias" | |
# Try to resolve alias | |
target=$(resolve-alias "$alias" 2>/dev/null) | |
# Empty or failed resolution | |
if [[ -z "$target" || ! -e "$target" ]]; then | |
echo "β Broken or unresolvable alias: $alias" | |
continue | |
fi | |
# Check for known bundle types (but only if valid) | |
if is_bundle "$alias"; then | |
echo "β οΈ Alias has bundle-like extension (.$(echo "$alias" | rev | cut -d. -f1 | rev)), but it's a real alias: $alias" | |
fi | |
# Valid folder alias | |
if [[ -d "$target" ]]; then | |
echo "π Folder alias β $alias" | |
echo " βͺ Target: $target" | |
if [[ -e "$alias" && ! -L "$alias" ]]; then | |
echo -n " β€ Convert this alias to a symlink? [y/N]: " > /dev/tty | |
read -r answer < /dev/tty | |
if [[ "$answer" =~ ^[Yy]$ ]]; then | |
rm -f "$alias" | |
ln -s "$target" "$alias" | |
echo "β Symlink created: $alias β $target" | |
else | |
echo "βοΈ Skipped." | |
fi | |
else | |
echo "β οΈ Skipping: $alias already a symlink or missing." | |
fi | |
elif [[ -f "$target" ]]; then | |
echo "π File alias β $alias" | |
echo " βͺ Target: $target" | |
else | |
echo "β Unknown target type: $alias β $target" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment