LSSharedFileList

[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で生成しました

|

[NSKeyedUnarchiver]FInderでiPhoneを開くスクリプトを生成する(macOS14対応)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
# USB接続中のiPhoneをくスクリプトを生成します
# スクリプトメニューから実行しても戻り値がありません
----+----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

############################################
####設定項目
###iPhoneの名前(一部でもOK)
set strPhoneName to ("iPhone") as text


##スクリプトメニューから実行させない
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
open aliasPathToMe
    end tell
return "中止しました"
  end tell
else
  tell current application
activate
  end tell
end if

##################
set listDockPath to {} as list
###処理開始
set appFileManager to refMe's NSFileManager's defaultManager()
###ファイル名
set strFileName to "com.apple.LSSharedFileList.FavoriteVolumes.sfl3" as text
###パス
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/" & strFileName) as text
set ocidFavoriteServersURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false
##NSdataに読み込み
set ocidPlistData to refMe's NSData's dataWithContentsOfURL:(ocidFavoriteServersURL)
###解凍してDictに
#set ocidArchveDict to refMe's NSKeyedUnarchiver's unarchiveObjectWithData:(ocidPlistData)
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidPlistData) |error|:(reference)
set ocidArchveDict to (item 1 of listResponse)

###ここは不要なんだけど、値も変更できるように準備
set ocidArchveDictM to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidArchveDictM's setDictionary:(ocidArchveDict)
###ALLkeys
set ocidAllKeysArray to ocidArchveDictM's |allKeys|()

