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?
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?
While the files may look the same in the finder they are very different.
ln -s
is creating a Unix symbolic link fileTo 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.
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.
I slightly modified @Dave's answer to make it work with an example
There is a file ReadMe.txt on Desktop
Trying to create ReamMeAlias file
Just update home directory with your actual home directory name in the below command
Run the command in Terminal
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"
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
Try this app: symboliclinker, you can make a unix-like symbolic link (download here).
Install
/Library/Services
or ~/Library/Services
Useage
© 2022 - 2024 — McMap. All rights reserved.