How Do I Determine if File is SymLink?

(Jim Underwood) #1

How Do I Determine if File is SymLink, or Alias, given its POSIX Path?

I have a solution for just Alias, and using Finder selection, but not with just a POSIX path.

this statement:

set itemAlias to (POSIX file kmFilePath) as alias

returns an AppleScript Alias for a alias file, but for a SymLInk file it returns the AS Alias for the target file/folder.

Any ideas?

0 Likes

(Shane Stanley) #2

Something like this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theURL to current application's NSURL's fileURLWithPath:kmFilePath
set {NSURLIsAliasFileKey:isAlias, NSURLIsSymbolicLinkKey:isSymLink} to (theURL's resourceValuesForKeys:{current application's NSURLIsSymbolicLinkKey, current application's NSURLIsAliasFileKey} |error|:(missing value)) as record
0 Likes