AppleScript XML Plist

[Json]PlistをJsonに変換する(NSTaggedDate対策入り)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
日付データNSTaggedDateをstringに置換してから
PLISTデータをJSON形式にします
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


####ダイアログで使うデフォルトロケーション
tell application "Finder"
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
end tell
####UTIリスト
set listUTI to {"com.apple.property-list", "public.xml"}
####ダイアログを出す
set aliasFilePath to (choose file with prompt "ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias

set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)
set ocidFileName to ocidFilePathURL's lastPathComponent()
##########################################
###【1】テンポラリディレクトリとパス
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
if (item 1 of listDone) is true then
  #テンポラリファイル
  set ocidTmpFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false
log "【1】正常終了"
else if (item 1 of listDone) is false then
log (item 2 of listDone)'s localizedDescription() as text
return "【1】失敗しました"
end if


##########################################
### 【2】PLISTファイルをNSDATAとして読み込み
(* NSDataReadingOptions
(*1*)log refMe's NSDataReadingMappedIfSafe as integer
(*2*)log refMe's NSDataReadingUncached as integer
(*8*)log refMe's NSDataReadingMappedAlways as integer
*)
set listReadData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSDataReadingMappedIfSafe) |error|:(reference)
if (item 2 of listReadData) is (missing value) then
  set coidReadData to (item 1 of listReadData)
log " 【2】正常終了"
else
log (item 2 of listReadData)'s localizedDescription() as text
return " 【2】失敗しました"
end if


##########################################
####【3】PLISTに変換 (optionは 0-2 Immutable /MutableContainers /MutableContainersAndLeaves)
set ocidXmlPlist to refMe's NSPropertyListXMLFormat_v1_0
set ocidPlistSerial to refMe's NSPropertyListSerialization
set ocidOption to refMe's NSPropertyListMutableContainersAndLeaves
set listPlistDict to ocidPlistSerial's propertyListWithData:(coidReadData) options:(ocidOption) format:(ocidXmlPlist) |error|:(reference)
if (item 2 of listPlistDict) is (missing value) then
  set ocidPlistDict to (item 1 of listPlistDict)
log "【3】正常終了"
else
log (item 2 of listPlistDict)'s localizedDescription() as text
return "【3】失敗しました"
end if