###items のArrayを取り出しhて
set ocidItemsArray to ocidArchveDictM's objectForKey:("items")
set numCntArray to (ocidItemsArray's |count|()) as integer

###itemsの数だけ繰り返し
#repeat with itemArray in ocidItemsArray

repeat with itemIntNo from 0 to (numCntArray - 1) by 1
  set itemArray to (ocidItemsArray's objectAtIndex:(itemIntNo))
  
  # log className() of itemArray as text
  # log itemArray's allKeys() as list
  --> (*visibility, CustomItemProperties, Bookmark, uuid*)
  set ocidVisibility to (itemArray's objectForKey:("visibility"))
  # log className() of ocidVisibility as text
  # log ocidVisibility as integer
  set ocidCustomItemProperties to (itemArray's objectForKey:("CustomItemProperties"))
  # log className() of ocidCustomItemProperties as text
  # log ocidCustomItemProperties as record
  set ocidUUID to (itemArray's objectForKey:("uuid"))
  # log className() of ocidUUID as text
  # log ocidUUID as text
  set ocidName to (itemArray's objectForKey:("Name"))
  try
log className() of ocidName as text
log "■" & ocidName as text
    set strName to ocidName as text
  on error
    set strName to ("missing value") as text
  end try
  if strName contains strPhoneName then
    set ocidBookMarkData to (itemArray's objectForKey:("Bookmark"))
    ###エイリアスの解決
    set listResponse to (refMe's NSURL's URLByResolvingBookmarkData:(ocidBookMarkData) options:11 relativeToURL:(missing value) bookmarkDataIsStale:(false) |error|:(reference))
    set ocidBookMarkURL to item 1 of listResponse
    ###エイリアスが無い場合=すでに削除された場合や移動してしまった場合
    if ocidBookMarkURL is not (missing value) then
      ###パスにして
      set strFilePath to ocidBookMarkURL's absoluteString() as text
log strFilePath
      ###リストに追加
      if strFilePath contains "x-finder-iTunes" then
        set end of listDockPath to strFilePath
      end if
    end if
  end if
end repeat

if listDockPath is {} then
return "接続中のiPhone無し"
end if

try
  ###ダイアログ
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  set listResponse to (choose from list listDockPath with title "選んでください" with prompt "FavoriteVolumesから取得した\n接続中のiPhoneのURL\n複数選択時は対象を選んでください" default items (item 1 of listDockPath) OK button name "このiPhoneのURLを取得する" cancel button name "閉じる" without multiple selections allowed and empty selection allowed) as list
on error
log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
return "キャンセルしました"
end if
set strOpenURL to (item 1 of listResponse) as text


####クリップボードに渡す用のスクリプトテンプレート
set strScript to ("#!/usr/bin/env osascript\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\n#\n#com.cocolog-nifty.quicktimer.icefloe\n----+----1----+----2----+-----3----+----4----+----5----+----6----+----7\nuse AppleScript version \"2.8\"\nuse framework \"Foundation\"\nuse scripting additions\nset strURL to \"" & strOpenURL & "\"\ntell application \"Finder\"\nopen location strURL\nend tell") as text

set strMes to ("↓接続中のiPhoneのURLです\n" & strOpenURL & "\n↓は次回から利用可能なスクリプト") as text
###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
set recordResult to (display dialog strMes with title "接続中のiPhoneのURL" default answer strScript buttons {"スクリプトをクリップボードにコピー", "キャンセル", "iPhoneをFinderで開く"} default button "iPhoneをFinderで開く" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
if button returned of recordResult is "iPhoneをFinderで開く" then
  tell application "Finder"
open location strOpenURL
  end tell
  ###クリップボードコピー
else if button returned of recordResult is "スクリプトをクリップボードにコピー" then
  set strText to text returned of recordResult as text
  ####ペーストボード宣言
  set appPasteboard to refMe's NSPasteboard's generalPasteboard()
  set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
end if


display notification "処理終了" with title "処理が終了" subtitle "処理が終了しました" sound name "Sonumi"
log ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"
return ">>>>>>>>>>>>処理終了<<<<<<<<<<<<<<<"



|

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

|

[ApplicationRecentDocuments]アプリケーションの最近使った項目をリセットする


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

#!/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
###################################
##スクリプトメニューから実行させない
###################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
open aliasPathToMe
    end tell
return "中止しました"
  end tell
else
  tell current application
activate
  end tell
end if

###################################
#####ファイル選択ダイアログ
###################################
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/com.apple.LSSharedFileList.ApplicationRecentDocuments") as text
set ocidDefaultLocationURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:true
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)
###################################
#####本処理
###################################
# 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
#propertiesの値は
set ocidProperties to ocidPlistDict's objectForKey:("properties")
#引き継ぐ
set ocidSaveDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidSaveDict's setObject:(ocidProperties) forKey:("properties")
#itemsは空のArrayをセット=リセット
set ocidItemsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSaveDict's setObject:(ocidItemsArray) forKey:("items")
#アーカイブする
set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidSaveDict) requiringSecureCoding:(false) |error|:(reference)
set ocidSfl3Data to (item 1 of listResponse)
if ocidSfl3Data = (missing value) then
return "アーカイブに失敗しました"
end if
#ファイル保存
set listDone to ocidSfl3Data's writeToURL:(ocidFilePathURL) options:0 |error|:(reference)
if (item 1 of listDone) is false then
return "保存に失敗しました"
end if
###################################
#####本処理
###################################
set strAppendPath to ("com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments.sfl3") as text
set ocidFilePathURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false

# 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
#propertiesの値は
set ocidProperties to ocidPlistDict's objectForKey:("properties")
#引き継ぐ
set ocidSaveDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidSaveDict's setObject:(ocidProperties) forKey:("properties")
#itemsは空のArrayをセット=リセット
set ocidItemsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSaveDict's setObject:(ocidItemsArray) forKey:("items")
#アーカイブする
set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidSaveDict) requiringSecureCoding:(false) |error|:(reference)
set ocidSfl3Data to (item 1 of listResponse)
if ocidSfl3Data = (missing value) then
return "アーカイブに失敗しました"
end if
#ファイル保存
set listDone to ocidSfl3Data's writeToURL:(ocidFilePathURL) options:0 |error|:(reference)
if (item 1 of listDone) is false then
return "保存に失敗しました"
end if


#######################################
### リロード
#######################################
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 & "\"") as text
  try
do shell script strCommandText
  end try
  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
  try
do shell script strCommandText
  end try
end try

|

[LSSharedFileList]最近使った項目のサーバー部分をリセットする(macOS14 sfl3対応)

20240329103425_453x321

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

#!/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
###################################
##スクリプトメニューから実行させない
###################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
open aliasPathToMe
    end tell
return "中止しました"
  end tell
else
  tell current application
activate
  end tell
end if

###################################
#####本処理
###################################
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/com.apple.LSSharedFileList.RecentServers.sfl3") as text
set ocidFilePathURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false

# 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
#propertiesの値は
set ocidProperties to ocidPlistDict's objectForKey:("properties")
#引き継ぐ
set ocidSaveDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidSaveDict's setObject:(ocidProperties) forKey:("properties")
#itemsは空のArrayをセット=リセット
set ocidItemsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSaveDict's setObject:(ocidItemsArray) forKey:("items")
#アーカイブする
set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidSaveDict) requiringSecureCoding:(false) |error|:(reference)
set ocidSfl3Data to (item 1 of listResponse)
if ocidSfl3Data = (missing value) then
return "アーカイブに失敗しました"
end if
#ファイル保存
set listDone to ocidSfl3Data's writeToURL:(ocidFilePathURL) options:0 |error|:(reference)
if (item 1 of listDone) is false then
return "保存に失敗しました"
end if


#######################################
### リロード
#######################################
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 & "\"") as text
  try
do shell script strCommandText
  end try
  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
  try
do shell script strCommandText
  end try
end try
#
do shell script "/usr/bin/killall Finder"

|

[LSSharedFileList]サーバーに接続の履歴部分をリセットする(macOS14 sfl3対応)

20240329103445_970x464

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

#!/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
###################################
##スクリプトメニューから実行させない
###################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
open aliasPathToMe
    end tell
return "中止しました"
  end tell
else
  tell current application
activate
  end tell
end if

###################################
#####本処理
###################################
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/com.apple.LSSharedFileList.RecentHosts.sfl3") as text
set ocidFilePathURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false

# 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
#propertiesの値は
set ocidProperties to ocidPlistDict's objectForKey:("properties")
#引き継ぐ
set ocidSaveDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidSaveDict's setObject:(ocidProperties) forKey:("properties")
#itemsは空のArrayをセット=リセット
set ocidItemsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSaveDict's setObject:(ocidItemsArray) forKey:("items")
#アーカイブする
set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidSaveDict) requiringSecureCoding:(false) |error|:(reference)
set ocidSfl3Data to (item 1 of listResponse)
if ocidSfl3Data = (missing value) then
return "アーカイブに失敗しました"
end if
#ファイル保存
set listDone to ocidSfl3Data's writeToURL:(ocidFilePathURL) options:0 |error|:(reference)
if (item 1 of listDone) is false then
return "保存に失敗しました"
end if


#######################################
### リロード
#######################################
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 & "\"") as text
  try
