AppleScript LSSharedFileList

[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"

|

[Bookmark] sfl3のブックマークの内容を確認する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
#
# よく使う項目にiCloudを追加する
----+----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 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 ocidSfl3FilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)


#######################################
##NSdataに読み込み Keyを解凍する
#######################################
###【1】NSDataに読み込む
set ocidOption to (refMe's NSDataReadingMappedIfSafe)
set listReadData to refMe's NSData's dataWithContentsOfURL:(ocidSfl3FilePathURL) options:(ocidOption) |error|:(reference)
set ocidPlistData to (item 1 of listReadData)
###【2】NSKeyedUnarchiverで解凍してDictに
#macOS13まで
#set ocidArchveDict to (refMe's NSKeyedUnarchiver's unarchiveObjectWithData:(ocidPlistData))
#macOS14から
set listReadUnarchiver to (refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidPlistData) |error|:(reference))
set ocidArchveDict to (item 1 of listReadUnarchiver)
###【2】可変Dictにセット
set ocidReplaceDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidReplaceDict's setDictionary:ocidArchveDict)
###ALLkeys
set ocidAllKeysArray to ocidReplaceDict's allKeys()
#######################################
### items の処理
#######################################
###【3】items のArrayを取り出して
set ocidItemsArray to (ocidReplaceDict's objectForKey:("items"))
set ocidSaveString to refMe's NSMutableString's alloc()'s initWithCapacity:0

repeat with itemArray in ocidItemsArray
  set ocidBookMarkData to (itemArray's objectForKey:("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)
  if ocidBookMarkURL ≠ (missing value) then
    set strSetValue to ocidBookMarkURL's absoluteString() as text
(ocidSaveString's appendString:(strSetValue))
(ocidSaveString's appendString:("\n"))
  end if
end repeat
#######################################
### 戻り値
#######################################
set aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" 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 strMes to ("BookMarkエイリアスの戻り値です") as text
try
  set recordResult to (display dialog strMes with title strMes default answer (ocidSaveString as text) buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer) as record
on error
log "エラーしました"
end try
if (gave up of recordResult) is true then
return "時間切れです"
end if
##############################
#####値のコピー
##############################
if button returned of recordResult is "クリップボードにコピー" then
  try
    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)
  on error
    tell application "Finder"
      set the clipboard to strText as text
    end tell
  end try
end if



|

[LSSharedFileList] unarchivedObjectOfClassesで解凍する


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

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

property refMe : a reference to current application



set strFilePath to ("~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.RecentServers.sfl3") as text

set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)

set ocidPlistData to (refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL))

####
# unarchivedObjectOfClasses

set ocidSetClass to refMe's NSSet's alloc()'s initWithArray:{(refMe's NSObject's classForKeyedUnarchiver), (refMe's NSMutableDictionary), (refMe's NSDictionary), (refMe's NSObject's classForCoder), (refMe's NSObject's classForKeyedArchiver)}
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClasses:(ocidSetClass) fromData:(ocidPlistData) |error|:(reference)
set ocidPlistDict to (item 1 of listResponse)
log ocidPlistDict's allKeys() as list

####
# unarchivedObjectOfClass

set ocidSetClass to (refMe's NSObject)'s class
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:(ocidSetClass) fromData:(ocidPlistData) |error|:(reference)
set ocidPlistDict to (item 1 of listResponse)
log ocidPlistDict's allKeys() as list


set ocidSetClass to (refMe's NSObject's classForCoder)
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:(ocidSetClass) fromData:(ocidPlistData) |error|:(reference)
set ocidPlistDict to (item 1 of listResponse)
log ocidPlistDict's allKeys() as list

set ocidSetClass to (refMe's NSObject's classForArchiver)
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:(ocidSetClass) fromData:(ocidPlistData) |error|:(reference)
set ocidPlistDict to (item 1 of listResponse)
log ocidPlistDict's allKeys() as list


set ocidSetClass to (refMe's NSObject's classForKeyedArchiver)
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:(ocidSetClass) fromData:(ocidPlistData) |error|:(reference)
set ocidPlistDict to (item 1 of listResponse)
log ocidPlistDict's allKeys() as list


set ocidSetClass to (refMe's NSObject's classForKeyedUnarchiver)
set listResponse to refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:(ocidSetClass) fromData:(ocidPlistData) |error|:(reference)
set ocidPlistDict to (item 1 of listResponse)
log ocidPlistDict's allKeys() as list


|

[FavoriteItems.sfl3]Finderサイドバーにフォルダを追加(macOS14対応版)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#com.cocolog-nifty.quicktimer.icefloe
#
# Finderサイドバーにフォルダを追加します
# よく使う項目にiCloudを追加する
----+----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


#######################################
##追加するフォルダを選択
#Finder上の表示はiCloud Driveになっていますが実名はMobile Documents
set strFilePath to "~/Library/Mobile Documents" as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set aliasDefaultLocation to (ocidFilePathURL's absoluteURL()) as alias


#######################################
###ダイアログ
tell current application
  set strName to name as text
end tell
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
###
set strMes to "フォルダを選んでください" as text
set strPrompt to "サイドバーに追加したいフォルダを\n選択してください" as text
try
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation without multiple selections allowed, invisibles and showing package contents) as alias
on error
log "エラーしました"
return
end try
###URLにしておく
set strAddDirPath to (POSIX path of aliasResponse) as text
set strAddDirPathStr to refMe's NSString's stringWithString:(strAddDirPath)
set strAddDirPath to strAddDirPathStr's stringByStandardizingPath()
set strAddDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(strAddDirPath) isDirectory:false)
log strAddDirPathURL's absoluteString() as text
###ローカライズ名があれば取得する
set listAttributesDict to strAddDirPathURL's resourceValuesForKeys:({refMe's NSURLLocalizedNameKey}) |error|:(reference)
set ocidAttributesDict to (item 1 of listAttributesDict)
set ocidLocalizedName to (ocidAttributesDict's objectForKey:(refMe's NSURLLocalizedNameKey))
log ocidLocalizedName as text

