use framework "Foundation"
on createSymLinkInFolder:folderPath linkingTo:oldPath
-- make paths into NSStrings so we can manipulate them
set folderPathNSString to current application's NSString's stringWithString:folderPath
set oldPathNSString to current application's NSString's stringWithString:oldPath
-- add name of existing file to destination path
set newPath to folderPathNSString's stringByAppendingPathComponent:(oldPathNSString's lastPathComponent())
-- expand tildes
set newPath to newPath's stringByStandardizingPath()
set oldPath to oldPathNSString's stringByStandardizingPath()
-- make link
set theNSFileManager to current application's NSFileManager's defaultManager()
set {theResult, theError} to theNSFileManager's createSymbolicLinkAtPath:newPath withDestinationPath:oldPath |error|:(reference)
if not theResult as boolean then
error (theError's localizedDescription() as text)
end if
return theResult as boolean
end createSymLinkInFolder:linkingTo: