AppleScript Attributes

com.apple.TextEncodingの値を再設定する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# /usr/bin/xattr  -p com.apple.TextEncoding /some/text/file.txt
004(*
005Non-lossy ASCII ;3071
006macintosh;0
007x-mac-japanese;1
008cp932;1056
009Shift_JIS;1576
010shift_jis;2561
011iso-2022-jp;2080
012iso-2022-jp-2;2081
013iso-2022-jp-1;2082
014euc-jp;2336
015windows-1252;1280
016windows-1250;1281
017cp852;1042
018
019us-ascii;1536
020utf-7;67109120
021utf-8;134217984
022utf-16;256
023utf-16be;268435712
024utf-16le;335544576
025utf-32;201326848
026utf-32be;402653440
027utf-32le;469762304
028
029iso-8859-10;522
030
031big5-hkscs;2566
032x-mac-trad-chinese;2
033x-mac-korean;3
034x-mac-simp-chinese;25
035gb18030;1586
036*)
037# ファイルの属性(アトリビュート)のテキストエンコードと
038# 実際のファイルのテキストエンコードが不一致になった時用
039# com.cocolog-nifty.quicktimer.icefloe
040----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
041use AppleScript version "2.6"
042use framework "Foundation"
043use framework "AppKit"
044use scripting additions
045
046property refMe : a reference to current application
047property listUTI : {"public.text"} as list
048
049#################################
050#【1】クリックでオープンした場合
051on run
052  #ダイアログ を前面に
053  set strName to (name of current application) as text
054  if strName is "osascript" then
055    tell application "Finder" to activate
056  else
057    tell current application to activate
058  end if
059  #デフォルトパス
060  set appFileManager to refMe's NSFileManager's defaultManager()
061  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
062  set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
063  set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
064  set strMes to ("ファイルを選んでください") as text
065  set strPrompt to ("ファイルを選んでください") as text
066  try
067    #ダイアログ
068    set listChooseAliasFilePath 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
069  on error
070    log "エラーしました"
071    return "エラーしました"
072  end try
073  #ファイルリストを次の処理に渡す
074  set boolDone to doPathSender(listChooseAliasFilePath)
075  #戻り値チェック
076  if boolDone is false then
077    display alert "エラーが発生しました" message "エラーが発生しました"
078    return "エラー終了run"
079  else
080    return "処理終了run"
081  end if
082end run
083
084#################################
085#【2】ドロップした場合
086on open listDropAliasFilePath
087  #########【2−1】UTIチェック
088  #サブルーチンに渡すリスト
089  set listAliasFilePath to {} as list
090  #ドロップされたアイテムの数だけ繰り返す
091  repeat with itemDropAliasFilePath in listDropAliasFilePath
092    #エイリアス
093    set aliasItemFilePath to itemDropAliasFilePath as alias
094    tell application "Finder"
095      #Finder情報を取得して
096      set recordInfoFor to info for aliasItemFilePath
097    end tell
098    #UTIを取得
099    set strItemUIT to (type identifier of recordInfoFor) as text
100    #UTIが対象ファイルならリストに追加
101    repeat with itemUTI in listUTI
102      if strItemUIT is itemUTI then
103        copy aliasItemFilePath to end of listAliasFilePath
104      end if
105    end repeat
106  end repeat
107  #########【2−1】KINDチェック
108  set listSendAliasFilePath to {} as list
109  repeat with itemAliasFilePath in listAliasFilePath
110    #処理する判定
111    set boolChkAliasPath to true as boolean
112    try
113      tell application "Finder"
114        set strKind to (kind of itemDropObject) as text
115      end tell
116      if strKind is "アプリケーション" then
117        log "アプリケーションは処理しない"
118        set boolChkAliasPath to false as boolean
119      else if strKind is "ボリューム" then
120        log "ボリュームは処理しない"
121        set boolChkAliasPath to false as boolean
122      else if strKind is "エイリアス" then
123        log "エイリアスは処理しない"
124        set boolChkAliasPath to false as boolean
125      else if strKind is "フォルダ" then
126        log "フォルダは処理しない"
127        set boolChkAliasPath to false as boolean
128      end if
129    on error
130      log "シンボリックリンク等kindを取得できないファイルは処理しない"
131      set boolChkAliasPath to false as boolean
132    end try
133    if boolChkAliasPath is true then
134      copy itemAliasFilePath to end of listSendAliasFilePath
135    end if
136  end repeat
137  #########【2−3】次工程に渡す
138  set boolDone to doPathSender(listSendAliasFilePath)
139  if boolDone is not true then
140    return false
141  else
142    return "処理終了open"
143  end if
144end open
145
146#################################
147#【3】1と2からファイルパスのエイリアスを受け取り
148#処理に順番に渡す
149to doPathSender(argListAliasFilePath)
150  set appFileManager to refMe's NSFileManager's defaultManager()
151  #1回でいい処理はここに記述する
152  set recordTextEnc to {|日本語(Mac OS Roman)|:"macintosh;0", |日本語(Mac OS)|:"x-mac-japanese;1", |日本語(Windows, DOS)|:"cp932;1056", |日本語(Shift JIS X0213)|:"Shift_JIS;1576", |日本語(Shift JIS)|:"shift_jis;2561", |日本語(ISO 2022-JP)|:"iso-2022-jp;2080", |日本語(ISO 2022-JP-2)|:"iso-2022-jp-2;2081", |日本語(ISO 2022-JP-1)|:"iso-2022-jp-1;2082", |日本語(EUC)|:"euc-jp;2336", |Unicode (UTF-8)|:"utf-8;134217984", |Unicode (UTF-16)|:"utf-16;256", |Unicode (UTF-16BE)|:"utf-16be;268435712", |Unicode (UTF-16LE)|:"utf-16le;335544576", |Unicode (UTF-32)|:"utf-32;201326848", |Unicode (UTF-32BE)|:"utf-32be;402653440", |Unicode (UTF-32LE)|:"utf-32le;469762304"} as record
153  #DICTにしておく
154  set ocidTextEncDictJp to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
155  ocidTextEncDictJp's setDictionary:(recordTextEnc)
156  set ocidAllKeys to ocidTextEncDictJp's allKeys()
157  #ソート
158  set ocidSortedArray to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
159  #ダイアログ用のリスト
160  set listAllKeys to ocidSortedArray as list
161  #ダイアログ
162  tell current application
163    set strName to name as text
164  end tell
165  if strName is "osascript" then
166    tell application "Finder" to activate
167  else
168    tell current application to activate
169  end if
170  try
171    set listResponse to (choose from list listAllKeys with title "選んでください" with prompt "選んでください" default items (item 1 of listAllKeys) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
172  on error
173    log "エラーしました"
174    return "エラーしました"
175  end try
176  if (item 1 of listResponse) is false then
177    return "キャンセルしました"
178  end if
179  ###ダイアログの戻り値
180  set strComplianceName to (item 1 of listResponse) as text
181  #
182  set strErrorCode to (ocidTextEncDictJp's valueForKey:(strComplianceName)) as text
183  
184  ####1ファイルパス毎本処理に渡す
185  repeat with itemAliasFilePath in argListAliasFilePath
186    set aliasFilePath to itemAliasFilePath as alias
187    set strItemFilePath to (POSIX path of aliasFilePath) as text
188    ##まずは今設定されている属性を削除して
189    set strCommandText to ("/bin/zsh -c '/usr/bin/xattr -d \"com.apple.TextEncoding\" \"" & strItemFilePath & "\"'") as text
190    log strCommandText
191    try
192      do shell script strCommandText
193    end try
194    ##再設定する
195    set strCommandText to ("/bin/zsh -c '/usr/bin/xattr -w \"com.apple.TextEncoding\"  \"" & strErrorCode & "\" \"" & strItemFilePath & "\"'") as text
196    log strCommandText
197    #本処理に渡す
198    set boolDone to doAction(strCommandText)
199    #戻り値がエラーだったら?
200    if boolDone is false then
201      tell application "Finder"
202        set strFileName to (name of itemAliasFilePath) as text
203      end tell
204      set strMes to (strFileName & "でエラーになりました") as text
205      display alert "エラーが発生しました" message strMes
206      return strMes
207      #エラーになったところで止める
208    end if
209  end repeat
210  return true
211end doPathSender
212
213#################################
214#【4】実際の処理は全てここ
215to doAction(argCommandText)
216  ###
217  try
218    do shell script argCommandText
219  on error
220    #エラーになったらfalseを戻す
221    return false
222  end try
223  
224  return true
225end doAction
AppleScriptで生成しました

|

[xattr]コマンドラインからFinerラベルを設定する

Screen-20231025-110644

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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
STR_DIR_PATH="$HOME/Desktop/レッド フォルダ/"
/bin/mkdir -p "$STR_DIR_PATH"

PLIST_RED="<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>レッド</string></array></plist>"

### -w 属性を登録する
/usr/bin/xattr -w com.apple.metadata:_kMDItemUserTags "$PLIST_RED" "$STR_DIR_PATH"
#################################################
STR_DIR_PATH="$HOME/Desktop/ブルー フォルダ/"
/bin/mkdir -p "$STR_DIR_PATH"

PLIST_RED="<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>ブルー</string></array></plist>"

### -w 属性を登録する
/usr/bin/xattr -w com.apple.metadata:_kMDItemUserTags "$PLIST_RED" "$STR_DIR_PATH"

#################################################
STR_DIR_PATH="$HOME/Desktop/ブルー・レッド フォルダ/"
/bin/mkdir -p "$STR_DIR_PATH"

PLIST_RED="<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>レッド</string><string>ブルー</string></array></plist>"

### -w 属性を登録する
/usr/bin/xattr -w com.apple.metadata:_kMDItemUserTags "$PLIST_RED" "$STR_DIR_PATH"

#################################################
STR_DIR_PATH="$HOME/Desktop/レッド・ブルー フォルダ/"
/bin/mkdir -p "$STR_DIR_PATH"

PLIST_RED="<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>ブルー</string><string>レッド</string></array></plist>"

### -w 属性を登録する
/usr/bin/xattr -w com.apple.metadata:_kMDItemUserTags "$PLIST_RED" "$STR_DIR_PATH"


#################################################
STR_DIR_PATH="$HOME/Desktop/ラベル色無し フォルダ/"
/bin/mkdir -p "$STR_DIR_PATH"

PLIST_RED="<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>ラベル色無し</string></array></plist>"

### -w 属性を登録する
/usr/bin/xattr -w com.apple.metadata:_kMDItemUserTags "$PLIST_RED" "$STR_DIR_PATH"

exit 0


|

[xattr]xattr基本のおさらい


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
STR_FILE_PATH="$HOME/Desktop/test.txt"
/usr/bin/touch "$STR_FILE_PATH"

STR_DIR_PATH="$HOME/Desktop/test/"
/bin/mkdir -p "$STR_DIR_PATH"

#################################################
PLIST_RED="<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>tag1</string><string>レッド</string></array></plist>"

#################################################
### xattr 基本のおさらい
### -x 現在の属性名を表示 作成したばかりなので戻り値はないが
/usr/bin/xattr -x "$STR_FILE_PATH"
/usr/bin/xattr -x "$STR_DIR_PATH"

### -w 属性を登録する ラベルの赤を付与する
/usr/bin/xattr -w com.apple.metadata:_kMDItemUserTags "$PLIST_RED" "$STR_DIR_PATH"
/usr/bin/xattr -w com.apple.metadata:_kMDItemUserTags "$PLIST_RED" "$STR_FILE_PATH"

### -x 現在の属性名を表示 com.apple.metadata:_kMDItemUserTagsが戻り値で入る(タグが設定されているって意味)
/usr/bin/xattr -x "$STR_FILE_PATH"
/usr/bin/xattr -x "$STR_DIR_PATH"

### -p 指定した属性名の内容を表示 タグの内容であるPLISTが表示される
/usr/bin/xattr -p com.apple.metadata:_kMDItemUserTags "$STR_FILE_PATH"
/usr/bin/xattr -p com.apple.metadata:_kMDItemUserTags "$STR_DIR_PATH"

### -d 登録されている属性名を指定して削除クリアする
/usr/bin/xattr -d com.apple.metadata:_kMDItemUserTags "$STR_FILE_PATH"
/usr/bin/xattr -d com.apple.metadata:_kMDItemUserTags "$STR_DIR_PATH"

###-c 登録されている属性を削除クリアする
/usr/bin/xattr -c "$STR_FILE_PATH"
/usr/bin/xattr -c -r "$STR_DIR_PATH"



exit 0


|

[NSFilePosixPermissions]パーミッション変更10進数

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

#!/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 scripting additions


property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()



####ダイアログで使うデフォルトロケーション
tell application "Finder"
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell

###ANy
set listUTI to {"public.item"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

set strFilePath to POSIX path of aliasFilePath
####ドキュメントのパスをNSString
set ocidFilePath to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePath's stringByStandardizingPath
set ocidNSUrlPath to refMe's NSURL's fileURLWithPath:ocidFilePath


###アトリビュートを取得
set ocidFileAttr to appFileManager's attributesOfItemAtPath:ocidFilePath |error|:(missing value)
log (ocidFileAttr's valueForKey:"NSFilePosixPermissions") as integer

###8進数パーミッション値を10進数に変換
set strPemission to doOct2Dem(777)
####パス指定でパーミッション変更 10進数指定
appFileManager's setAttributes:{NSFilePosixPermissions:strPemission} ofItemAtPath:ocidFilePath |error|:(reference)

###511になれば777
###アトリビュートを取得
set ocidFileAttr to appFileManager's attributesOfItemAtPath:ocidFilePath |error|:(missing value)
log (ocidFileAttr's valueForKey:"NSFilePosixPermissions") as integer


###################################
#####パーミッション 8進→10進
(*
###主要なモード NSFilePosixPermissions
777-->511
775-->509
770-->504
755-->493
750-->488
700-->448
555-->365
333-->219
*)
###################################

to doOct2Dem(argOctNo)
  set strOctalText to argOctNo as text
  set num3Line to first item of strOctalText as number
  set num2Line to 2nd item of strOctalText as number
  set num1Line to last item of strOctalText as number
  set numDecimal to (num3Line * 64) + (num2Line * 8) + (num1Line * 1)
  return numDecimal as integer
end doOct2Dem

|

ファイルに設定されているNSFileExtendedAttributesを削除する

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

#!/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 scripting additions


property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()



####ダイアログで使うデフォルトロケーション
tell application "Finder"
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell

###ANy
set listUTI to {"public.item"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

set strFilePath to POSIX path of aliasFilePath
####ドキュメントのパスをNSString
set ocidFilePath to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePath's stringByStandardizingPath
set ocidNSUrlPath to refMe's NSURL's fileURLWithPath:ocidFilePath


###アトリビュートを取得
set ocidFileAttr to appFileManager's attributesOfItemAtPath:ocidFilePath |error|:(missing value)
###ExtendedAttributesを分離取得
set ocidExtendedAttrDict to (ocidFileAttr's valueForKey:"NSFileExtendedAttributes")
###設定されているキーを取得
set ocidAllKyesArray to ocidExtendedAttrDict's allKeys()
###キーの数だけ繰り返し
repeat with itemAllKyesArray in ocidAllKyesArray
  ###削除する
  (ocidExtendedAttrDict's removeObjectForKey:itemAllKyesArray)
end repeat
###確認
if (ocidExtendedAttrDict's valueForKey:"NSFileExtendedAttributes") is missing value then
  log "全て削除しました"
else
  log "何か残ってます"
end if


|

[enumeratorAtURL]ファイルアトリビュートを削除する(深部まで)

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

#!/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 scripting additions

property refMe : a reference to current application

on run
  set aliasDefaultLocation to (path to desktop from user domain) as alias
  set strPromptText to "フォルダをえらんでください"
  set strPromptText to "フォルダをえらんでください"
  try
    set listFolderPath to (choose folder strPromptText with prompt strPromptText default location aliasDefaultLocation with multiple selections allowed, invisibles and showing package contents) as list
  on error
    log "エラーしました"
    return
  end try
  open listFolderPath
end run




on open listFolderPath
  ###ファイルマネジャー初期化
  set appFileManager to refMe's NSFileManager's defaultManager()
  ####フォルダの数だけ繰り返し
  repeat with itemFolderPath in listFolderPath
    ######パス
    set aliasDirPath to itemFolderPath as alias
    set strDirPath to POSIX path of aliasDirPath as text
    set ocidDirPath to (refMe's NSString's stringWithString:strDirPath)
    set ocidDirPath to ocidDirPath's stringByStandardizingPath
    set ocidDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidDirPath isDirectory:true)
    ###enumeratorAtURL用のBoolean
    set ocidFalse to (refMe's NSNumber's numberWithBool:false)
    set ocidTrue to (refMe's NSNumber's numberWithBool:true)
    ###enumeratorAtURLL格納用のレコード
    set ocidEmuDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
    ###enumeratorAtURL格納するリスト
    set ocidEmuFileURLArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
    ###ファイルURLのみを格納するリスト
    set ocidFilePathURLArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
    ####
    set ocidFilePathArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
    ####
    set ocidSortedArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
    ##############################################
    ##ディレクトリのコンテツを収集
    ##############################################
    ###収集する付随プロパティ
    set ocidPropertiesForKeys to {refMe's NSURLIsRegularFileKey}
    ####ディレクトリのコンテツを収集
    set ocidEmuDict to (appFileManager's enumeratorAtURL:ocidDirPathURL includingPropertiesForKeys:ocidPropertiesForKeys options:(refMe's NSDirectoryEnumerationSkipsHiddenFiles) errorHandler:(reference))
    ###戻り値用のリストに格納
    set ocidEmuFileURLArray to ocidEmuDict's allObjects()
    ##############################################
    ##『ファイル』だけ取り出したリストにする
    ##############################################
    
    ####enumeratorAtURLのかずだけ繰り返し
    repeat with itemEmuFileURL in ocidEmuFileURLArray
      ####URLforKeyで取り出し
      set listResult to (itemEmuFileURL's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error|:(reference))
      ###リストからNSURLIsRegularFileKeyBOOLを取り出し
      set boolIsRegularFileKey to item 2 of listResult
      ####ファイルのみを(ディレクトリやリンボリックリンクは含まない)
      if boolIsRegularFileKey is ocidTrue then
        ####リストにする
        (ocidFilePathURLArray's addObject:itemEmuFileURL)
      end if
    end repeat
    
    ###解放
    set ocidEmuFileURLArray to ""
    set ocidEmuDict to ""
    ##############################################
    ##ソート
    ##############################################
    ###NSURLのリストを一旦パスに変更
    set ocidFilePathArray to (ocidFilePathURLArray's valueForKeyPath:"path")
    ###パスでソートしてから
    set ocidSortedArray to (ocidFilePathArray's sortedArrayUsingSelector:"compare:")
    
    
    repeat with itemPathArray in ocidSortedArray
      set strFilePath to itemPathArray as text
      try
        set strCommandText to "/usr/bin/xattr -c \"" & strFilePath & "\"" as text
        set strErrorMes to (do shell script strCommandText) as text
      on error
        log strErrorMes
      end try
    end repeat
    
  end repeat
end open

|

[contentsOfDirectoryAtURL]ファイルアトリビュートを削除する(第一階層のみ)

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

#!/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 scripting additions

property refMe : a reference to current application

on run
  set aliasDefaultLocation to (path to desktop from user domain) as alias
  set strPromptText to "フォルダをえらんでください"
  set strPromptText to "フォルダをえらんでください"
  try
    set listFolderPath to (choose folder strPromptText with prompt strPromptText default location aliasDefaultLocation with multiple selections allowed, invisibles and showing package contents) as list
  on error
    log "エラーしました"
    return
  end try
  open listFolderPath
end run




on open listFolderPath
  ###ファイルマネジャー初期化
  set appFileManager to refMe's NSFileManager's defaultManager()
  ####フォルダの数だけ繰り返し
  repeat with itemFolderPath in listFolderPath
    ######パス
    set aliasDirPath to itemFolderPath as alias
    set strDirPath to POSIX path of aliasDirPath as text
    set ocidDirPath to (refMe's NSString's stringWithString:strDirPath)
    set ocidDirPath to ocidDirPath's stringByStandardizingPath
    set ocidDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidDirPath isDirectory:true)
    ##プロパティ
    set ocidPropertieKey to {(refMe's NSURLPathKey), (refMe's NSURLIsRegularFileKey)}
    ##オプション
    set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles
    ##フォルダ内のファイルをArray
    set listPathUrlArray to (appFileManager's contentsOfDirectoryAtURL:ocidDirPathURL includingPropertiesForKeys:ocidPropertieKey options:ocidOption |error|:(reference))
    set ocidPathUrlArray to item 1 of listPathUrlArray
    log className() of ocidPathUrlArray as text
    ##############################
    ####ファイルパスのArrayに戻す
    ##############################
    set ocidPahtArray to (refMe's NSMutableArray's arrayWithCapacity:0)
    repeat with itemPathURL in ocidPathUrlArray
      set strExtension to itemPathURL's pathExtension() as text
      if strExtension is "url" then
        log
        set listResult to (appFileManager's trashItemAtURL:itemPathURL resultingItemURL:(missing value) |error|:(reference))
      else
        set strFilePath to itemPathURL's |path|()
        (ocidPahtArray's addObject:strFilePath)
      end if
    end repeat
    ##############################
    ####並び替え
    ##############################
    set ocidSortDescriptor to (refMe's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:(true) selector:"localizedStandardCompare:")
    (ocidPahtArray's sortUsingDescriptors:{ocidSortDescriptor})
    ###パスリストにする    UNIXパス形式のリストをOPENしても大丈夫
    set listPahtArray to ocidPahtArray as list
    
    repeat with itemPathArray in listPahtArray
      set strFilePath to itemPathArray as text
      try
        set strCommandText to "/usr/bin/xattr -c \"" & strFilePath & "\"" as text
        set strErrorMes to (do shell script strCommandText) as text
      on error
        log strErrorMes
      end tryv
    end repeat
    
  end repeat
end open

|

[xattr]属性削除

フォルダ版

#!/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 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 aliasDefaultLocation to (path to desktop folder from user domain) as alias
###ダイアログテキスト
set strPromptText to "入力フォルダを選んでください"
try
set listResponse to (choose folder strPromptText with prompt strPromptText default location aliasDefaultLocation with multiple selections allowed, invisibles and showing package contents) as list
on error
log "エラーしました"
return
end try


repeat with itemResponse in listResponse
####エイリアス
set aliasDirPath to itemResponse as alias
###UNIXパス
set strDirPath to POSIX path of aliasDirPath as text
###String
set ocidDirPath to (refNSString's stringWithString:strDirPath)
###NSURL
set ocidDirPathURL to (refNSURL's alloc()'s initFileURLWithPath:ocidDirPath isDirectory:true)

set strCommandText to "/usr/bin/xattr \"" & strDirPath & "\"" as text
set strCommandResponse to (do shell script strCommandText) as text

set AppleScript's text item delimiters to "\r"
set listAttributes to (every text item of strCommandResponse) as list
set AppleScript's text item delimiters to ""

repeat with itemAttributes in listAttributes
set strAttributes to itemAttributes as text
set strCommandText to "/usr/bin/xattr -rd " & strAttributes & " \"" & strDirPath & "\"" as text
do shell script strCommandText

end repeat

end repeat



ファイル版

#!/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 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 aliasDefaultLocation to (path to desktop folder from user domain) as alias
###ダイアログテキスト
set strPromptText to "ファイルを選んでください" as text
####UTI
set listUTI to {"public.item", "public.content", "public.data"}
try
set listResponse to (choose file with prompt strPromptText default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list

on error
log "エラーしました"
return
end try


repeat with itemResponse in listResponse
####エイリアス
set aliasFilePath to itemResponse as alias
###UNIXパス
set strFilePath to POSIX path of aliasFilePath as text
###String
set ocidFilePath to (refNSString's stringWithString:strFilePath)
###NSURL
set ocidFilePathURL to (refNSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:true)

set strCommandText to "/usr/bin/xattr \"" & strFilePath & "\"" as text
set strCommandResponse to (do shell script strCommandText) as text

set AppleScript's text item delimiters to "\r"
set listAttributes to (every text item of strCommandResponse) as list
set AppleScript's text item delimiters to ""

repeat with itemAttributes in listAttributes
set strAttributes to itemAttributes as text
set strCommandText to "/usr/bin/xattr -rd " & strAttributes & " \"" & strFilePath & "\"" as text
do shell script strCommandText

end repeat

end repeat

|

[attributes]ファイル・ディレクトリFinder属性を確認する

/usr/bin/xattr
FInderで設定した属性タグとか?の内容を確認します


sh-3.2$ pwd

/Users/Shared

sh-3.2$ ls

AdobeLibraryPublicZoomOutlookPlugin

ApplicationPicturesSC Infoadi

sh-3.2$ /usr/bin/xattr *

Pictures: com.apple.FinderInfo

Pictures: com.apple.metadata:_kMDItemUserTags

Public: com.apple.FinderInfo

Public: com.apple.metadata:_kMDItemUserTags

SC Info: com.apple.FinderInfo

sh-3.2$ 


|

その他のカテゴリー

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