Saturday, 15 March 2014

osx - How to check if a file or folder is a symbolic link, using AppleScript -



osx - How to check if a file or folder is a symbolic link, using AppleScript -

i know how check if file/folder exists, wonder how can check if file/folder symbolic link applescript.

any help welcome. thanks.

if can provide input in form of posix-style paths (/ separator), here's handler uses do shell script , shell's -l file-test operator:

class="lang-applescript prettyprint-override">on issymlink(posixpath) seek shell script "[[ -l " & quoted form of posixpath & " ]]" homecoming true end seek homecoming false end issymlink # sample call. issymlink("/user guides , information") # -> true # if have hfs-style path (':' separator), prepend # `posix path of`. issymlink(posix path of "macintosh hd:user guides , information")

things note:

the handler homecoming false if specified file/folder doesn't exist @ all. applying alias hfs-style path string representing symlink results in instant resolution of symlink target; in other words: object returned represents symlink's target (original), not symlink itself; e.g.: class="lang-applescript prettyprint-override"> # returns reference *target*, # "macintosh hd:library:documentation:user guides , information.localized:" alias "macintosh hd:user guides , information" the same happens in system events context file / folder specifier: target returned: class="lang-applescript prettyprint-override"> tell application "system events" # returns reference *target* folder, # "macintosh hd:library:documentation:user guides , information.localized:" folder "macintosh hd:user guides , information" end tell to truly reference symlink - represented class alias file in applescript - utilize tell application "finder" , object specifier file, if symlink's target folder: class="lang-applescript prettyprint-override"> tell application "finder" file "macintosh hd:user guides , information" # -> alias file end tell also note it isn't symlinks represented alias file instances - finder's own alias files (created control-clicking item , selecting make alias) represented same way - utilize file type property distinguish them: true symlinks homecoming slnk (sic), whereas finder aliases homecoming alis (sic).

in lite of above: if still want handler limited utilize case of testing whether finder file [alias] object symlink:

class="lang-applescript prettyprint-override">on issymlinkfile(fileobj) seek homecoming "slnk" file type of fileobj end seek homecoming false end issymlinkfile # sample call. tell application "finder" set f file "macintosh hd:user guides , information" issymlinkfile(f) # -> true end tell

osx applescript symlink

No comments:

Post a Comment