[AppleScript] リンク切れになった『エイリアス』『シンボリックリンク』を探す
【スクリプトエディタで開く】 |
エイリアスのリンク切れを探す.scpt.scpt | ソース |
|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 |
|
| 006 | エイリアス・シンボリックリンクの参照先を解決できない |
| 007 | 孤立してしまったファイルを探します。 |
| 008 | クラッシックなAs記法 |
| 009 |
|
| 010 | 判定に『エラー』を使っているので |
| 011 | あまり良い方法とは言えないけど |
| 012 | 判定の材料としては利用可能 |
| 013 |
|
| 014 |
|
| 015 |
|
| 016 | com.cocolog-nifty.quicktimer.icefloe *) |
| 017 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 018 | use AppleScript version "2.8" |
| 019 | use scripting additions |
| 020 |
|
| 021 | set dateNow to current date |
| 022 |
|
| 023 |
|
| 024 | set listBrokenLink to {} as list |
| 025 |
|
| 026 | tell application "SystemUIServer" |
| 027 | activate |
| 028 | set aliasChooleDirPath to (choose folder without multiple selections allowed) as alias |
| 029 | end tell |
| 030 |
|
| 031 |
|
| 032 | tell application "Finder" |
| 033 | set listAliasFilePath to (every alias file of (entire contents of aliasChooleDirPath)) as alias list |
| 034 | end tell |
| 035 |
|
| 036 | #Count alias list |
| 037 | set numCntList to (count of listAliasFilePath) as integer |
| 038 |
|
| 039 | #roop list |
| 040 | repeat with itemNo from 1 to (numCntList) by 1 |
| 041 | |
| 042 | #get alias path |
| 043 | try |
| 044 | set aliasItemFilePath to (item itemNo of listAliasFilePath) as alias |
| 045 | #Alias info |
| 046 | set recordInfoFor to (info for aliasItemFilePath) as record |
| 047 | #IS ALIAS |
| 048 | set boolIsAlias to (alias of recordInfoFor) as boolean |
| 049 | # |
| 050 | if boolIsAlias is true then |
| 051 | tell application "Finder" |
| 052 | tell file aliasItemFilePath |
| 053 | set recordFileProperties to (properties of aliasItemFilePath) as record |
| 054 | set refOrgFile to (original item of recordFileProperties) |
| 055 | end tell |
| 056 | end tell |
| 057 | #オリジナルが探せない場合 |
| 058 | #alias file Broken |
| 059 | if refOrgFile = (missing value) then |
| 060 | set end of listBrokenLink to (POSIX path of aliasItemFilePath) |
| 061 | end if |
| 062 | |
| 063 | #種類別のリストにしたい場合 |
| 064 | set strFileType to (file type of recordFileProperties) as text |
| 065 | #シンボリックリンクの場合 |
| 066 | if strFileType is "fdrp" then |
| 067 | --> Sym link or Hard Link |
| 068 | |
| 069 | #エイリアスの場合 |
| 070 | else if strFileType is "alis" then |
| 071 | -->Alias |
| 072 | end if |
| 073 | end if |
| 074 | |
| 075 | on error |
| 076 | #シンボリックリンクの場合、解決不能だとas aliasでエラーになるのを利用 |
| 077 | #In the case of symbolic links, if it cannot be solved, it will cause an error in as alias. |
| 078 | #Sym link Broken |
| 079 | set end of listBrokenLink to (POSIX path of (item itemNo of listAliasFilePath)) |
| 080 | end try |
| 081 | |
| 082 | end repeat |
| 083 |
|
| 084 |
|
| 085 | set dateDone to current date |
| 086 |
|
| 087 | log dateDone - dateNow |
| 088 | log (count of listBrokenLink) |
| 089 | return listBrokenLink |
| AppleScriptで生成しました |
|---|