NSURLResourceKey

特定のディレクトリにあるファイルサイズ最大と最小


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
005use AppleScript version "2.8"
006use framework "Foundation"
007use framework "AppKit"
008use framework "UniformTypeIdentifiers"
009use scripting additions
010property refMe : a reference to current application
011
012set strTargetDirPath to ("~/Downloads") as text
013set ocidTargetDirPathStr to refMe's NSString's stringWithString:(strTargetDirPath)
014set ocidTargetDirPath to ocidTargetDirPathStr's stringByStandardizingPath()
015set ocidTargetDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidTargetDirPath) isDirectory:false)
016##############
017set appFileManager to refMe's NSFileManager's defaultManager()
018#非表示URLを除外するオプション
019set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
020#収集するリソースキー
021set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
022ocidKeyArray's addObject:(refMe's NSURLPathKey)
023ocidKeyArray's addObject:(refMe's NSURLFileSizeKey)
024#対象のディレクトリのコンテンツの収集
025set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidTargetDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error| :(reference))
026if (item 2 of listResponse) = (missing value) then
027  #収集したURLのArray
028  set ocidFilePathURLArray to (item 1 of listResponse)
029else if (item 2 of listResponse) ≠ (missing value) then
030  set strErrorNO to (item 2 of listResponse)'s code() as text
031  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
032  refMe's NSLog("■:" & strErrorNO & strErrorMes)
033  return "エラーしました" & strErrorNO & strErrorMes
034end if
035##############
036#ソートキー用のArray
037set ocidDescriptorsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
038#収取したのがNSURLなのでabsoluteString
039set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(no) selector:("localizedStandardCompare:")
040ocidDescriptorsArray's addObject:(ocidDescriptor)
041#ABC順にソート
042set ocidSortedURLArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorsArray)
043
044##############
045#リソースキー取得用のArray
046set ocidResourceArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
047#収集したNSURL順に処理
048repeat with itemSortedURLArray in ocidSortedURLArray
049  #リソースキーでDICTを取得
050  set listResponse to (itemSortedURLArray's resourceValuesForKeys:(ocidKeyArray) |error| :(reference))
051  set ocidResourceValues to (item 1 of listResponse)
052  #取得用のArrayに追加
053  (ocidResourceArray's addObject:(ocidResourceValues))
054end repeat
055
056##############
057#ソート用のArray
058set ocidDescriptorsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
059#ABC順
060set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:(refMe's NSURLLocalizedTypeDescriptionKey) ascending:(yes) selector:("localizedStandardCompare:")
061ocidDescriptorsArray's addObject:(ocidDescriptor)
062#ファイル修正日でソート
063set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:(refMe's NSURLFileSizeKey) ascending:(no)
064ocidDescriptorsArray's addObject:(ocidDescriptor)
065#ソート実行
066set ocidSortedResourceArray to ocidResourceArray's sortedArrayUsingDescriptors:(ocidDescriptorsArray)
067#ソートされた項目の個数
068set numCntArray to ocidSortedResourceArray's |count|()
069
070
071
072##一番サイズ大きいの新しいパス
073log ((ocidSortedResourceArray's firstObject())'s valueForKey:("_NSURLPathKey")) as text
074
075##一番サイズの小さいパス
076log ((ocidSortedResourceArray's lastObject())'s valueForKey:("_NSURLPathKey")) as text
077
AppleScriptで生成しました

|

特定のディレクトリにある修正日が一番古いパスと一番新しいパス


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
005use AppleScript version "2.8"
006use framework "Foundation"
007use framework "AppKit"
008use framework "UniformTypeIdentifiers"
009use scripting additions
010property refMe : a reference to current application
011
012#サンプルはダウンロードフォルダ
013set strTargetDirPath to ("~/Downloads") as text
014set ocidTargetDirPathStr to refMe's NSString's stringWithString:(strTargetDirPath)
015set ocidTargetDirPath to ocidTargetDirPathStr's stringByStandardizingPath()
016set ocidTargetDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidTargetDirPath) isDirectory:false)
017##############
018#URLの収集
019set appFileManager to refMe's NSFileManager's defaultManager()
020#非表示URLを除外するオプション
021set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
022#収集するリソースキー
023set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
024ocidKeyArray's addObject:(refMe's NSURLPathKey)
025ocidKeyArray's addObject:(refMe's NSURLContentModificationDateKey)
026#対象のディレクトリのコンテンツの収集 第一階層のみ
027set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidTargetDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error| :(reference))
028if (item 2 of listResponse) = (missing value) then
029  #収集したURLのArray
030  set ocidFilePathURLArray to (item 1 of listResponse)
031else if (item 2 of listResponse) ≠ (missing value) then
032  set strErrorNO to (item 2 of listResponse)'s code() as text
033  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
034  refMe's NSLog("■:" & strErrorNO & strErrorMes)
035  return "エラーしました" & strErrorNO & strErrorMes
036end if
037##############
038#ソートABC順
039#ソートキー用のArray
040set ocidDescriptorsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
041#収取したのがNSURLなのでabsoluteString
042set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(no) selector:("localizedStandardCompare:")
043ocidDescriptorsArray's addObject:(ocidDescriptor)
044#ABC順にソート
045set ocidSortedURLArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorsArray)
046
047##############
048#リソースキー取得用のArray
049set ocidResourceArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
050#収集したNSURL順に処理
051repeat with itemSortedURLArray in ocidSortedURLArray
052  #リソースキーでDICTを取得
053  set listResponse to (itemSortedURLArray's resourceValuesForKeys:(ocidKeyArray) |error| :(reference))
054  set ocidResourceValues to (item 1 of listResponse)
055  #取得用のArrayに追加
056  (ocidResourceArray's addObject:(ocidResourceValues))
057end repeat
058
059##############
060#ソート用のArray
061set ocidDescriptorsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
062#ABC順
063set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:(refMe's NSURLLocalizedTypeDescriptionKey) ascending:(yes) selector:("localizedStandardCompare:")
064ocidDescriptorsArray's addObject:(ocidDescriptor)
065#ファイル修正日でソート
066set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:(refMe's NSURLContentModificationDateKey) ascending:(no)
067ocidDescriptorsArray's addObject:(ocidDescriptor)
068#ソート実行
069set ocidSortedResourceArray to ocidResourceArray's sortedArrayUsingDescriptors:(ocidDescriptorsArray)
070#ソートされた項目の個数
071set numCntArray to ocidSortedResourceArray's |count|()
072
073
074##一番更新日の新しいパス
075log ((ocidSortedResourceArray's firstObject())'s valueForKey:("_NSURLPathKey")) as text
076
077##一番更新日の古いパス
078log ((ocidSortedResourceArray's lastObject())'s valueForKey:("_NSURLPathKey")) as text
079
080
081
082
083
AppleScriptで生成しました

|

[getResourceValue]各種情報の取得


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "UniformTypeIdentifiers"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015set appFileManager to refMe's NSFileManager's defaultManager()
016
017#############################
018###ダイアログを前面に出す
019set strName to (name of current application) as text
020if strName is "osascript" then
021  tell application "Finder" to activate
022else
023  tell current application to activate
024end if
025#デフォルトロケーション
026set appFileManager to refMe's NSFileManager's defaultManager()
027set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
028set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
029set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
030
031###ANY
032set listUTI to {"public.item"}
033set strMes to ("ファイルを選んでください") as text
034set strPrompt to ("ファイルを選んでください") as text
035try
036  set listFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with multiple selections allowed without invisibles and showing package contents) as list
037on error
038  log "エラーしました"
039  return "エラーしました"
040end try
041
042
043repeat with itemFilePath in listFilePath
044  set strFilePath to (POSIX path of itemFilePath) as text
045  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
046  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
047  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
048  (*
049  NSURLResourceKey
050  forKey ここで 取得するキーを指定します
051  https://developer.apple.com/documentation/foundation/nsurlresourcekey
052*)
053  
054  set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLPathKey) |error| :(reference))
055  if (item 3 of listResponse) = (missing value) then
056    set ocidResourceValue to (item 2 of listResponse)
057    log ocidResourceValue as text
058    (*
059ここで戻り値
060値のクラスによって text number integer 等色々
061*)
062    
063  else if (item 3 of listResponse) ≠ (missing value) then
064    set strErrorNO to (item 3 of listResponse)'s code() as text
065    set strErrorMes to (item 3 of listResponse)'s localizedDescription() as text
066    refMe's NSLog("■:" & strErrorNO & strErrorMes)
067    return "エラーしました" & strErrorNO & strErrorMes
068  end if
069  
070end repeat
AppleScriptで生成しました

|

[contentsOfDirectoryAtURL]コンテンツURLの収集 第一階層のみ


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005#
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011property refMe : a reference to current application
012
013
014##ダウンロードフォルダ
015set appFileManager to refMe's NSFileManager's defaultManager()
016set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
017set ocidDownloadsDirPathURL to ocidURLsArray's firstObject()
018##
019#不可視ファイル無視
020set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
021#収集キー
022set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
023ocidKeyArray's addObject:(refMe's NSURLPathKey)
024ocidKeyArray's addObject:(refMe's NSURLIsSymbolicLinkKey)
025ocidKeyArray's addObject:(refMe's NSURLIsDirectoryKey)
026ocidKeyArray's addObject:(refMe's NSURLContentTypeKey)
027#URLの収集
028set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidDownloadsDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error| :(reference))
029if (item 2 of listResponse) = (missing value) then
030  set ocidSubPathURLArray to (item 1 of listResponse)
031else if (item 2 of listResponse) ≠ (missing value) then
032  set strErrorNO to (item 2 of listResponse)'s code() as text
033  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
034  refMe's NSLog("■:" & strErrorNO & strErrorMes)
035  return "エラーしました" & strErrorNO & strErrorMes
036end if
037#必要があればソートしておく
038set ocidURLArraySorted to ocidSubPathURLArray's sortedArrayUsingSelector:("absoluteString")
039#収取したURLの数
040set numCntArray to ocidURLArraySorted's |count|()
041#収集したURLの数だけ繰り返し
042repeat with itemNo from 0 to (numCntArray - 1) by 1
043  #URL取り出し
044  set ocidItemURL to (ocidURLArraySorted's objectAtIndex:(itemNo))
045  #リソース取り出し
046  set listResponse to (ocidItemURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference))
047  if (item 3 of listResponse) = (missing value) then
048    set ocidUTType to (item 2 of listResponse)
049  else if (item 3 of listResponse) ≠ (missing value) then
050    set strErrorNO to (item 3 of listResponse)'s code() as text
051    set strErrorMes to (item 3 of listResponse)'s localizedDescription() as text
052    refMe's NSLog("■:" & strErrorNO & strErrorMes)
053    return "エラーしました" & strErrorNO & strErrorMes
054  end if
055  #UTI
056  set ocidUTI to ocidUTType's identifier()
057  log ocidItemURL's |path| as text
058  log ocidUTI as text
059  
060end repeat
061
062
AppleScriptで生成しました

