How to create a Mac OS X "Alias" kind file in Terminal?
Asked Answered
M

5

16

With the ln command , ln -s ~/dir dir. alias we can alias a file or folder.

Mac OS X also provides a way to create the "Alias Kind" file, by dragging one file while holding the command+option keys.

How can I create such a file in the Terminal?

Modie answered 15/2, 2012 at 16:10 Comment(1)
did you ever find out how to do this?Daradarach
P
10

While the files may look the same in the finder they are very different.

  • ln -s is creating a Unix symbolic link file
  • Finder's option copy is creating a Mac alias file.

To create an alias in a Unix shell one can use the osascript command and call it up like they would an Apple Script to do the same thing.

Plumcot answered 15/2, 2012 at 16:26 Comment(3)
That link seems dodgy now. Is the description available somewhere else?Tandi
@SamDutton - prosseek.blogspot.sg/2012/12/… is pretty much the same thingExtrusive
@SamDutton - this is also relevant, better info: apple.stackexchange.com/questions/2991/…Extrusive
C
2
osascript -e 'tell application "Finder"' -e '  set theTgt to POSIX file \"/Your/Alias/Target/Path/Goes/Here\" as alias' -e '  make new alias to theTgt at POSIX file "/The/Directory/Path/To/Your/New/Alias/Goes/Here"' -e '  set name of result to "YourNewAliasFileNameGoesHere"' -e 'end tell'"

This is a one-liner for the Terminal that'll create an alias at /The/Directory/Path/To/Your/New/Alias/Goes/Here/YourNewAliasFileNameGoesHere which points at /Your/Alias/Target/Path/Goes/Here. Note that if the alias path already exists (and would cause stomping) the command will error out instead of working. Also, the path you're trying to point at should exists too.

Crupper answered 20/9, 2022 at 23:27 Comment(1)
For a one-off, you can put the AppleScript code for this into Script Editor, which makes it a little easier to see what it's doing.Hellkite
A
0

I slightly modified @Dave's answer to make it work with an example

  1. There is a file ReadMe.txt on Desktop

  2. Trying to create ReamMeAlias file

  3. Just update home directory with your actual home directory name in the below command

  4. Run the command in Terminal

  5. Find ReadMeAlias on your Desktop

    osascript -e "tell application "Finder"" -e "set theTgt to POSIX file "/Users/home directory/Desktop/ReadMe.txt" as alias" -e "make new alias to theTgt at POSIX file "/Users/home directory/Desktop/"" -e "set name of result to "ReadMeAlias"" -e "end tell"

Anemometer answered 26/10, 2022 at 0:43 Comment(0)
M
0

This is the code that makes the alias h.txt in the desktop directory from the same directory's a.txt file.

#!/usr/bin/env osascript

set pathToB to ((path to home folder as text) & "Desktop:a.txt") as text

set pathToAliasLocation to ((path to home folder as text) & "Desktop") as text
set aliasName to "h2.txt"

-- Create the alias
tell application "Finder"
    set originalItem to alias pathToB
    make new alias at folder pathToAliasLocation to originalItem with properties {name:aliasName}
end tell
Manipulate answered 16/1 at 0:56 Comment(0)
L
-1

Try this app: symboliclinker, you can make a unix-like symbolic link (download here).

Install

  • install in /Library/Services or ~/Library/Services
  • double click it, and make sure click "ok" to enable app from github
  • make sure the service is enabled: open System Preferences-Keyboard-Shortcuts-Services, make sure the "Make Symbolic Link" service is checked.

Useage

  • right-click on the item you want to make into a symbolic link
  • Choose "Make Symbolic Link" from the "Services" contextual menu
Luculent answered 31/3, 2021 at 2:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.