I’m all for using ASObjC when there is a clear advantage for doing so.
For example, when getting, searching, or sorting a long list of files, it has been shown that ASObjC is greatly faster.
But sometimes I wonder if there is a clear advantage.
Can anyone provide an objective comparison between using this simple, one-line Shell Script, vs a very complicated 24-line ASObjC script?
Is there any reason to use the longer, more complex ASObjC script?
The more lines of code, the more likelihood of a bug.
Objective: Create A Symlink from a Finder Selection and Put in A Selected Folder
These scripts deal only with creation of the symlink.
**EDIT: 2017-04-13 1:29 PM CT**
* @koenigyvan provided the solution
* Please see [my summary/conclusions at bottom of this thread](http://forum.latenightsw.com/t/asobjc-vs-shell-script/547/32?u=jmichaeltx).
###Shell Script Solution
do shell script "ln -s" & space & quoted form of itemPath & space & quoted form of trgPath
###ASObjC Solution
(my createSymlink:trgPath pointingTo:itemPath)
-- Creates a symbolic link
on createSymlink:aFileOrPath pointingTo:originalFileOrPath
set theLinkURL to my makeURLFromFileOrPath:aFileOrPath
set originalURL to my makeURLFromFileOrPath:originalFileOrPath
set theFileManager to current application's NSFileManager's |defaultManager|()
set {theResult, theError} to theFileManager's createSymbolicLinkAtURL:theLinkURL withDestinationURL:originalURL |error|:(reference)
if not (theResult as boolean) then error (theError's |localizedDescription|() as text)
end createSymlink:pointingTo:
on makeURLFromFileOrPath:theFileOrPathInput
-- make it into a Cocoa object for easier comparison
set theFileOrPath to item 1 of (current application's NSArray's arrayWithObject:theFileOrPathInput)
if (theFileOrPath's isKindOfClass:(current application's NSString)) as boolean then
if (theFileOrPath's hasPrefix:"/") as boolean then -- full POSIX path
return current application's class "NSURL"'s fileURLWithPath:theFileOrPath
else if (theFileOrPath's hasPrefix:"~") as boolean then -- POSIX path needing ~ expansion
return current application's class "NSURL"'s fileURLWithPath:(theFileOrPath's |stringByExpandingTildeInPath|())
else -- must be HFS path
return current application's class "NSURL"'s fileURLWithPath:(POSIX path of theFileOrPathInput)
end if
else if (theFileOrPath's isKindOfClass:(current application's class "NSURL")) as boolean then -- happens with files and aliases in 10.11
return theFileOrPath
else -- must be a file or alias
return current application's class "NSURL"'s fileURLWithPath:(POSIX path of theFileOrPathInput)
end if
end makeURLFromFileOrPath: