Can I create a Desktop Shortcut/Alias to a Folder from the Terminal? I'd like to create a desktop shortcut to a specific folder, buried deep within ~/Library/. Library is Hidden by default in Lion, and I'd like to keep it that way, for a variety of reasons. Is there a one-step, command line action I can use, to create a desktop shortcut to a given path? I'd like to avoid solutions that involve unhiding the Library, creating the Alias using Finder, and rehiding it. I know how to do that, but for my purposes, a single line that can be pasted into Terminal and be done with it would be preferable.
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 &lt;&lt;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.