do shell script strCommandText
  end try
  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
  try
do shell script strCommandText
  end try
end try
#
do shell script "/usr/bin/killall Finder"

|

[LSSharedFileList]最近使った項目のアプリケーション部分をリセットする(macOS14 sfl3対応)

20240329102618_2880x1800

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

#!/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
###################################
##スクリプトメニューから実行させない
###################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
open aliasPathToMe
    end tell
return "中止しました"
  end tell
else
  tell current application
activate
  end tell
end if

###################################
#####本処理
###################################
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/com.apple.LSSharedFileList.RecentApplications.sfl3") as text
set ocidFilePathURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false

# 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
#propertiesの値は
set ocidProperties to ocidPlistDict's objectForKey:("properties")
#引き継ぐ
set ocidSaveDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidSaveDict's setObject:(ocidProperties) forKey:("properties")
#itemsは空のArrayをセット=リセット
set ocidItemsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSaveDict's setObject:(ocidItemsArray) forKey:("items")
#アーカイブする
set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidSaveDict) requiringSecureCoding:(false) |error|:(reference)
set ocidSfl3Data to (item 1 of listResponse)
if ocidSfl3Data = (missing value) then
return "アーカイブに失敗しました"
end if
#ファイル保存
set listDone to ocidSfl3Data's writeToURL:(ocidFilePathURL) options:0 |error|:(reference)
if (item 1 of listDone) is false then
return "保存に失敗しました"
end if


#######################################
### リロード
#######################################
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 & "\"") as text
  try
do shell script strCommandText
  end try
  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
  try
do shell script strCommandText
  end try
end try
#
do shell script "/usr/bin/killall Finder"

|

[LSSharedFileList]最近使った項目の書類部分をリセットする(macOS14 sfl3対応)

20240329102052_553x428

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

#!/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
###################################
##スクリプトメニューから実行させない
###################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    set aliasPathToMe to path to me as alias
    tell application "Script Editor"
open aliasPathToMe
    end tell
return "中止しました"
  end tell
else
  tell current application
activate
  end tell
end if

###################################
#####本処理
###################################
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/com.apple.LSSharedFileList.RecentDocuments.sfl3") as text
set ocidFilePathURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false

# 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
#propertiesの値は
set ocidProperties to ocidPlistDict's objectForKey:("properties")
#引き継ぐ
set ocidSaveDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidSaveDict's setObject:(ocidProperties) forKey:("properties")
#itemsは空のArrayをセット=リセット
set ocidItemsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSaveDict's setObject:(ocidItemsArray) forKey:("items")
#アーカイブする
set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidSaveDict) requiringSecureCoding:(false) |error|:(reference)
set ocidSfl3Data to (item 1 of listResponse)
if ocidSfl3Data = (missing value) then
return "アーカイブに失敗しました"
end if
#ファイル保存
set listDone to ocidSfl3Data's writeToURL:(ocidFilePathURL) options:0 |error|:(reference)
if (item 1 of listDone) is false then
return "保存に失敗しました"
end if


#######################################
### リロード
#######################################
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 & "\"") as text
  try
do shell script strCommandText
  end try
  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
  try
do shell script strCommandText
  end try
end try
#
do shell script "/usr/bin/killall Finder"

|

より以前の記事一覧

その他のカテゴリー

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