|

NSURLCreationDateKey NSURLContentModificationDateKey ファイルの作成日と修正日のテキスト形式での取得


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005#com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "UniformTypeIdentifiers"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014set appFileManager to refMe's NSFileManager's defaultManager()
015
016
017################################
018#ダイアログ
019set strName to (name of current application) as text
020if strName is "osascript" then
021  tell application "Finder" to activate
022else
023  tell current application to activate
024end if
025
026set appFileManager to refMe's NSFileManager's defaultManager()
027set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
028set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
029set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
030#
031set listUTI to {"public.item"}
032set strMes to ("ファイルを選んでください") as text
033set strPrompt to ("ファイルを選んでください") as text
034try
035  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
036on error
037  log "エラーしました"
038  return "エラーしました"
039end try
040if listAliasFilePath is {} then
041  return "選んでください"
042end if
043################################
044#ファイルの数だけ繰り返し
045repeat with itemAliasFilePath in listAliasFilePath
046  ##########
047  #パス
048  set aliasFilePath to itemAliasFilePath as alias
049  set strFilePath to (POSIX path of aliasFilePath) as text
050  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
051  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
052  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
053  
054  ##########
055  #NSURLContentModificationDateKey
056  set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentModificationDateKey) |error| :(reference))
057  if (item 1 of listResponse) is true then
058    set ocidModificationDate to (item 2 of listResponse)
059    log ocidModificationDate as date
060  else if (item 1 of listResponse) is false then
061    set strErrorNO to (item 3 of listDone)'s code() as text
062    set strErrorMes to (item 3 of listDone)'s localizedDescription() as text
063    refMe's NSLog("■:" & strErrorNO & strErrorMes)
064    return "エラーしました" & strErrorNO & strErrorMes
065  end if
066  ##########
067  #NSURLCreationDateKey
068  set listResponse to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLCreationDateKey) |error| :(reference))
069  if (item 1 of listResponse) is true then
070    set ocidCreationDateDate to (item 2 of listResponse)
071    log ocidCreationDateDate as date
072  else if (item 1 of listResponse) is false then
073    set strErrorNO to (item 3 of listDone)'s code() as text
074    set strErrorMes to (item 3 of listDone)'s localizedDescription() as text
075    refMe's NSLog("■:" & strErrorNO & strErrorMes)
076    return "エラーしました" & strErrorNO & strErrorMes
077  end if
078  
079  ####################
080  #カレンダーの仕様を設定
081  set ocidCalendarID to (refMe's NSCalendarIdentifierGregorian)
082  set ocidCalendar to (refMe's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID))
083  set ocidTimezoneJP to (refMe's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo"))
084  set ocidLocaleJP to (refMe's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX"))
085  #カレンダー初期化
086  set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
087  (ocidFormatter's setCalendar:(ocidCalendar))
088  (ocidFormatter's setTimeZone:(ocidTimezoneJP))
089  (ocidFormatter's setLocale:(ocidLocaleJP))
090  (ocidFormatter's setDateStyle:(refMe's NSDateFormatterFullStyle))
091  (ocidFormatter's setDateFormat:("yyyyMMdd-hhmmss"))
092  
093  #NSURLContentModificationDateKey
094  set ocidCreationDateDateStr to (ocidFormatter's stringFromDate:(ocidCreationDateDate))
095  set strCreationDateDate to ocidCreationDateDateStr as text
096  log strCreationDateDate
097  
098  #NSURLContentModificationDateKey
099  set ocidModificationDateStr to (ocidFormatter's stringFromDate:(ocidModificationDate))
100  set strModificationDate to ocidModificationDateStr as text
101  log strModificationDate
102  
103  log (ocidCalendar's component:(refMe's NSCalendarUnitYear) fromDate:(ocidCreationDateDate))
104  
105  
106  return
107  
108end repeat
109
110
111
112
AppleScriptで生成しました

|

[NSURLTagNamesKey]選択したフォルダに内包しているファイル全てタグ削除 (修正)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# フォルダ内のコンテンツを収集して内包されている項目全部処理する
# NSURLTagNamesKeyに空のArrayをセットでも良かったが
# 後日特定のタグだけ削除とかに使いたいので個別で処理する方式にした
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application


##############################
### Wクリックで起動時
on run
  ###ドロップレットWクリック時にはファイル選択ダイアログを出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else if strName is (name of me as text) then
    set strName to (name of me) as text
    tell application strName to activate
  else
    tell current application to activate
  end if
  ###デフォルトロケーションはデスクトップ
  set appFileManager to refMe's NSFileManager's defaultManager()
  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
  set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
  set strMes to "選んでください"
  set listDropOpenPath to (choose folder strMes default location aliasDesktopDirPath with prompt strMes with multiple selections allowed and showing package contents without invisibles) as list
open listDropOpenPath
end run

##################################
###本処理
##################################
on open listDropOpenPath
  #ファイル ディレクトリの全てのパスの格納用
  set ocidFilePathURLArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
  #ドロップの数だけ繰り返し
  repeat with itemDropPath in listDropOpenPath
    ###ドップパス
    set appFileManager to refMe's NSFileManager's defaultManager()
    set strDropPath to (POSIX path of itemDropPath) as text
    set ocidDropPathStr to (refMe's NSString's stringWithString:(strDropPath))
    set ocidDropPath to ocidDropPathStr's stringByStandardizingPath()
    set ocidDropPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDropPath))
    ###ドロップされたのが?
    set listResults to (ocidDropPathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference))
    if (item 2 of listResults) = (refMe's NSNumber's numberWithBool:true) then
log "このURLはフォルダです"
      ##取得するプロパティ
      set ocidProperties to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
(ocidProperties's addObject:(refMe's NSURLPathKey))
      # (ocidProperties's addObject:(refMe's NSURLIsRegularFileKey))
      # (ocidProperties's addObject:(refMe's NSURLContentTypeKey))
      ##オプション(隠しファイルは含まない)
      set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles
      ##コンテンツの収集
      set ocidEmuDict to (appFileManager's enumeratorAtURL:(ocidDropPathURL) includingPropertiesForKeys:(ocidProperties) options:(ocidOption) errorHandler:(reference))
      set ocidFilePathURLArray to ocidEmuDict's allObjects()
      #フォルダ自身も追加しておく
(ocidFilePathURLArray's addObject:(itemDropPath))
    else
log "このURLはファイルです"
(ocidFilePathURLArray's addObject:(itemDropPath))
    end if
  end repeat
  
  ###不要なんだが念のためパスをURL順に並び替え
  set ocidSortDescriptor to (refMe's NSSortDescriptor's sortDescriptorWithKey:"absoluteString" ascending:(true) selector:"localizedStandardCompare:")
(ocidFilePathURLArray's sortUsingDescriptors:{ocidSortDescriptor})
  
  repeat with itemFilePathURL in ocidFilePathURLArray
    ##設定されているタグの名前を取得して
    set listResult to (itemFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLTagNamesKey) |error|:(reference))
    set ocidTagArray to (item 2 of listResult)
    if ocidTagArray = (missing value) then
log "タグは設定されていません"
    else
      #取得したタグの数だけくりかえし
      repeat with itemTag in ocidTagArray
        #タグを削除して
(ocidTagArray's removeObject:(itemTag))
      end repeat
      #削除したタグArrayを戻す
      set listDone to (itemFilePathURL's setResourceValue:(ocidTagArray) forKey:(refMe's NSURLTagNamesKey) |error|:(reference))
      if (item 1 of listDone) = true then
log "タグを削除しました"
      else
log itemFilePathURL's |path| as text
log "タグの削除に失敗しました"
      end if
    end if
  end repeat
  
end open

|

フォルダ名(localized表示)を取得する


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()


set strFilePath to "~/Applications" as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set ocidLocalizedPath to ocidFilePath's stringByAppendingPathComponent:(".localized")
###フォルダなければ作る
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolDone to appFileManager's createDirectoryAtURL:(ocidFilePathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
###localizedの空ファイルも作る
set listBoolDone to appFileManager's createFileAtPath:(ocidLocalizedPath) |contents|:(missing value) attributes:(ocidAttrDict)
###ローカライズ名があれば取得する
set listAttributesDict to ocidFilePathURL's resourceValuesForKeys:({refMe's NSURLLocalizedNameKey}) |error|:(reference)
set ocidAttributesDict to (item 1 of listAttributesDict)
set ocidLocalizedName to (ocidAttributesDict's objectForKey:(refMe's NSURLLocalizedNameKey))
log ocidLocalizedName as text
--->(*アプリケーション*)




|

[NSURLResourceKey]|error|:(reference)

#!/usr/bin/env osascript

----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

#

#

#

#

#                       com.cocolog-nifty.quicktimer.icefloe

----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

##自分環境がos12なので2.8にしているだけです

use AppleScript version "2.8"

use framework "Foundation"

use scripting additions


property refMe : a reference to current application

property refNSString : a reference to refMe's NSString

property refNSURL : a reference to refMe's NSURL

property refNSNotFound : a reference to 9.22337203685477E+18 + 5807


set strDirPath to "/Users/Shared"

set ocidNSString to refNSString's stringWithString:strDirPath

set ocidURLPath to refNSURL's fileURLWithPath:ocidNSString



#####不可視ファイルの場合

### |error|:(missing value

set ocidResponseArray to (ocidURLPath's getResourceValue:(reference) forKey:(refMe's NSURLIsHiddenKey) |error|:(missing value))

log ocidResponseArray as list

(*true, «class ocid» id «data optr00000000D0460CEF01000000»*)

-->2つの値があります

set boolResponseDone to item 1 of ocidResponseArray

set boolIsHiddenKey to item 2 of ocidResponseArray


###  |error|:(reference))

set ocidResponseArray to (ocidURLPath's getResourceValue:(reference) forKey:(refMe's NSURLIsHiddenKey) |error|:(reference))

log ocidResponseArray as list

(*true, «class ocid» id «data optr00000000D0460CEF01000000», missing value*)

set boolHiddenKey to (item 2 of ocidResponseArray) as boolean

-->3つの値があります


set boolResponseDone to item 1 of ocidResponseArray

set boolIsHiddenKey to item 2 of ocidResponseArray

set ocidNSError to item 3 of ocidResponseArray



|

[NSURLIsUbiquitousItemKey]iCloudのURLか?

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL


#############################################

###デスクトップ
set strFilePath to "~/Library/Mobile Documents/" as text

###NSStringにして
set ocidPosixPath to refNSString's stringWithString:strFilePath
##NSStringフルパスにして
set strBaseFilePath to ocidPosixPath's stringByStandardizingPath
log strBaseFilePath as text
(*/Users/ユーザー名/Library/Mobile Documents/*)
log className() of strBaseFilePath as text
(*NSPathStore2*)
set ocidFilePathURL to refNSURL's alloc()'s initFileURLWithPath:strBaseFilePath
log ocidFilePathURL's |path|() as text
(*/Users/ユーザー名/Library/Mobile Documents/*)
log ocidFilePathURL's absoluteString() as text
(*file:///Users/ユーザー名/Library/Mobile%20Documents/*)
log ocidFilePathURL as text
(*Macintosh HD:Users:ユーザー名:Library:Mobile Documents:*)
log className() of ocidFilePathURL as text
(*NSURL*)




#############################################
####そのURLNSURLIsUbiquitousItemKeyは何ですか?
set ocidResultArray to ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsUbiquitousItemKey) |error|:(missing value)
set boolGetResourceResult to item 1 of ocidResultArray
set ocidResultValue to item 2 of ocidResultArray
###getResourceが成功したか?
log boolGetResourceResult as boolean
###Value->結果
log ocidResultValue as text
(*1*)
(*
1:icloudURL
(missing value):それ以外
*)
log className() of ocidResultValue as text
(*__NSCFNumber*)

|

[NSURLVolumeURLKey]URLのボリューム名

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL



#############################################
###デスクトップ
set strFilePath to "/" as text
###NSStringにして
set ocidPosixPath to refNSString's stringWithString:strFilePath
###NSURL
set ocidFilePathURL to refNSURL's alloc()'s initFileURLWithPath:ocidPosixPath
log className() of ocidFilePathURL as text
(*NSURL*)


#############################################
####そのURLNSURLVolumeURLKeyは何ですか?
set ocidResultArray to ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLVolumeURLKey) |error|:(missing value)
set boolGetResourceResult to item 1 of ocidResultArray
set ocidResultValue to item 2 of ocidResultArray
###getResourceが成功したか?
log boolGetResourceResult as boolean
###Value->結果
log ocidResultValue as text
(*Macintosh HD:*)
log className() of ocidResultValue as text
(*NSURL*)

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom