NSKeyedUnarchiver

[decodeObjectOfClasses]FontBookのフォントコレクションファイルをデコード(KeyedUnarchive)する


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 "AppKit"
010use scripting additions
011property refMe : a reference to current application
012
013
014###################################
015#####ファイル選択ダイアログ
016###################################
017set appFileManager to refMe's NSFileManager's defaultManager()
018set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
019set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
020set strAppendPath to ("FontCollections") as text
021set ocidDefaultLocationURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:true
022set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
023tell current application
024  set strName to name as text
025end tell
026####スクリプトメニューから実行したら
027if strName is "osascript" then
028  tell application "Finder"
029    activate
030  end tell
031else
032  tell current application
033    activate
034  end tell
035end if
036####ダイアログを出す
037set listUTI to {"public.item"} as list
038set aliasFilePath to (choose file with prompt "collectionファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
039####入力ファイルパス
040set strFilePath to POSIX path of aliasFilePath
041set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
042set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
043set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
044set strExtensionName to ocidFilePathURL's pathExtension() as text
045if strExtensionName is not "collection" then
046  tell application "Finder"
047    set aliasPathToMe to (path to me) as alias
048  end tell
049  return "対象外"
050end if
051
052###################################
053#####本処理
054###################################
055# NSDataに読み込んで
056set ocidOption to (refMe's NSDataReadingMappedIfSafe)
057set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
058if (item 2 of listResponse) = (missing value) then
059  log "initWithContentsOfURL 正常処理"
060  set ocidReadData to (item 1 of listResponse)
061else if (item 2 of listResponse) ≠ (missing value) then
062  log (item 2 of listResponse)'s code() as text
063  log (item 2 of listResponse)'s localizedDescription() as text
064  return "initWithContentsOfURL エラーしました"
065end if
066
067# NSKeyedUnarchiverに読み込んで
068set listResponse to refMe's NSKeyedUnarchiver's alloc()'s initForReadingFromData:(ocidReadData) |error| :(reference)
069if (item 2 of listResponse) = (missing value) then
070  log "initForReadingFromData 正常処理"
071  set ocidUnarchiverData to (item 1 of listResponse)
072else if (item 2 of listResponse) ≠ (missing value) then
073  log (item 2 of listResponse)'s code() as text
074  log (item 2 of listResponse)'s localizedDescription() as text
075  return "initForReadingFromData エラーしました"
076end if
077# RequiresSecureCodingを指定
078ocidUnarchiverData's setRequiresSecureCoding:(true)
079
080#クラス
081set ocidClassListArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0))
082(ocidClassListArray's addObject:(refMe's NSFontCollection's class))
083(ocidClassListArray's addObject:(refMe's NSFontDescriptor's class))
084(ocidClassListArray's addObject:(refMe's NSMutableDictionary's class))
085(ocidClassListArray's addObject:(refMe's NSDictionary's class))
086(ocidClassListArray's addObject:(refMe's NSMutableArray's class))
087(ocidClassListArray's addObject:(refMe's NSArray's class))
088(ocidClassListArray's addObject:(refMe's NSString's class))
089(ocidClassListArray's addObject:(refMe's NSNumber's class))
090(ocidClassListArray's addObject:(refMe's NSObject's class))
091#クラスセット
092set ocidSetClass to refMe's NSSet's alloc()'s initWithArray:(ocidClassListArray)
093#decodeObjectOfClassesでデコード
094set ocidPlistDict to ocidUnarchiverData's decodeObjectOfClasses:(ocidSetClass) forKey:("NSFontCollectionDictionary")
095##
096set ocidAttributes to (ocidPlistDict's objectForKey:("NSFontCollectionAttributes"))
097log "NSFontCollectionName : " & (ocidAttributes's valueForKey:("NSFontCollectionName")) as text
098log "NSFontCollectionFileName : " & (ocidAttributes's valueForKey:("NSFontCollectionFileName")) as text
099##
100set ocidDescriptors to (ocidPlistDict's objectForKey:("NSFontCollectionFontDescriptors"))
101repeat with itemDescript in ocidDescriptors
102  log "NSFontNameAttribute : " & (itemDescript's objectForKey:(refMe's NSFontNameAttribute)) as text
103end repeat
104
AppleScriptで生成しました

|

[sfl3] decodeObjectOfClassで解凍する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# LSSharedFileList を Plistに解凍します
005# initForReadingFromDataで読み込んで
006# decodeObjectOfClassで解凍します
007#com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013property refMe : a reference to current application
014
015set appFileManager to refMe's NSFileManager's defaultManager()
016
017###################################
018#####ファイル選択ダイアログ
019###################################
020set appFileManager to refMe's NSFileManager's defaultManager()
021set ocidURLArray to appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)
022set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
023set strAppendPath to ("com.apple.sharedfilelist") as text
024set ocidDefaultLocationURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:true
025set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
026tell current application
027  set strName to name as text
028end tell
029####スクリプトメニューから実行したら
030if strName is "osascript" then
031  tell application "Finder"
032    activate
033  end tell
034else
035  tell current application
036    activate
037  end tell
038end if
039####ダイアログを出す
040set listUTI to {"public.item", "dyn.ah62d4rv4ge81g3xqgk", "dyn.ah62d4rv4ge81g3xqgq", "dyn.ah62d4rv4ge80e7dr"} as list
041set aliasFilePath to (choose file with prompt "sfl3ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
042####入力ファイルパス
043set strFilePath to POSIX path of aliasFilePath
044set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
045set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
046set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
047set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
048set ocidPrefixName to ocidBaseFilePathURL's lastPathComponent()
049###################################
050#####保存先ダイアログ
051###################################
052###ファイル名
053set strPrefixName to ocidPrefixName as text
054###拡張子変える場合
055set strFileExtension to "plist"
056###ダイアログに出すファイル名
057set strDefaultName to (strPrefixName & "." & strFileExtension) as text
058set strPromptText to "名前を決めてください"
059set strMesText to "名前を決めてください"
060####
061set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
062set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
063set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
064
065####実在しない『はず』なのでas «class furl»で
066set aliasSaveFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
067####UNIXパス
068set strSaveFilePath to POSIX path of aliasSaveFilePath as text
069####ドキュメントのパスをNSString
070set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
071####ドキュメントのパスをNSURLに
072set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
073###拡張子取得
074set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
075###ダイアログで拡張子を取っちゃった時対策
076if strFileExtensionName is not strFileExtension then
077  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
078end if
079
080###################################
081#####本処理
082###################################
083# NSDataに読み込んで
084set ocidOption to (refMe's NSDataReadingMappedIfSafe)
085set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
086if (item 2 of listResponse) = (missing value) then
087  log "正常処理"
088  set ocidReadData to (item 1 of listResponse)
089else if (item 2 of listResponse) ≠ (missing value) then
090  log (item 2 of listResponse)'s code() as text
091  log (item 2 of listResponse)'s localizedDescription() as text
092  return "エラーしました"
093end if
094
095# NSKeyedUnarchiverに読み込んで
096set listDone to refMe's NSKeyedUnarchiver's alloc()'s initForReadingFromData:(ocidReadData) |error| :(reference)
097
098log className() of (item 1 of listDone) as text
099if (item 2 of listDone) = (missing value) then
100  log "initForReadingFromData 正常処理"
101  set ocidUnarchiverData to (item 1 of listDone)
102else if (item 2 of listDone) ≠ (missing value) then
103  log (item 2 of listDone)'s code() as text
104  log (item 2 of listDone)'s localizedDescription() as text
105  return "initForReadingFromData エラーしました"
106end if
107
108##decodeObjectOfClassで解凍する
109set ocidPlistDict to ocidUnarchiverData's decodeObjectOfClass:(refMe's NSObject's class) forKey:(refMe's NSKeyedArchiveRootObjectKey)
110
111# 解凍したデータ=DICTをPLISTで保存する
112#XML形式
113set ocidFromat to refMe's NSPropertyListXMLFormat_v1_0
114#NSPropertyListSerialization
115set listResponst to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0  |error| :(reference)
116set ocidPlistEditData to (item 1 of listResponst)
117#ファイル保存
118set listDone to ocidPlistEditData's writeToURL:(ocidSaveFilePathURL) options:0  |error| :(reference)
119
120if (item 1 of listDone) is true then
121  log "正常処理"
122else if (item 2 of listDone) ≠ (missing value) then
123  log (item 2 of listDone)'s code() as text
124  log (item 2 of listDone)'s localizedDescription() as text
125  return "エラーしました"
126end if
AppleScriptで生成しました

|

[sfl3]decodeObjectOfClassesで解凍する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# LSSharedFileList を Plistに解凍します
005# initForReadingFromDataでNSDATAを読み込んで
006# decodeObjectOfClassesで解凍します
007#com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013property refMe : a reference to current application
014
015set appFileManager to refMe's NSFileManager's defaultManager()
016
017###################################
018#####ファイル選択ダイアログ
019###################################
020set appFileManager to refMe's NSFileManager's defaultManager()
021set ocidURLArray to appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)
022set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
023set strAppendPath to ("com.apple.sharedfilelist") as text
024set ocidDefaultLocationURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:true
025set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
026tell current application
027  set strName to name as text
028end tell
029####スクリプトメニューから実行したら
030if strName is "osascript" then
031  tell application "Finder"
032    activate
033  end tell
034else
035  tell current application
036    activate
037  end tell
038end if
039####ダイアログを出す
040set listUTI to {"public.item", "dyn.ah62d4rv4ge81g3xqgk", "dyn.ah62d4rv4ge81g3xqgq", "dyn.ah62d4rv4ge80e7dr"} as list
041set aliasFilePath to (choose file with prompt "sfl3ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
042####入力ファイルパス
043set strFilePath to POSIX path of aliasFilePath
044set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
045set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
046set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
047set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
048set ocidPrefixName to ocidBaseFilePathURL's lastPathComponent()
049###################################
050#####保存先ダイアログ
051###################################
052###ファイル名
053set strPrefixName to ocidPrefixName as text
054###拡張子変える場合
055set strFileExtension to "plist"
056###ダイアログに出すファイル名
057set strDefaultName to (strPrefixName & "." & strFileExtension) as text
058set strPromptText to "名前を決めてください"
059set strMesText to "名前を決めてください"
060####
061set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
062set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
063set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
064
065####実在しない『はず』なのでas «class furl»で
066set aliasSaveFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
067####UNIXパス
068set strSaveFilePath to POSIX path of aliasSaveFilePath as text
069####ドキュメントのパスをNSString
070set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
071####ドキュメントのパスをNSURLに
072set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
073###拡張子取得
074set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
075###ダイアログで拡張子を取っちゃった時対策
076if strFileExtensionName is not strFileExtension then
077  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
078end if
079
080###################################
081#####本処理
082###################################
083# NSDataに読み込んで
084set ocidOption to (refMe's NSDataReadingMappedIfSafe)
085set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
086if (item 2 of listResponse) = (missing value) then
087  log "initWithContentsOfURL 正常処理"
088  set ocidReadData to (item 1 of listResponse)
089else if (item 2 of listResponse) ≠ (missing value) then
090  log (item 2 of listResponse)'s code() as text
091  log (item 2 of listResponse)'s localizedDescription() as text
092  return "initWithContentsOfURL エラーしました"
093end if
094
095# NSKeyedUnarchiverにNSDATAを読み込んで
096set listDone to refMe's NSKeyedUnarchiver's alloc()'s initForReadingFromData:(ocidReadData) |error| :(reference)
097
098log className() of (item 1 of listDone) as text
099if (item 2 of listDone) = (missing value) then
100  log "initForReadingFromData 正常処理"
101  set ocidUnarchiverData to (item 1 of listDone)
102else if (item 2 of listDone) ≠ (missing value) then
103  log (item 2 of listDone)'s code() as text
104  log (item 2 of listDone)'s localizedDescription() as text
105  return "initForReadingFromData エラーしました"
106end if
107# RequiresSecureCodingを指定
108ocidUnarchiverData's setRequiresSecureCoding:(true)
109#クラス
110set ocidClassListArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0))
111(ocidClassListArray's addObject:(refMe's NSMutableDictionary's class))
112(ocidClassListArray's addObject:(refMe's NSDictionary's class))
113(ocidClassListArray's addObject:(refMe's NSMutableArray's class))
114(ocidClassListArray's addObject:(refMe's NSArray's class))
115(ocidClassListArray's addObject:(refMe's NSString's class))
116(ocidClassListArray's addObject:(refMe's NSNumber's class))
117(ocidClassListArray's addObject:(refMe's NSObject's class))
118#クラスセット
119set ocidSetClass to refMe's NSSet's alloc()'s initWithArray:(ocidClassListArray)
120#decodeObjectOfClassesでコード
121set ocidPlistDict to ocidUnarchiverData's decodeObjectOfClasses:(ocidSetClass) forKey:(refMe's NSKeyedArchiveRootObjectKey)
122
123# 解凍したデータ=DICTをPLISTで保存する
124#XML形式
125set ocidFromat to refMe's NSPropertyListXMLFormat_v1_0
126#NSPropertyListSerialization
127set listResponst to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0  |error| :(reference)
128set ocidPlistEditData to (item 1 of listResponst)
129#ファイル保存
130set listDone to ocidPlistEditData's writeToURL:(ocidSaveFilePathURL) options:0  |error| :(reference)
131
132if (item 1 of listDone) is true then
133  log "writeToURL 正常処理"
134else if (item 2 of listDone) ≠ (missing value) then
135  log (item 2 of listDone)'s code() as text
136  log (item 2 of listDone)'s localizedDescription() as text
137  return "writeToURL エラーしました"
138end if
AppleScriptで生成しました

|

[sfl3]decodePropertyListForKeyで解凍する


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# LSSharedFileList を Plistに解凍します
005# initForReadingFromDataで読み込んで
006# decodePropertyListForKeyで解凍します
007#com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013property refMe : a reference to current application
014
015set appFileManager to refMe's NSFileManager's defaultManager()
016
017###################################
018#####ファイル選択ダイアログ
019###################################
020set appFileManager to refMe's NSFileManager's defaultManager()
021set ocidURLArray to appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)
022set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
023set strAppendPath to ("com.apple.sharedfilelist") as text
024set ocidDefaultLocationURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:true
025set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
026tell current application
027  set strName to name as text
028end tell
029####スクリプトメニューから実行したら
030if strName is "osascript" then
031  tell application "Finder"
032    activate
033  end tell
034else
035  tell current application
036    activate
037  end tell
038end if
039####ダイアログを出す
040set listUTI to {"public.item", "dyn.ah62d4rv4ge81g3xqgk", "dyn.ah62d4rv4ge81g3xqgq", "dyn.ah62d4rv4ge80e7dr"} as list
041set aliasFilePath to (choose file with prompt "sfl3ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
042####入力ファイルパス
043set strFilePath to POSIX path of aliasFilePath
044set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
045set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
046set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
047set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
048set ocidPrefixName to ocidBaseFilePathURL's lastPathComponent()
049###################################
050#####保存先ダイアログ
051###################################
052###ファイル名
053set strPrefixName to ocidPrefixName as text
054###拡張子変える場合
055set strFileExtension to "plist"
056###ダイアログに出すファイル名
057set strDefaultName to (strPrefixName & "." & strFileExtension) as text
058set strPromptText to "名前を決めてください"
059set strMesText to "名前を決めてください"
060####
061set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
062set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
063set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
064
065####実在しない『はず』なのでas «class furl»で
066set aliasSaveFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
067####UNIXパス
068set strSaveFilePath to POSIX path of aliasSaveFilePath as text
069####ドキュメントのパスをNSString
070set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
071####ドキュメントのパスをNSURLに
072set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
073###拡張子取得
074set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
075###ダイアログで拡張子を取っちゃった時対策
076if strFileExtensionName is not strFileExtension then
077  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
078end if
079
080###################################
081#####本処理
082###################################
083# NSDataに読み込んで
084set ocidOption to (refMe's NSDataReadingMappedIfSafe)
085set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
086if (item 2 of listResponse) = (missing value) then
087  log "正常処理"
088  set ocidReadData to (item 1 of listResponse)
089else if (item 2 of listResponse) ≠ (missing value) then
090  log (item 2 of listResponse)'s code() as text
091  log (item 2 of listResponse)'s localizedDescription() as text
092  return "エラーしました"
093end if
094
095# NSKeyedUnarchiverに読み込んで
096set listResponse to refMe's NSKeyedUnarchiver's alloc()'s initForReadingFromData:(ocidReadData) |error| :(reference)
097if (item 2 of listResponse) = (missing value) then
098  log "initForReadingFromData 正常処理"
099  set ocidUnarchiverData to (item 1 of listResponse)
100else if (item 2 of listResponse) ≠ (missing value) then
101  log (item 2 of listResponse)'s code() as text
102  log (item 2 of listResponse)'s localizedDescription() as text
103  return "initForReadingFromData エラーしました"
104end if
105# RequiresSecureCodingを指定
106ocidUnarchiverData's setRequiresSecureCoding:(true)
107
108# decodePropertyListForKeyでデコード
109set ocidPlistDict to ocidUnarchiverData's decodePropertyListForKey:(refMe's NSKeyedArchiveRootObjectKey)
110
111# 解凍したデータ=DICTをPLISTで保存する
112#XML形式
113set ocidFromat to refMe's NSPropertyListXMLFormat_v1_0
114#NSPropertyListSerialization
115set listResponst to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0  |error| :(reference)
116set ocidPlistEditData to (item 1 of listResponst)
117#ファイル保存
118set listDone to ocidPlistEditData's writeToURL:(ocidSaveFilePathURL) options:0  |error| :(reference)
119
120if (item 1 of listDone) is true then
121  log "正常処理"
122else if (item 2 of listDone) ≠ (missing value) then
123  log (item 2 of listDone)'s code() as text
124  log (item 2 of listDone)'s localizedDescription() as text
125  return "エラーしました"
126end if
AppleScriptで生成しました

|

com.apple.sharedfilelist

com.apple.sharedfilelist
macOS14で拡張子がsfl2からsfl3に変わった
キーアーカイブされたPLISTデータの取り扱いについて

リセットは今まで通り『sfltool』が利用できます
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-3140f3.html
ここでは、キー・アーカイブのことを
NSKeyedArchiverを圧縮
NSKeyedUnarchiverを解凍と呼んでいます

macOS13まので
圧縮 archivedDataWithRootObject
解凍 unarchiveObjectWithData 

非推奨から利用できなくなりましたので
macOS14では
圧縮 archivedDataWithRootObject:() requiringSecureCoding:() |error|:()
解凍 unarchivedObjectOfClass:(class)fromData:() |error|:() 

使う事になります
com.apple.sharedfilelistのsfl3ファイルはrequiringSecureCodingはfalse=NOが使われます。
macOS13までのスクリプトもこの部分を修正すればそのまま利用できます
Comapplesharedfilelist001

macOS14
圧縮:NSKeyedArchiver
202403201133261332x646

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

set listSaveData to (refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidReplaceDict) requiringSecureCoding:(true) |error|:(reference))
set ocidSaveData to (item 1 of listSaveData)
set ocidOption to (refMe's NSDataWritingFileProtectionNone)
set listDone to (ocidSaveData's writeToURL:(ocidSfl3FilePathURL) options:(ocidOption) |error|:(reference))
set boolDone to (item 1 of listDone) as boolean
if boolDone is false then
log (item 2 of listDone)'s localizedDescription() as text
return "保存に失敗しました"
end if

解凍:NSKeyedUnarchiver
202403201131291322x638

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

set ocidPlistData to (refMe's NSData's dataWithContentsOfURL:(ファイルのURL))
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidPlistData) |error|:(reference)
set ocidPlistDict to (item 1 of listResponse)

LSSharedFileList カテゴリ
https://quicktimer.cocolog-nifty.com/icefloe/cat76055054/index.html

【1】圧縮:NSKeyedArchiver
[NSKeyedArchiver]plistをsfl3形式にKeyedArchiveする
https://quicktimer.cocolog-nifty.com/icefloe/2023/12/post-8e56a6.html


【2】解凍:NSKeyedUnarchiver
[NSKeyedUnarchiver]sfl3をplist形式にKeyedUnarchiveする
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-e2ea07.html

[LSSharedFileList] unarchivedObjectOfClassesで解凍する
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-2d749d.html

com.apple.LSSharedFileList.RecentServers.sfl3
[LSSharedFileList] unarchivedObjectOfClassesで解凍する
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-2d749d.html
[LSSharedFileList]最近使った項目のサーバー部分をリセットする(macOS14 sfl3対応)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-00119a.html

com.apple.LSSharedFileList.RecentHosts.sfl3
[LSSharedFileList]サーバーに接続の履歴部分をリセットする(macOS14 sfl3対応)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-5833e6.html

com.apple.LSSharedFileList.RecentDocuments.sfl3
[LSSharedFileList]最近使った項目の書類部分をリセットする(macOS14 sfl3対応)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-d344c8.html

com.apple.LSSharedFileList.RecentApplications.sfl3
[LSSharedFileList]最近使った項目のアプリケーション部分をリセットする(macOS14 sfl3対応)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-acaee1.html

com.apple.LSSharedFileList.ProjectsItems.sfl3
プロジェクトアイテムはラベルとタグのカテゴリをみてください
https://quicktimer.cocolog-nifty.com/icefloe/cat76054827/index.html

com.apple.LSSharedFileList.NetworkBrowser.sfl3
[sfl3 LSSharedFileList] com.apple.LSSharedFileList.NetworkBrowser.sfl3の設定変更 (macOS14対応版)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-601a41.html

com.apple.LSSharedFileList.iCloudItems.sfl3
[sfl3 LSSharedFileList]サイドバーiCloud編集(iCloudItems.sfl3)検索条件を加える macOS14対応版
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-3a956e.html

com.apple.LSSharedFileList.FavoriteVolumes.sfl3
[sfl3 FavoriteVolumes.sfl3]接続中のiPhoneを開く(sfl3 macOS14対応)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-30f29a.html
[sfl3 LSSharedFileList] com.apple.LSSharedFileList.FavoriteVolumes.sfl3の設定変更 (macOS14対応版)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-d202b0.html

com.apple.LSSharedFileList.FavoriteServers.sfl3
[LSSharedFileList]サーバーへ接続のよく使うサーバーを追加
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-41922b.html

com.apple.LSSharedFileList.FavoriteItems.sfl3
[sfl3 LSSharedFileList]Finderサイドバーのよく使う項目を追加する
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-7f4cb0.html
[FavoriteItems.sfl3]Finderサイドバーにフォルダを追加(macOS14対応版)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-e38f0e.html
[LSSharedFileList]サイドバーよく使う項目にiCloudを追加する(FavoriteItems.sfl3 macOS14対応版)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-3b822c.html

com.apple.LSSharedFileList.ApplicationRecentDocuments.sfl3
[ApplicationRecentDocuments]アプリケーションの最近使った項目をリセットする
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-0516ef.html

com.apple.LSSharedFileList.ApplicationRecentDocuments
[com.apple.sharedfilelist]最近使った書類を初期化する(com.apple.LSSharedFileList.ApplicationRecentDocuments)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-1556a6.html

|

ラベル(色)指定のあるタグを作成する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# macOS14版
# 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 strTagName to ("名称未設定新規タグ") as text
##ラベル番号=色ね
(*
0:ラベル無し
1:グレー
2:グリーン
3:パープル
4:ブルー
5:イエロー
6:レッド
7:オレンジ
*)
set numLabelNo to 6 as integer


###実行
log doMakeTagName(strTagName, numLabelNo)



#######################################
##ファンクション
#######################################
to doMakeTagName(argTagNameText, argLabeClolorNo)
  
  set strName to argTagNameText as text
  set numLabelNo to argLabeClolorNo as integer
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###処理するファイル名
  set strFileName to "com.apple.LSSharedFileList.ProjectsItems.sfl3" as text
  ###URLに
  set ocidURLArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
  set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
  set ocidContainerPathURL to (ocidAppSuppDirPathURL's URLByAppendingPathComponent:("com.apple.sharedfilelist") isDirectory:true)
  set ocidSharedFileListURL to (ocidContainerPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false)
  ###NSDATAに読み込みます
  set ocidPlistData to (refMe's NSData's dataWithContentsOfURL:(ocidSharedFileListURL))
  ### 解凍してDictに Flozenなので値を変更するために 可変に変えます
  #NSKeyedUnarchiver's  OS13までの方式
  # set ocidArchveDict to (refMe's NSKeyedUnarchiver's unarchiveObjectWithData:(ocidPlistData))
  #NSKeyedUnarchiver's  OS14からの方式
  set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidPlistData) |error|:(reference)
  set ocidArchveDict to (item 1 of listResponse)
  ### 可変Dictにセット
  set ocidArchveDictM to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidArchveDictM's setDictionary:ocidArchveDict)
  #######################################
  ### items の処理
  #######################################
  ### items のArrayを取り出して Flozenなので値を変更するために 可変に変えます
  set ocidItemsArray to (ocidArchveDictM's objectForKey:("items"))
  ### 項目入替用のArray 
  set ocidItemsArrayM to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
(ocidItemsArrayM's setArray:ocidItemsArray)
  ##################
  ###itemsの数だけ繰り返し
  repeat with itemsArrayDict in ocidItemsArray
    #
    set strItemName to (itemsArrayDict's objectForKey:("Name")) as text
    if strItemName is strName then
      ###値があった場合
      set boolChkTagName to true as boolean
      exit repeat
    else
      ###なかった場合
      set boolChkTagName to false as boolean
    end if
  end repeat
log "タグの有無:" & boolChkTagName
  #######################################
  ### タグがない場合は作る
  #######################################
  if boolChkTagName is false then
    try
      set strAgentPath to "/System/Library/LaunchAgents/com.apple.coreservices.sharedfilelistd.plist"
      set strCommandText to ("/bin/launchctl unload -w \"" & strAgentPath & "\"") as text
do shell script strCommandText
    end try
    try
      set strAgentPath to "/System/Library/LaunchAgents/com.apple.cfprefsd.xpc.agent.plist"
      set strCommandText to ("/bin/launchctl unload -w \"" & strAgentPath & "\"") as text
do shell script strCommandText
    end try
    ### 項目追加用のDict
    set ocidAddProkectDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
    set ocidCustomPropertiesDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
    ################################CustomItemProperties
    set ocidTrue to refMe's NSNumber's numberWithBool:(true)
ocidCustomPropertiesDict's setValue:(ocidTrue) forKey:("kLSSharedTagFileListItemPinned")
    ##表示させたい場合はここをocidFalseに
    set ocidTrue to refMe's NSNumber's numberWithBool:(true)
ocidCustomPropertiesDict's setValue:(ocidTrue) forKey:("com.apple.LSSharedFileList.ItemIsHidden")
    ##
    set ocidLabelNo to refMe's NSNumber's numberWithInteger:(numLabelNo)
ocidCustomPropertiesDict's setValue:(ocidLabelNo) forKey:("kLSSharedTagFileListItemLabel")
    ##CustomItemPropertiesでDictを追加
ocidAddProkectDict's setObject:(ocidCustomPropertiesDict) forKey:("CustomItemProperties")
    #######################################
    ### Bookmarkデータ生成
    #######################################
    (*
URL形式で
x-apple-findertag:%エンコードされたタグの名前
の形式になります
*)
    set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
ocidURLComponents's setScheme:("x-apple-findertag")
ocidURLComponents's setPath:(strName)
    set ocidTagURL to ocidURLComponents's |URL|()
    set listBookMarkData to (ocidTagURL's bookmarkDataWithOptions:(11) includingResourceValuesForKeys:({missing value}) relativeToURL:(missing value) |error|:(reference))
    set ocidBookMarkData to item 1 of listBookMarkData
ocidAddProkectDict's setObject:(ocidBookMarkData) forKey:("Bookmark")
    ##
    set ocidTagName to refMe's NSString's stringWithString:(strName)
ocidAddProkectDict's setObject:(ocidTagName) forKey:("Name")
    ##
    set ocidUUID to refMe's NSUUID's alloc()'s init()
    set ocidUUIDString to ocidUUID's UUIDString()
ocidAddProkectDict's setValue:(ocidUUIDString) forKey:("uuid")
    ##
    set ocidVisibility to refMe's NSNumber's numberWithInteger:(0)
ocidAddProkectDict's setValue:(ocidVisibility) forKey:("visibility")
    ##itemsのArrayに追加
ocidItemsArrayM's addObject:(ocidAddProkectDict)
    ### RootにItemsを追加
(ocidArchveDictM's setObject:(ocidItemsArrayM) forKey:("items"))
    #######################################
    ### 値が新しくなった解凍済みDictをアーカイブする
    #######################################
    ##NSKeyedArchiverに戻す OS13までの形式
    # set listSaveData to (refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidArchveDictM) requiringSecureCoding:(true) |error|:(reference))
    ##NSKeyedArchiver OS14からの形式
    set listSaveData to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidArchveDictM) requiringSecureCoding:(false) |error|:(reference)
    set ocidSaveData to item 1 of listSaveData
    ###########
    ##保存
    set listDone to ocidSaveData's writeToURL:(ocidSharedFileListURL) options:0 |error|:(reference)
    ###########
    ###リロード
    ###########
    try
      set strAgentPath to "/System/Library/LaunchAgents/com.apple.coreservices.sharedfilelistd.plist"
      set strCommandText to ("/bin/launchctl load -w \"" & strAgentPath & "\"") as text
do shell script strCommandText
    end try
    try
      set strAgentPath to "/System/Library/LaunchAgents/com.apple.cfprefsd.xpc.agent.plist"
      set strCommandText to ("/bin/launchctl load -w \"" & strAgentPath & "\"") as text
do shell script strCommandText
    end try
delay 1
    try
do shell script "/usr/bin/killall cfprefsd"
    end try
    try
do shell script "/usr/bin/killall sharedfilelistd"
    end try
    
    
  else
    try
do shell script "/usr/bin/killall cfprefsd"
    end try
    
    try
do shell script "/usr/bin/killall sharedfilelistd"
    end try
  end if
  
  
  
  
end doMakeTagName


|

[NSKeyedUnarchiver]sfl3をplist形式にKeyedUnarchiveする


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# LSSharedFileList を Plistに解凍します
#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 appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLArray to appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)
set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
set strAppendPath to ("com.apple.sharedfilelist") as text
set ocidDefaultLocationURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false
set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
####ダイアログを出す
set listUTI to {"public.item", "dyn.ah62d4rv4ge81g3xqgk", "dyn.ah62d4rv4ge81g3xqgq"} as list
set aliasFilePath to (choose file with prompt "sfl3ファイルを選んでください" 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
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 ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
set ocidPrefixName to ocidBaseFilePathURL's lastPathComponent()
###################################
#####保存先ダイアログ
###################################
###ファイル名
set strPrefixName to ocidPrefixName as text
###拡張子変える場合
set strFileExtension to "plist"
###ダイアログに出すファイル名
set strDefaultName to (strPrefixName & "." & strFileExtension) as text
set strPromptText to "名前を決めてください"
set strMesText to "名前を決めてください"
####
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias

####実在しない『はず』なのでas «class furl»で
set aliasSaveFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
####UNIXパス
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
####ドキュメントのパスをNSString
set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
####ドキュメントのパスをNSURLに
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
###拡張子取得
set strFileExtensionName to ocidSaveFilePathURL's pathExtension() as text
###ダイアログで拡張子を取っちゃった時対策
if strFileExtensionName is not strFileExtension then
  set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if

###################################
#####本処理
###################################
# NSDataに読み込んで
set ocidReadData to refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL)
# unarchivedObjectOfClassで解凍する
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidReadData) |error|:(reference)
set ocidPlistDict to (item 1 of listResponse)
if ocidPlistDict = (missing value) then
return "解凍に失敗しました"
end if
# 解凍したデータ=DICTをPLISTで保存する
#XML形式
set ocidFromat to refMe's NSPropertyListXMLFormat_v1_0
#NSPropertyListSerialization
set listResponst to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0 |error|:(reference)
set ocidPlistEditData to (item 1 of listResponst)
#ファイル保存
set listDone to ocidPlistEditData's writeToURL:(ocidSaveFilePathURL) options:0 |error|:(reference)



|

[NSKeyedUnarchiver]com.apple.LSSharedFileListのBookMarkデータを表示(macOS14対応)ちょっと修正


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.apple.LSSharedFileListのBookMarkデータを表示します
#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 ocidURLArray to appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)
set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
set strAppendPath to ("com.apple.sharedfilelist") as text
set ocidTargetDirURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false
set aliasDefaultLocation to (ocidTargetDirURL's absoluteURL()) as alias
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
####ダイアログを出す
set listUTI to {"com.apple.property-list", "dyn.ah62d4rv4ge81g3xqgq"} as list
set aliasFilePath to (choose file with prompt "plistファイルを選んでください" 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
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 strExtensionName to (ocidFilePathURL's pathExtension()) as text

###################################
#####処理分岐
###################################
if strExtensionName is "plist" then
  # DICTに読み込んで
  set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference)
  set ocidPlistDict to (item 1 of listResponse)
else if strExtensionName is "sfl3" then
  # NSDataに読み込んで
  set ocidReadData to refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL)
  # unarchivedObjectOfClassで解凍する
  set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidReadData) |error|:(reference)
  set ocidPlistDict to (item 1 of listResponse)
  if ocidPlistDict = (missing value) then
return "解凍に失敗しました"
  end if
end if

###################################
#####
###################################
set ocidItemsArray to (ocidPlistDict's objectForKey:("items"))
repeat with itemsArrayDict in ocidItemsArray
  set ocidBookMarkData to (itemsArrayDict's objectForKey:("Bookmark"))
  #BOOKMarkデータの解凍
  set listResponse to (refMe's NSURL's URLByResolvingBookmarkData:(ocidBookMarkData) options:(refMe's NSURLBookmarkResolutionWithoutUI) relativeToURL:(missing value) bookmarkDataIsStale:(missing value) |error|:(reference))
  set ocidBookMarkURL to (item 1 of listResponse)
log ocidBookMarkURL's absoluteString() as text
  
end repeat



|

[LSSharedFileList.ProjectsItems]タグの有無のチェック(macOS14 sfl3対応)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
Finder>>設定>>タグに項目がすでにあるか?をチェック
macOS14以降のsfl3版です
*)
----+----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 strName to ("CMYK Image")

#######################################
##NSdataに読み込み Keyを解凍する
#######################################
set appFileManager to refMe's NSFileManager's defaultManager()
###処理するファイル名
set strFileName to "com.apple.LSSharedFileList.ProjectsItems.sfl3" as text
###URLに
set ocidURLArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
set ocidContainerPathURL to (ocidAppSuppDirPathURL's URLByAppendingPathComponent:("com.apple.sharedfilelist") isDirectory:true)
set ocidSharedFileListURL to (ocidContainerPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false)
###NSDATAに読み込みます
set ocidPlistData to (refMe's NSData's dataWithContentsOfURL:(ocidSharedFileListURL))
### 解凍してDictに Flozenなので値を変更するために 可変に変えます
#NSKeyedUnarchiver's  OS13までの方式
# set ocidArchveDict to (refMe's NSKeyedUnarchiver's unarchiveObjectWithData:(ocidPlistData))
#NSKeyedUnarchiver's  OS14からの方式
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidPlistData) |error|:(reference)
set ocidArchveDict to (item 1 of listResponse)
### 可変Dictにセット
set ocidArchveDictM to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidArchveDictM's setDictionary:ocidArchveDict)
#######################################
### items の処理
#######################################
### items のArrayを取り出して Flozenなので値を変更するために 可変に変えます
set ocidItemsArray to (ocidArchveDictM's objectForKey:("items"))
##################
###itemsの数だけ繰り返し
repeat with itemsArrayDict in ocidItemsArray
  #
  set strItemName to (itemsArrayDict's objectForKey:("Name")) as text
  if strItemName is strName then
    ###値があった場合
    set boolChkTagName to true as boolean
log "指定の名称のタグがすでにあります"
    exit repeat
  else
    ###なかった場合
    set boolChkTagName to false as boolean
  end if
end repeat


return boolChkTagName

|

[LSSharedFileList.ProjectsItems]色指定付きのタグを作る(macOS14 sfl3対応)

Screen_20230809_11_58_19_20240312193201

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
Finder>>設定>>タグに項目を追加します
macOS14以降のsfl3版です
*)
----+----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 strName to ("Windows非互換文字") as text
###ラベルカラー番号
set numLabelNo to (5) as integer
(* ラベルカラー番号 Finderラベル番号の逆順なので留意ください
0 なし
1 グレイ
2 グリーン
3 パープル
4 ブルー
5 イエロー
6 レッド
7 オレンジ
*)

#######################################
##NSdataに読み込み Keyを解凍する
#######################################
set appFileManager to refMe's NSFileManager's defaultManager()
###処理するファイル名
set strFileName to "com.apple.LSSharedFileList.ProjectsItems.sfl3" as text
###URLに
set ocidURLArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
set ocidContainerPathURL to (ocidAppSuppDirPathURL's URLByAppendingPathComponent:("com.apple.sharedfilelist") isDirectory:true)
set ocidSharedFileListURL to (ocidContainerPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false)
###NSDATAに読み込みます
set ocidPlistData to (refMe's NSData's dataWithContentsOfURL:(ocidSharedFileListURL))
### 解凍してDictに Flozenなので値を変更するために 可変に変えます
#NSKeyedUnarchiver's  OS13までの方式
# set ocidArchveDict to (refMe's NSKeyedUnarchiver's unarchiveObjectWithData:(ocidPlistData))
#NSKeyedUnarchiver's  OS14からの方式
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidPlistData) |error|:(reference)
set ocidArchveDict to (item 1 of listResponse)
### 可変Dictにセット
set ocidArchveDictM to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidArchveDictM's setDictionary:ocidArchveDict)

#######################################
### items の処理
#######################################
### items のArrayを取り出して Flozenなので値を変更するために 可変に変えます
set ocidItemsArray to (ocidArchveDictM's objectForKey:("items"))
### 項目入替用のArray 
set ocidItemsArrayM to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
(ocidItemsArrayM's setArray:ocidItemsArray)
set numCntArrayItem to count of ocidItemsArray
#######################################
### 値がすでにあるか?確認
set boolChkTagName to (missing value)
##################
###itemsの数だけ繰り返し
repeat with itemsArrayDict in ocidItemsArrayM
  ####
  set strItemName to (itemsArrayDict's objectForKey:("Name")) as text
  if strItemName is strName then
    ###値があった場合
    set boolChkTagName to true as boolean
    exit repeat
  else
    ###なかった場合
    set boolChkTagName to false as boolean
  end if
end repeat
#######################################
### 本処理項目の追加
#######################################
### 項目追加用のDict
set ocidAddProkectDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set ocidCustomPropertiesDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
###すでにあるか?判定でなけば追加する
if boolChkTagName is false then
  ################################CustomItemProperties
  set ocidTrue to refMe's NSNumber's numberWithBool:(true)
ocidCustomPropertiesDict's setValue:(ocidTrue) forKey:("kLSSharedTagFileListItemPinned")
  ##表示させたい場合はここをocidFalseに
  set ocidTrue to refMe's NSNumber's numberWithBool:(true)
ocidCustomPropertiesDict's setValue:(ocidTrue) forKey:("com.apple.LSSharedFileList.ItemIsHidden")
  (* #### LabelNumber
0:ラベル無し
1:グレー
2:グリーン
3:パープル
4:ブルー
5:イエロー
6:レッド
7:オレンジ
*)
  set numLabelNo to 3 as integer
  #
  set ocidLabelNo to refMe's NSNumber's numberWithInteger:(numLabelNo)
ocidCustomPropertiesDict's setValue:(ocidLabelNo) forKey:("kLSSharedTagFileListItemLabel")
  ##CustomItemPropertiesでDictを追加
ocidAddProkectDict's setObject:(ocidCustomPropertiesDict) forKey:("CustomItemProperties")
  ################################ 追加用のDict root
  (* Bookmarkデータ生成
URL形式で
x-apple-findertag:%エンコードされたタグの名前
の形式になります
*)
  set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
ocidURLComponents's setScheme:("x-apple-findertag")
ocidURLComponents's setPath:(strName)
  set ocidTagURL to ocidURLComponents's |URL|()
  set listBookMarkData to (ocidTagURL's bookmarkDataWithOptions:(11) includingResourceValuesForKeys:({missing value}) relativeToURL:(missing value) |error|:(reference))
  set ocidBookMarkData to item 1 of listBookMarkData
ocidAddProkectDict's setObject:(ocidBookMarkData) forKey:("Bookmark")
  ##
  set ocidTagName to refMe's NSString's stringWithString:(strName)
ocidAddProkectDict's setObject:(ocidTagName) forKey:("Name")
  ##
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString()
ocidAddProkectDict's setValue:(ocidUUIDString) forKey:("uuid")
  ##
  set ocidVisibility to refMe's NSNumber's numberWithInteger:(0)
ocidAddProkectDict's setValue:(ocidVisibility) forKey:("visibility")
  ##itemsのArrayに追加
ocidItemsArrayM's addObject:(ocidAddProkectDict)
end if
### RootにItemsを追加
(ocidArchveDictM's setObject:(ocidItemsArrayM) forKey:("items"))

#######################################
### 値が新しくなった解凍済みDictをアーカイブする
#######################################
##NSKeyedArchiverに戻す OS13までの形式
# set listSaveData to (refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidArchveDictM) requiringSecureCoding:(true) |error|:(reference))
##NSKeyedArchiver OS14からの形式
set listSaveData to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidArchveDictM) requiringSecureCoding:(false) |error|:(reference)
set ocidSaveData to item 1 of listSaveData

#######################################
### データを上書き保存する
#######################################
##保存
set listDone to ocidSaveData's writeToURL:(ocidSharedFileListURL) options:0 |error|:(reference)

#######################################
### リロード
#######################################
try
do shell script "/usr/bin/killall sharedfilelistd"
on error
  set strAgentPath to "/System/Library/LaunchAgents/com.apple.coreservices.sharedfilelistd.plist"
  set strCommandText to ("/bin/launchctl stop -w \"" & strAgentPath & "\"")
  try
do shell script strCommandText
  end try
  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
  try
do shell script strCommandText
  end try
end try
delay 0.5
do shell script "/usr/bin/killall Finder"

return


|

その他のカテゴリー

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