指定フォルダ以下の指定形式の書類をすべてもとめてファイル名に重複がないかチェック

AppleScript名:指定フォルダ以下の指定形式の書類をすべてもとめてファイル名に重複がないかチェック
— Created 2017-10-28 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use mdLib : script "Metadata Lib" version "1.0.0"

set origFol to POSIX path of (choose folder)

set aResList to mdLib’s searchFolders:{origFol} searchString:("kMDItemContentTypeTree CONTAINS %@ || kMDItemContentTypeTree CONTAINS %@") searchArgs:{"net.daringfireball.markdown", "com.apple.iwork.pages.sffpages"}
if aResList = missing value or aResList = {} then
  return false
end if

set anArray to current application’s NSArray’s arrayWithArray:aResList
set aRes to anArray’s valueForKeyPath:"lastPathComponent"

set bLen to length of (aRes as list)

set b1Res to uniquify1DList(aRes as list, true) of me
set b1Len to length of b1Res

if bLen = b1Len then
  display dialog "No Duplicates"
else
  display dialog "Some Duplicates"
end if

on getSameItemsInLists(aList as list, bList as list)
  
  –ASオブジェクトをCocoaオブジェクトに変換
  
set aArray to current application’s NSArray’s arrayWithArray:aList
  
set bArray to current application’s NSArray’s arrayWithArray:bList
  
  — まとめる
  
set allSet to current application’s NSMutableSet’s setWithArray:aArray
  
allSet’s addObjectsFromArray:bArray
  
  –重複する要素のみ抜き出す
  
set duplicateSet to current application’s NSMutableSet’s setWithArray:aArray
  
duplicateSet’s intersectSet:(current application’s NSSet’s setWithArray:bArray)
  
  –重複部分だけを返す
  
set resArray to duplicateSet’s allObjects()
  
  set resList to resArray as list
  
  return resList
  
end getSameItemsInLists

–1D/2D Listをユニーク化
on uniquify1DList(theList as list, aBool as boolean)
  set aArray to current application’s NSArray’s arrayWithArray:theList
  
set bArray to aArray’s valueForKeyPath:"@distinctUnionOfObjects.self"
  
return bArray as list
end uniquify1DList

★Click Here to Open This Script 

Please follow and like us:

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です