エイリアス・シンボリックリンクの参照元の取得 基本型
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | #com.cocolog-nifty.quicktimer.icefloe |
005 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
006 | use AppleScript version "2.8" |
007 | use framework "Foundation" |
008 | use framework "UniformTypeIdentifiers" |
009 | use framework "AppKit" |
010 | use scripting additions |
011 | property refMe : a reference to current application |
012 | |
013 | |
014 | #シンボリックリンク |
015 | set strFilePath to ("/Library/Fonts/Arial Unicode.ttf") as text |
016 | |
017 | #パスURL |
018 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
019 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
020 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
021 | |
022 | #エイリアスか?確認 |
023 | set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsAliasFileKey) |error| :(reference)) |
024 | set boolIs to (item 2 of listResponse) as boolean |
025 | if boolIs is true then |
026 | #シンボリックリンクか?確認 |
027 | set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsSymbolicLinkKey) |error| :(reference)) |
028 | set boolIs to (item 2 of listResponse) as boolean |
029 | if boolIs is true then |
030 | log "エイリアスではありません シンボリックリンクです" |
031 | set ocidResolvedURL to ocidFilePathURL's URLByResolvingSymlinksInPath() |
032 | if ocidResolvedURL = (missing value) then |
033 | display alert "参照先がすでに削除済みです" |
034 | else |
035 | set strResolvedPath to ocidResolvedURL's |path|() as text |
036 | end if |
037 | else |
038 | log "エイリアスです" |
039 | #URLByResolvingAliasFileAtURLで取得を試みる |
040 | (* |
041 | NSURLBookmarkResolutionOptions |
042 | NSURLBookmarkResolutionWithoutUI:8 |
043 | NSURLBookmarkResolutionWithoutMounting:9 |
044 | NSURLBookmarkResolutionWithSecurityScope:10 |
045 | NSURLBookmarkResolutionWithoutImplicitStartAccessing:15 |
046 | *) |
047 | set option to (42) as integer |
048 | set listResponse to refMe's NSURL's URLByResolvingAliasFileAtURL:(ocidFilePathURL) options:(option) |error| :(reference) |
049 | set ocidResolvedURL to (item 1 of listResponse) |
050 | #取得できなければ |
051 | if ocidResolvedURL = (missing value) then |
052 | #bookmarkData を使って取得を試みる |
053 | set listResponse to refMe's NSURL's bookmarkDataWithContentsOfURL:(ocidFilePathURL) |error| :(reference) |
054 | set ocdiBookMarkData to (item 1 of listResponse) |
055 | set listResponse to refMe's NSURL's URLByResolvingBookmarkData:(ocdiBookMarkData) options:(refMe's NSURLBookmarkResolutionWithoutUI) relativeToURL:(missing value) bookmarkDataIsStale:("isStale") |error| :(reference) |
056 | set ocidResolvedURL to (item 1 of listResponse) |
057 | display alert "参照先がすでに削除済みです" |
058 | else |
059 | set strResolvedPath to ocidResolvedURL's |path|() as text |
060 | end if |
061 | end if |
062 | else |
063 | return "エイリアスではありません" |
064 | end if |
065 | |
066 | |
067 | # |
AppleScriptで生成しました |
| 固定リンク