##########################################
####【4】テンポラリファイルを保存
set ocidOption to (refMe's NSDataWritingWithoutOverwriting)
set listDone to ocidPlistDict's writeToURL:(ocidTmpFilePathURL) |error|:(reference)
if (item 1 of listDone) is true then
log "【4】正常終了"
else if (item 1 of listDone) is false then
log (item 2 of listDone)'s localizedDescription() as text
return "【4】失敗しました"
end if
##########################################
####【5】テンポラリのPLISTの『フォーマット』を変更
set listReadString to refMe's NSMutableString's alloc()'s initWithContentsOfURL:(ocidTmpFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
if (item 2 of listReadString) is (missing value) then
  set ocidReadString to (item 1 of listReadString)
log "【5-1】正常終了"
else
log (item 2 of listReadString)'s localizedDescription() as text
return "【5-1】失敗しました"
end if
##置換
set ocidSaveString to ocidReadString's stringByReplacingOccurrencesOfString:("<date>") withString:("<string>")
set ocidSaveString to ocidSaveString's stringByReplacingOccurrencesOfString:("</date>") withString:("</string>")
set ocidSaveString to ocidSaveString's stringByReplacingOccurrencesOfString:("<data>") withString:("<string>")
set ocidSaveString to ocidSaveString's stringByReplacingOccurrencesOfString:("</data>") withString:("</string>")
##上書き保存
set listDone to ocidSaveString's writeToURL:(ocidTmpFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
if (item 1 of listDone) is true then
log "【5-2】正常終了"
else if (item 1 of listDone) is false then
log (item 2 of listDone)'s localizedDescription() as text
return "【5-2】失敗しました"
end if
##########################################
### 【6】PLISTファイルをNSDATAとして読み込み
set listReadTmpData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidTmpFilePathURL) options:(refMe's NSDataReadingMappedIfSafe) |error|:(reference)
if (item 2 of listReadTmpData) is (missing value) then
  set ocidReadTmpData to (item 1 of listReadTmpData)
log "【6】正常終了"
else
log (item 2 of listReadTmpData)'s localizedDescription() as text
return "【6】失敗しました"
end if
##########################################
####【7】PLISTに変換 (optionは 0-2 Immutable /MutableContainers /MutableContainersAndLeaves)
set ocidXmlPlist to refMe's NSPropertyListXMLFormat_v1_0
set ocidPlistSerial to refMe's NSPropertyListSerialization
set ocidOption to refMe's NSPropertyListMutableContainersAndLeaves
set listPlistDict to ocidPlistSerial's propertyListWithData:(ocidReadTmpData) options:(ocidOption) format:(ocidXmlPlist) |error|:(reference)
if (item 2 of listPlistDict) is (missing value) then
  set ocidPlistDict to (item 1 of listPlistDict)
log "【7】正常終了"
else
log (item 2 of listPlistDict)'s localizedDescription() as text
return "【7】失敗しました"
end if

##########################################
### 【8】JSON初期化
(* NSJSONReadingOptions
(*1*)log refMe's NSJSONReadingMutableContainers as integer
(*2*)log refMe's NSJSONReadingMutableLeaves as integer
(*4*)log refMe's NSJSONReadingFragmentsAllowed as integer
(*8*)log refMe's NSJSONReadingJSON5Allowed as integer
(*16*)log refMe's NSJSONReadingTopLevelDictionaryAssumed as integer
*)
set listJSONSerialization to (refMe's NSJSONSerialization's dataWithJSONObject:(ocidPlistDict) options:(refMe's NSJSONReadingJSON5Allowed) |error|:(reference))
if (item 2 of listJSONSerialization) is (missing value) then
  set ocidJsonData to (item 1 of listJSONSerialization)
log "【8】正常終了"
else
log (item 2 of listJSONSerialization)'s localizedDescription() as text
return "【8】失敗しました"
end if


##########################################
####【9】保存
###保存先パスをURLを生成して
set ocidBaseFileURL to ocidFilePathURL's URLByDeletingPathExtension()
set ocidSaveFilePathURL to ocidBaseFileURL's URLByAppendingPathExtension:"json"
###保存
set ocidOption to (refMe's NSDataWritingAtomic)
set listDone to ocidJsonData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
if (item 1 of listDone) is true then
log "【9】正常終了"
else if (item 1 of listDone) is false then
log (item 2 of listDone)'s localizedDescription() as text
return "【9】失敗しました"
end if

return "処理終了"

|

[Plist]Plistの値の変更 writeToURL:atomicallyが非推奨→ writeToURL:errorに変更


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

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

property refMe : a reference to current application

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


##########################################
###【1】ドキュメントのパス
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
set ocidPreferencesDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences")
set ocidFilePathURL to ocidPreferencesDirPathURL's URLByAppendingPathComponent:("com.apple.finder.plist")
set strDateNo to doGetDateNo("yyyyMMdd") as text
set strSetValue to ("com.apple.finder." & strDateNo & ".plist")
set ocidBackupFilePathURL to ocidPreferencesDirPathURL's URLByAppendingPathComponent:(strSetValue)
#バックアップ作成
# set listDone to appFileManager's copyItemAtURL:(ocidFilePathURL) toURL:(ocidBackupFilePathURL) |error|:(reference)

#
##########################################
### 【2】PLISTを可変レコードとして読み込み
set listPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference)
set ocidPlistDict to (item 1 of listPlistDict)
##########################################
#設定する値
set listAddItem to {"com_apple_ats_name_postscript", "com_apple_ats_name_full", "com_apple_ats_name_family", "com_apple_ats_name_style", "com_apple_ats_name_fond"} as list

###【3】値の編集
set coidSlicesRootAttributesArray to ocidPlistDict's objectForKey:("SlicesRootAttributes")
###値がすでに設定済みでないか?確認して
repeat with itemList in listAddItem
  set boolContain to (coidSlicesRootAttributesArray's containsObject:(itemList))
  ##値がなければ追加
  if boolContain is false then
log "追加します"
    ##Arrayに追加
(coidSlicesRootAttributesArray's addObject:(itemList))
  end if
end repeat
##########################################
### 【4】保存
# writeToURL:atomically:がDeprecatedになったので
# writeToURL:error:を使います(macOS14対応)

set listDone to ocidPlistDict's writeToURL:(ocidFilePathURL) |error|:(reference)
if (item 1 of listDone) is true then
return "正常終了"
else if (item 1 of listDone) is false then
return "保存に失敗しました"
end if


to doGetDateNo(strDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
ocidNSDateFormatter's setDateFormat:strDateFormat
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo

|

[Plist]Plist まとめ



A:入力
B:編集
C:出力
D:備考


A:入力
1:DATA
[Plist]NSDATAを使って読み込む
https://quicktimer.cocolog-nifty.com/icefloe/2023/07/post-14ff50.html
2:Dict
[PLIST]値の取得 基本
https://quicktimer.cocolog-nifty.com/icefloe/2023/06/post-46307d.html
3:キーアーカイブ
セキュリティ上の理由もあるが
NSURL等 PLISTには保存できない形式も保存が可能
[基本]NSKeyedArchiver
https://quicktimer.cocolog-nifty.com/icefloe/cat76056161/index.html
NSKeyedUnarchiver
https://quicktimer.cocolog-nifty.com/icefloe/cat76055043/index.html
4:ファイルから
[PLIST]値の取得 基本 その1 plistを読み込んでPlistで保存
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-e591c4.html
[plutil]Plistのフォーマット変更(サービスメニュー用)
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-4fcfa5.html
5:JSON
[JSON]JSONの取扱 その1(rootがDict形式の場合
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-7ac684.html
[JSON]JSONの取扱 その2(rootがArray形式の場合)
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-0ed292.html
その他
https://quicktimer.cocolog-nifty.com/icefloe/cat76049735/index.html


B:編集
[PLIST]値の取得 基本
https://quicktimer.cocolog-nifty.com/icefloe/2023/06/post-46307d.html
1: /usr/bin/defaults
[Plist]defaults read
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-035836.html
[Plist]defaults write
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-8926ec.html
2: /usr/libexec/PlistBuddy
https://quicktimer.cocolog-nifty.com/icefloe/cat76027586/index.html
3: /usr/bin/plutil
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-892166.html
4: /usr/bin/xmllint
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-c9efbb.html
5: AppleScript System Events
https://quicktimer.cocolog-nifty.com/icefloe/cat76056176/index.html
6: AppleScript Oc
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-e591c4.html
7:Xcode
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-cdefb1.html
8:Visual Studio Code
https://quicktimer.cocolog-nifty.com/icefloe/2023/09/post-d25c0e.html


C:出力
NSDATA
writeToURL:options:error:
writeToURL:atomically: での保存になります
Plistはバイナリー形式が基本です。アクセスや読み込みが速いからかな?と思います
1:バイナリ

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

set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0)
set ocidPlistData to refMe's NSPropertyListSerialization's dataWithPropertyList:("ここにDICTデータ") format:(ocidFormat) options:0 |error|:(reference)


2: XMLモバイルコンフィグ等XMLであった方が編集しやすい時は迷わずこちら

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

set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0)
set ocidPlistData to refMe's NSPropertyListSerialization's dataWithPropertyList:("ここにDICTデータ") format:(ocidFormat) options:0 |error|:(reference)


3:キーアーカイブ
[基本]NSKeyedArchiver 圧縮
https://quicktimer.cocolog-nifty.com/icefloe/cat76056161/index.html

カテゴリー 解凍 NSKeyedUnarchiver
https://quicktimer.cocolog-nifty.com/icefloe/cat76055043/index.html
4:JSON
https://quicktimer.cocolog-nifty.com/icefloe/cat76049735/index.html



D:備考
mobileconfigは中身はPLIST
[mobileconfig]AppleScriptでの処理の基本(再考)
https://quicktimer.cocolog-nifty.com/icefloe/2022/05/post-9dad8c.html
LSSharedFileListはキーアーカイブされたPLIST
AppleScript LSSharedFileList
https://quicktimer.cocolog-nifty.com/icefloe/cat76055054/index.html
検索条件を記録してあるsavedSearchもPLIST
[savedSearch]検索条件ファイルを作成する
https://quicktimer.cocolog-nifty.com/icefloe/2023/06/post-e476bb.html


[Webloc]ロケーションファイル(com.apple.generic-internet-location)もPLIST
インターネット・ロケーションファイルまとめ
https://quicktimer.cocolog-nifty.com/icefloe/cat76053046/index.html


plutil defaults PlistBuddyの文法の比較


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#
#plutil
STR_USR_LANG=$(/usr/bin/plutil -extract AppleLanguages.0 raw -expect string $HOME/Library/Preferences/.GlobalPreferences.plist ) 
/bin/echo "plutil:ユーザー設定の第1言語は $STR_USR_LANG です"
#defaults
STR_USR_LANG=$(/usr/bin/defaults read $HOME/Library/Preferences/.GlobalPreferences AppleLanguages| tr -d "[:space:][(][)]\""|cut -d , -f 1 )
/bin/echo "defaults:ユーザー設定の第1言語は $STR_USR_LANG です"
#PlistBuddy
STR_USR_LANG=$(/usr/libexec/PlistBuddy -c "Print:AppleLanguages:0" "$HOME/Library/Preferences/.GlobalPreferences.plist")
/bin/echo "PlistBuddy:ユーザー設定の第1言語は $STR_USR_LANG です"

exit 0




Serialization004_20231028110801


Screen-20231028-110332

|

[LSSharedFileList]Finderサイドバーのよく使う項目を追加する

20240312072816_1272x780

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
サーバーに接続の
よく使うサーバーを追加します
macOS14以降のsfl3版です
AirDrop
nwnode://domain-AirDrop
一部個別のスキームがあります

*)
----+----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 strAddDirPath to ("~/Downloads") as text

###
set ocidAddDirPathStr to refMe's NSString's stringWithString:(strAddDirPath)
set ocidAddDirPath to ocidAddDirPathStr's stringByStandardizingPath()
set ocidAddDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAddDirPath) isDirectory:false)
set strAddDirPath to ocidAddDirPathURL's absoluteString() as text

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

#######################################
### items の処理
#######################################
### items のArrayを取り出して Flozenなので値を変更するために 可変に変えます
set ocidItemsArray to (ocidArchveDictM's objectForKey:("items"))
### 項目入替用のArray 
set ocidItemsArrayM to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
(ocidItemsArrayM's setArray:ocidItemsArray)
set numCntArrayItem to count of ocidItemsArray
#######################################
### 値がすでにあるか?確認
set boolChkTagName to (missing value)
##################
###itemsの数だけ繰り返し
repeat with itemsArrayDict in ocidItemsArrayM
  ####
  set ocidBookMarkData to (itemsArrayDict's objectForKey:("Bookmark"))
  #BOOKMarkデータの解凍
  set listResponse to (refMe's NSURL's URLByResolvingBookmarkData:(ocidBookMarkData) options:(refMe's NSURLBookmarkResolutionWithoutUI) relativeToURL:(missing value) bookmarkDataIsStale:(missing value) |error|:(reference))
  set ocidBookMarkURL to (item 1 of listResponse)
  set strBookMarkPath to ocidBookMarkURL's absoluteString() as text
  ##
  if strAddDirPath is strBookMarkPath then
    ###値があった場合
    set boolChkTagName to true as boolean
    exit repeat
  else
    ###なかった場合
    set boolChkTagName to false as boolean
  end if
end repeat

#######################################
### 本処理項目の追加
#######################################

###なければ追加
if boolChkTagName is false then
  ######## 【1】項目追加用のDict
  set ocidAddDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  ######## CustomItemProperties
  #【2】CustomItemProperties用のDICT
  set ocidCustomPropertiesDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  # 0=true 1=false
  set ocidSetValue to (refMe's NSNumber's numberWithInteger:1)
ocidCustomPropertiesDict's setValue:(ocidSetValue) forKey:("com.apple.LSSharedFileList.ItemIsHidden")
  # 0=true 1=false
  set ocidSetValue to (refMe's NSNumber's numberWithInteger:0)
ocidCustomPropertiesDict's setValue:(ocidSetValue) forKey:("com.apple.finder.dontshowonreappearance")
  
  #【1】のDICTに追加
ocidAddDict's setObject:(ocidCustomPropertiesDict) forKey:("CustomItemProperties")
  ######## 追加用のDict root
  ## uuid
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString()
ocidAddDict's setValue:(ocidUUIDString) forKey:("uuid")
  ## visibility
  set ocidVisibility to refMe's NSNumber's numberWithInteger:(0)
ocidAddDict's setValue:(ocidVisibility) forKey:("visibility")
  ## Bookmark
  set listBookMarkData to (ocidAddDirPathURL's bookmarkDataWithOptions:(11) includingResourceValuesForKeys:({missing value}) relativeToURL:(missing value) |error|:(reference))
  set ocidBookMarkData to (item 1 of listBookMarkData)
ocidAddDict's setObject:(ocidBookMarkData) forKey:("Bookmark")
  
  ##itemsのArrayに追加
ocidItemsArrayM's addObject:(ocidAddDict)
end if
### RootにItemsを追加
(ocidArchveDictM's setObject:(ocidItemsArrayM) forKey:("items"))

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

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

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

return


|

[NSKeyedArchiver]plistをsfl3形式にKeyedArchiveする


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

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

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

###################################
#####ファイル選択ダイアログ
###################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
####ダイアログを出す
set listUTI to {"com.apple.property-list"} as list
set aliasFilePath to (choose file with prompt "plistファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
####入力ファイルパス
set strFilePath to POSIX path of aliasFilePath
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
set ocidPrefixName to ocidBaseFilePathURL's lastPathComponent()
###################################
#####保存先ダイアログ
###################################
###ファイル名
set strPrefixName to ocidPrefixName as text
###拡張子変える場合
set strFileExtension to "sfl3"
###ダイアログに出すファイル名
set strDefaultName to (strPrefixName & "." & strFileExtension) as text
set strPromptText to "名前を決めてください"
set strMesText to "名前を決めてください"
####
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias

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

###################################
#####本処理
###################################
# DICTに読み込んで
set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference)
set ocidReadData to (item 1 of listResponse)
#アーカイブする
#
set listResponse to refMe's NSKeyedArchiver's archivedDataWithRootObject:(ocidReadData) 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:(ocidSaveFilePathURL) options:0 |error|:(reference)



|

[NSKeyedUnarchiver]com.apple.LSSharedFileListのBookMarkデータを表示(macOS14対応)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.apple.LSSharedFileListのBookMarkデータを表示します
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application

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

###################################
#####ファイル選択ダイアログ
###################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
####ダイアログを出す
set listUTI to {"com.apple.property-list", "dyn.ah62d4rv4ge81g3xqgq"} as list
set aliasFilePath to (choose file with prompt "plistファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
####入力ファイルパス
set strFilePath to POSIX path of aliasFilePath
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set strExtensionName to (ocidFilePathURL's pathExtension()) as text

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

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



|

[unarchivedObjectOfClass]sfl3(LSSharedFileList)を解凍してplistに変換保存する(sfl3ToPlist)


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

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

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

###################################
#####ファイル選択ダイアログ
###################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLArray to appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)
set ocidAppSuppDirPathURL to ocidURLArray's firstObject()
set strAppendPath to ("com.apple.sharedfilelist") as text
set ocidDefaultLocationURL to ocidAppSuppDirPathURL's URLByAppendingPathComponent:(strAppendPath) isDirectory:false
set aliasDefaultLocation to (ocidDefaultLocationURL's absoluteURL()) as alias
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
activate
  end tell
else
  tell current application
activate
  end tell
end if
####ダイアログを出す
set listUTI to {"public.item", "dyn.ah62d4rv4ge81g3xqgk", "dyn.ah62d4rv4ge81g3xqgq"} as list
set aliasFilePath to (choose file with prompt "sfl3ファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
####入力ファイルパス
set strFilePath to POSIX path of aliasFilePath
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
set ocidPrefixName to ocidBaseFilePathURL's lastPathComponent()
###################################
#####保存先ダイアログ
###################################
###ファイル名
set strPrefixName to ocidPrefixName as text
###拡張子変える場合
set strFileExtension to "plist"
###ダイアログに出すファイル名
set strDefaultName to (strPrefixName & "." & strFileExtension) as text
set strPromptText to "名前を決めてください"
set strMesText to "名前を決めてください"
####
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias

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

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



|

InfoPlist.loctableの内容をタブ区切りテキストにする


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

#!/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 listTypeKey to {"Burn Folder", "smart folder", "iOS Package Archive", "Saved Search Query", "Predefined Search", "FTP Internet Location", "AFP URL", "Internet Location", "File URL", "File Internet Location", "Mail Internet Location", "Text Clipping", "Web Internet Location", "FTP URL", "AppleTalk Internet Location", "AFP Internet Location", "Apple Device Software Update File", "CFBundleDisplayName", "Folder", "NSL Internet Location", "Picture Clipping", "News Internet Location", "Sound Clipping", "Clipping", "Volume"} as list



set strFilePath to ("/System/Library/CoreServices/Finder.app/Contents/Resources/InfoPlist.loctable") as text
##########################################
###【1】ドキュメントのパス
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:(ocidFilePath)

##########################################
### 【2】PLISTを可変レコードとして読み込み
set listPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error|:(reference)
set ocidPlistDict to (item 1 of listPlistDict)

##########################################
### 出力用のテキスト
set ocidOutPutText to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidOutPutText's appendString:("\")
ocidOutPutText's appendString:("\t")

##########################################
### 【3】AllKeyを取得してKyeの数だけ繰り返し(見出し行)
set ocidLocationKey to ocidPlistDict's allKeys()
set ocidArrayM to refMe's NSMutableArray's arrayWithArray:(ocidLocationKey)
set ocidLocationArray to ocidArrayM's sortedArrayUsingSelector:("caseInsensitiveCompare:")
repeat with itemLocationKey in ocidLocationArray
  ###ロケーション取得
  set ocidLocation to itemLocationKey
(ocidOutPutText's appendString:(ocidLocation))
(ocidOutPutText's appendString:("\t"))
end repeat

(ocidOutPutText's appendString:("\n"))
##########################################
###
repeat with itemTypeKey in listTypeKey
(ocidOutPutText's appendString:(itemTypeKey))
(ocidOutPutText's appendString:("\t"))
  repeat with itemLocationKey in ocidLocationArray
    set ocidLocDict to (ocidPlistDict's objectForKey:(itemLocationKey))
    set ocidValue to (ocidLocDict's valueForKey:(itemTypeKey))
    if ocidValue = (missing value) then
(ocidOutPutText's appendString:(" "))
(ocidOutPutText's appendString:("\t"))
    else
(ocidOutPutText's appendString:(ocidValue))
(ocidOutPutText's appendString:("\t"))
    end if
  end repeat
(ocidOutPutText's appendString:("\n"))
end repeat
#####
set ocidLength to ocidOutPutText's |length|()
set ocidRange to refMe's NSMakeRange(0, ocidLength)
set ocidOption to (refMe's NSCaseInsensitiveSearch)
ocidOutPutText's replaceOccurrencesOfString:("\t\n") withString:("\n") options:(ocidOption) range:(ocidRange)

##########################################
###保存先
##ファイル名取得
set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
set ocidBaseFileName to ocidBaseFilePathURL's lastPathComponent()
##デスクトップに保存
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
##ファイル名を追加
set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(ocidBaseFileName)
##拡張子を追加
set ocidSaveFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:("tsv")
##保存
set listDone to ocidOutPutText's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)



|

[XML]PlistをXMLとして作成する

PlistはDictにすべし!XMLで処理するのは無駄

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

#!/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 "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


###【1】保存先ファイルパス
###デスクトップ
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
###保存ファイルURL
set strFileName to ("test.plist") as text
set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)

###【2】XML生成
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setVersion:"1.0"
ocidXMLDoc's setCharacterEncoding:"UTF-8"
(*
NSXMLDocumentXMLKind: XML形式
NSXMLDocumentXHTMLKind: XHTML形式の
NSXMLDocumentHTMLKind: HTML形式の
NSXMLDocumentTextKind: プレーンテキスト形式
*)
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentXMLKind)

###【3】DTD生成
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:"plist"
ocidDTD's setPublicID:"-//Apple//DTD PLIST 1.0//EN"
ocidDTD's setSystemID:("http://www.apple.com/DTDs/PropertyList-1.0.dtd")
####【3-1】DTDをXMLにセットする
ocidXMLDoc's setDTD:(ocidDTD)

###【4】ROOTエレメントを生成
set ocidRootElement to refMe's NSXMLElement's elementWithName:("plist")
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.0"))
###【4-1】rootのDictionaryを生成
set ocidRootDictElement to refMe's NSXMLElement's alloc()'s initWithName:("dict")
###サンプルのエレメントを生成
set ocidKey to refMe's NSXMLElement's elementWithName:("key") stringValue:("SampleText")
set ocidValue to refMe's NSXMLElement's elementWithName:("string") stringValue:("美しい日本語")
###サンプルのエレメントをセット
ocidRootDictElement's addChild:(ocidKey)
ocidRootDictElement's addChild:(ocidValue)
###【4-2】rootのDictionaryを子要素としてROOTエレメントに追加
ocidRootElement's addChild:(ocidRootDictElement)
###【4-3】ROOTエレメントXMLにセットする
ocidXMLDoc's setRootElement:(ocidRootElement)
###【5】XMLデータにして(ここでテキスト形式のXMLに)
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
###【6】ファイルに保存
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)


return


|

[com.apple.finder] SlicesRootAttributes その2

 

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

#!/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 appFileManager to refMe's NSFileManager's defaultManager()


##########################################
###【1】ドキュメントのパスをNSString
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
##テスト用
##set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.finder.test.plist")
set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/com.apple.finder.plist")
##########################################
### 【2】PLISTを可変レコードとして読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL)

##########################################
### 【3】処理はここで
set ocidSlicesRootArray to (ocidPlistDict's objectForKey:("SlicesRootAttributes"))
if ocidSlicesRootArray = (missing value) then
log "未設定なので設定します"
  set listkMDitem to {"kMDItemKind", "kMDItemLastUsedDate", "kMDItemContentModificationDate", "kMDItemContentCreationDate", "kMDItemDisplayName", "kMDItemTextContent", "com_apple_FileExtensionAttribute", "kMDItemFSInvisible", "kMDItemBitsPerSample", "kMDItemFSName", "kMDItemFSSize", "kMDItemPixelCount", "kMDItemOrientation", "kMDItemDurationSeconds", "kMDItemPixelWidth", "kMDItemPixelHeight", "kMDItemFSLabel", "kMDItemMediaTypes", "kMDItemColorSpace", "kMDItemFonts", "kMDItemPageWidth", "kMDItemFSContentChangeDate", "kMDItemFSCreationDate", "kMDItemEmailAddresses", "kMDItemPageHeight", "kMDItemFSNodeCount", "kMDItemLayerNames"} as list
  set ocidSlicesRootArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidSlicesRootArray's setArray:(listkMDitem)
ocidPlistDict's setObject:(ocidSlicesRootArray) forKey:("SlicesRootAttributes")
else
  ###項目の有無確認 ラベル追加
  set strTBID to ("kMDItemFSLabel") as text
  set boolValue to ocidSlicesRootArray's containsObject:(strTBID)
  if boolValue = false then
log "未設定なので設定します"
    set ocidSetValue to refMe's NSString's stringWithString:(strTBID)
ocidSlicesRootArray's addObject:(ocidSetValue)
  else
log "すでに設定済み"
  end if
end if
###項目の有無確認 タグ追加
set strTBID to ("kMDItemUserTags") as text
set boolValue to ocidSlicesRootArray's containsObject:(strTBID)
if boolValue = false then
log "未設定なので設定します"
  set ocidSetValue to refMe's NSString's stringWithString:(strTBID)
ocidSlicesRootArray's addObject:(ocidSetValue)
else
log "すでに設定済み"
end if
##########################################
####【4】保存 ここは上書き
set boolDone to ocidPlistDict's writeToURL:(ocidPlistFilePathURL) atomically:true
-->システムファイルなの書き込めないので書き込み失敗でfalseが返る
log boolDone


##########################################
####【5】リロード

if boolDone = true then
  tell application "Finder" to quit
  repeat 1 times
delay 1
    #####CFPreferencesを再起動
    set strCommandText to "/usr/bin/killall cfprefsd" as text
do shell script strCommandText
delay 1
  end repeat
  
  tell application "Finder" to activate
return "正常終了"
else
return "保存に失敗しました"
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