Apple - Can I create a Desktop Shortcut/Alias to a Folder from the Terminal?

It's possible to do it in one line of Terminal. Let's say you want to alias to the file "/Users/me/Library/Preferences/org.herf.Flux.plist".

osascript -e 'tell application "Finder"' -e 'make new alias to file (posix file "/Users/me/Library/Preferences/org.herf.Flux.plist") at desktop' -e 'end tell'

You should replace to file with to folder if you have a folder.

Here's a shell script that allows you pass in a file or folder path to create the alias:

#!/bin/bash

if [[ -f "$1" ]]; then
  type="file"
else
  if [[ -d "$1" ]]; then 
    type="folder"
  else
    echo "Invalid path or unsupported type"
    exit 1
  fi
fi

osascript <<END_SCRIPT
tell application "Finder"
   make new alias to $type (posix file "$1") at desktop
end tell
END_SCRIPT

If you name this script make-alias.sh, chmod u+x make-alias.sh and put it in /usr/local/bin, you can run e.g. make-alias.sh ~/Library/Preferences.


Try this on Terminal:

cd ~/Desktop
ln -s ~/Library/path/to/folder