指定フォルダ以下の指定形式の書類をすべてもとめて拡張子をはずしたファ

AppleScript名:指定フォルダ以下の指定形式の書類をすべてもとめて拡張子をはずしたファイル名に重複がないかチェック v2
— 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" –https://www.macosxautomation.com/applescript/apps/Script_Libs.html#Metadata_Lib

set docUTIList to {"net.daringfireball.markdown", "com.apple.iwork.pages.sffpages"}
set origFol to (choose folder)
set dRes to detectDocNameDuplicateWithoutExt(origFol, docUTIList) of me
–> true / false

–origFolはaliasでもPOSIX pathでも可
on detectDocNameDuplicateWithoutExt(origFol, docTypeList as list)
  script spdMD
    property allResList : {}
  end script
  
  
set (allResList of spdMD) to {}
  
  
repeat with i in docTypeList
    set j to contents of i
    
set aResList to (mdLib’s searchFolders:{origFol} searchString:("kMDItemContentTypeTree CONTAINS %@") searchArgs:{j})
    
if aResList = missing value or aResList = {} then
      –Hitしなかった
    else
      set (allResList of spdMD) to (allResList of spdMD) & aResList
    end if
  end repeat
  
  
set aLen to length of contents of (allResList of spdMD)
  
if aLen = 0 then error "No match"
  
  
set anArray to current application’s NSArray’s arrayWithArray:(allResList of spdMD)
  
set aRes to anArray’s valueForKeyPath:"lastPathComponent.stringByDeletingPathExtension"
  
set b1Res to uniquify1DList(aRes as list, true) of me
  
set b1Len to length of b1Res
  
  
if aLen = b1Len then
    return true — No Duplicates
  else
    return false –Some duplicates
  end if
end detectDocNameDuplicateWithoutExt

–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:

コメントを残す

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