2025-07-23 23:08:10 cda: Change directory into a Finder alias
At the command line it's not possible to cd into a folder which is a Finder alias. Only the Finder has the metadata to know what it is an alias of. But, you can ask the Finder for that location via AppleScript. Since this was an incantation that took me an hour of trial and error (and several LLMs were no help), I thought I'd jot it down for others:

( applescript )
  1 on run argv
2 tell application "Finder" to POSIX path of ((original item of (((POSIX file (item 1 of argv)) as text) as alias)) as text)
3 end run


You can wrap that into a command line script, calling it here aliasToPath, simply with:

( sh )
  1 #!/usr/bin/osascript
2
on run argv
3 tell application "Finder" to POSIX path of ((original item of (((POSIX file (item 1 of argv)) as text) as alias)) as text)
4 end run


then you can chmod +x aliasToPath and then use cd `aliasToPath someAliasPath` or, in fish, cd (aliasToPath someAliasPath), and be on your way.

For an extra convenience, you can create a function in bash, zsh, fish, etc, to make it one bit shorter. In fish, add this to your ~/.config/fish/config.fish file:

( fish )
  1 function cda --argument aliasdir
2 cd (aliasToPath $aliasdir)
3 end


and now you can simply type cda instead of cd whenever you bump into this situation.
Leave a comment