#######################################
###処理するファイル名
set strSfl3FileName to "com.apple.LSSharedFileList.FavoriteItems.sfl3" as text

#######################################
##SFL3ファイルパスURL
#######################################
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 ocidContainerPathURL to (ocidAppSuppDirPathURL's URLByAppendingPathComponent:("com.apple.sharedfilelist") isDirectory:true)
set ocidSfl3FilePathURL to (ocidContainerPathURL's URLByAppendingPathComponent:(strSfl3FileName) isDirectory:false)

#######################################
##NSdataに読み込み Keyを解凍する
#######################################
###【1】NSDataに読み込む
set ocidOption to (refMe's NSDataReadingMappedIfSafe)
set listReadData to refMe's NSData's dataWithContentsOfURL:(ocidSfl3FilePathURL) options:(ocidOption) |error|:(reference)
set ocidPlistData to (item 1 of listReadData)
###【2】NSKeyedUnarchiverで解凍してDictに
#macOS13まで
#set ocidArchveDict to (refMe's NSKeyedUnarchiver's unarchiveObjectWithData:(ocidPlistData))
#macOS14から
set listReadUnarchiver to (refMe's NSKeyedUnarchiver's unarchivedObjectOfClass:((refMe's NSObject)'s class) fromData:(ocidPlistData) |error|:(reference))
set ocidArchveDict to (item 1 of listReadUnarchiver)
###【2】可変Dictにセット
set ocidReplaceDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
ocidReplaceDict's setDictionary:(ocidArchveDict)
# set ocidAllKeysArray to ocidReplaceDict's allKeys()
###【3】items のArrayを取り出して
set ocidItemsArray to (ocidReplaceDict's objectForKey:("items"))
#↑の数
set numCntItems to (count of ocidItemsArray) as integer
#######################################
###ダイアログ
set listChooseNo to {} as list
repeat with itemIntNo from 1 to (numCntItems + 1) by 1
  set end of listChooseNo to itemIntNo
end repeat
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 strTitle to ("選んでください") as text
set strPrompt to ("何番目に設定するか?\n上から何番目?") as text
try
  set listResponse to (choose from list listChooseNo with title strTitle with prompt strPrompt default items (last item of listChooseNo) OK button name "OK" 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 "キャンセルしましたA"
else if (item 1 of listResponse) is "キャンセル" then
return "キャンセルしましたB"
else
  #セットするポジション(0ベースの数値)
  set numPosisionNo to ((item 1 of listResponse) - 1) as integer
end if

#######################################
### items の処理
#######################################
###【3】items のArrayを取り出して
set ocidItemsArray to (ocidReplaceDict's objectForKey:("items"))

###【4】項目入替用のArray
set ocidReplaceArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
(ocidReplaceArray's setArray:ocidItemsArray)

###【5】項目追加用のDict
set ocidAddDictM to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
###【5-1】boolmark
set listBookMarkData to (strAddDirPathURL's bookmarkDataWithOptions:(11) includingResourceValuesForKeys:({missing value}) relativeToURL:(missing value) |error|:(reference))
set ocidBookMarkData to item 1 of listBookMarkData
(ocidAddDictM's setObject:(ocidBookMarkData) forKey:("Bookmark"))

###【5-2】 visibility = 0
set ocidAddVisibility to (refMe's NSNumber's numberWithInteger:0)
(ocidAddDictM's setValue:(ocidAddVisibility) forKey:("visibility"))

###【5-3】 UUIDは新規生成しているが、本当は?別な方法か?
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDStr to ocidUUID's UUIDString()
(ocidAddDictM's setValue:(ocidUUIDStr) forKey:("uuid"))

###【5-4】 Name ocidLocalizedName 追加しても無視される?
set ocidNamestr to (refMe's NSString's stringWithString:(ocidLocalizedName))
(ocidAddDictM's setValue:(ocidNamestr) forKey:("Name"))

###【5-5】 CustomItemProperties
set ocidPropertiesDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
set ocidBoolValue to (refMe's NSNumber's numberWithBool:true)
ocidPropertiesDict's setValue:(ocidBoolValue) forKey:("kLSSharedFileListItemIsiCloudLibrary")
(ocidAddDictM's setObject:(ocidPropertiesDict) forKey:("CustomItemProperties"))

####【6】5のDICTを4項目追加用のArrayに指定した場所に追加して
(ocidReplaceArray's insertObject:(ocidAddDictM) atIndex:(numPosisionNo))

####【7】2可変Dictに4の新しいArrayを"items"としてセット
(ocidReplaceDict's setObject:(ocidReplaceArray) forKey:("items"))

####【8】properties のDictを取り出して
set ocidPropertiesDict to (ocidReplaceDict's objectForKey:"properties")
###【8−1】項目入替用のDict
set ocidPropertiesDictM to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertiesDictM's setDictionary:ocidPropertiesDict)
###【8−2】テンプレートアイコンの使用をONに
set ocidBoolValue to (refMe's NSNumber's numberWithBool:true)
(ocidPropertiesDictM's setValue:(ocidBoolValue) forKey:("com.apple.LSSharedFileList.ForceTemplateIcons"))
###2可変Dictに8の新しいDictをセット
(ocidReplaceDict's setObject:(ocidPropertiesDictM) forKey:("properties"))

#######################################
### 値が新しくなった解凍済みDictをアーカイブする
#######################################
##【9】NSKeyedArchiverでアーカイブ圧縮する
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

#######################################
### リロード
#######################################

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


return

|

より以前の記事一覧

その他のカテゴリー

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