Create Symlink using ASObjC


(Jim Underwood) #1

@ccstone and @ShaneStanley:

Chris, you published this great tool for creating aliases in the current Finder target folder. Is there an equivalent for Symlinks?

# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2015/08/07 20:00
# dMod: 2017/03/21 17:02
# Appl: Finder
# Task: Paste Aliases of files copied to the clipboard in front Finder window.

# Creates an alias file at the provided path
on createAlias:aFileOrPath pointingTo:originalFileOrPath
  set theAliasURL to my makeURLFromFileOrPath:aFileOrPath
  set originalURL to my makeURLFromFileOrPath:originalFileOrPath
  set {theData, theError} to originalURL's bookmarkDataWithOptions:(current application's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:(missing value) relativeToURL:(missing value) |error|:(reference)
  if theData is missing value then error (theError's |localizedDescription|() as text)
  set {theResult, theError} to current application's class "NSURL"'s writeBookmarkData:theData toURL:theAliasURL options:0 |error|:(reference)
  if not (theResult as boolean) then error (theError's |localizedDescription|() as text)
end createAlias:pointingTo:


(Shane Stanley) #2

If you go here:

and download FileManagerLib, it contains the code you want.

(Jim Underwood) #3

Thanks, Shane for another great lib.

(Jim Underwood) #4

Here is an alternate, perhaps better, solution.
It is much more compact, simpler, and easier to use.