PlistBuddy

[bash][PlistBuddy]基本設定unarchiver


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#####################################

LIST_BUNDLEID=("com.macpaw.site.theunarchiver.plist" "cx.c3.theunarchiver.plist")

for ITEM_BUNDLEID in "${LIST_BUNDLEID[@]}"; do
/bin/echo "$ITEM_BUNDLEID"
STR_PLIST_FILEPATH="$HOME/Library/Preferences/$ITEM_BUNDLEID"
/bin/echo "$STR_PLIST_FILEPATH"
  if [ -e "STR_PLIST_FILEPATH" ]; then
/usr/libexec/PlistBuddy -c "Save" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:createFolder" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" -ne 2 ]; then
/usr/libexec/PlistBuddy -c "Set:createFolder 2" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:createFolder integer 2" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:extractionDestination" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" -ne 1 ]; then
/usr/libexec/PlistBuddy -c "Set:extractionDestination 1" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:extractionDestination integer 1" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:folderModifiedDate" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" -ne 2 ]; then
/usr/libexec/PlistBuddy -c "Set:folderModifiedDate 2" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:folderModifiedDate integer 2" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:LaunchCount" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" -ne 0 ]; then
/usr/libexec/PlistBuddy -c "Set:LaunchCount 0" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:LaunchCount integer 0" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:filenameEncoding" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" -ne 8 ]; then
/usr/libexec/PlistBuddy -c "Set:filenameEncoding 8" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:filenameEncoding integer 8" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:TUConfigInformationBannerViewedCount" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" -ne 0 ]; then
/usr/libexec/PlistBuddy -c "Set:TUConfigInformationBannerViewedCount 0" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:TUConfigInformationBannerViewedCount integer 0" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:OnboardingUserViewedWelcomeSlide" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" != "true" ]; then
/usr/libexec/PlistBuddy -c "Set:OnboardingUserViewedWelcomeSlide true" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:OnboardingUserViewedWelcomeSlide bool true" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:SUEnableAutomaticChecks" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" != "true" ]; then
/usr/libexec/PlistBuddy -c "Set:SUEnableAutomaticChecks true" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:SUEnableAutomaticChecks bool true" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:userAgreedToNewTOSAndPrivacy" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" != "true" ]; then
/usr/libexec/PlistBuddy -c "Set:userAgreedToNewTOSAndPrivacy true" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:userAgreedToNewTOSAndPrivacy bool true" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:isFreshInstall" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" != "true" ]; then
/usr/libexec/PlistBuddy -c "Set:isFreshInstall true" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:isFreshInstall bool true" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:TUConfigInformationBannerOpened" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" != "true" ]; then
/usr/libexec/PlistBuddy -c "Set:TUConfigInformationBannerOpened true" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:TUConfigInformationBannerOpened bool true" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:deleteExtractedArchive" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" != "true" ]; then
/usr/libexec/PlistBuddy -c "Set:deleteExtractedArchive true" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:deleteExtractedArchive bool true" "$STR_PLIST_FILEPATH"
  fi
  #####
STR_VALUE=$(/usr/libexec/PlistBuddy -c "Print:autoupdatesEnabled" "$STR_PLIST_FILEPATH")
  if [ $? -eq 0 ]; then
    if [ "$STR_VALUE" != "false" ]; then
/usr/libexec/PlistBuddy -c "Set:autoupdatesEnabled false" "$STR_PLIST_FILEPATH"
    fi
  else
/usr/libexec/PlistBuddy -c "Add:autoupdatesEnabled bool false" "$STR_PLIST_FILEPATH"
  fi


###
/usr/libexec/PlistBuddy -c "Save" "$STR_PLIST_FILEPATH"
done

sleep 1

"/usr/bin/killall" cfprefsd

/bin/echo "処理:設定終了"
exit 0


|

[PlistBuddy]bash zsh設定


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

#!/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()
set ocidUserName to refMe's NSUserName()
set ocidHomeDirURL to appFileManager's homeDirectoryForUser:(ocidUserName)

set listFileName to {".zshrc", ".zprofile", ".bashrc", ".bash_profile"} as list


########################################
##本処理
repeat with itemFileName in listFileName
  set strFileName to itemFileName as text
  set ocidFilePathURL to (ocidHomeDirURL's URLByAppendingPathComponent:(strFileName))
  ###テキストに読み込んで
  set listReadString to (refMe's NSString's stringWithContentsOfURL:(ocidFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
  set ocidReadString to (item 1 of listReadString)
  if ocidReadString = (missing value) then
    log "対象ファイルが見つかりません"
  else
    ###改行でArrayni
    set ocidReadArray to (ocidReadString's componentsSeparatedByString:("\n"))
    set boolExist to false
    repeat with itemReadLine in ocidReadArray
    ### PlistBuddy行があるか?チェック
      if (itemReadLine as text) starts with "alias PlistBuddy" then
set boolExist to true
exit repeat
      end if
    end repeat
    if boolExist is true then
      log "すでに登録済みです"
    else
      set ocidOutPutStrings to (ocidReadString's stringByAppendingString:("\nalias PlistBuddy='/usr/libexec/PlistBuddy'\n"))
      set listDone to (ocidOutPutStrings's writeToURL:(ocidFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
      log item 1 of listDone
      set strCommandText to ("source ~/" & strFileName & "") as text
      do shell script strCommandText
    end if
  end if
  
end repeat


return


|

[PlistBuddy]キー名称にスペースがある場合


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


##シングルクオトで囲む
/usr/libexec/PlistBuddy -c "Print:SystemPowerSettings:'Update DarkWakeBG Setting'" /Library/Preferences/com.apple.PowerManagement.plist
##スペースをエスケープするか
/usr/libexec/PlistBuddy -c "Print:SystemPowerSettings:Update\ DarkWakeBG\ Setting" /Library/Preferences/com.apple.PowerManagement.plist



|

[PlistBuddy]Dockにフォルダを追加する

サンプルはこの位置=『:persistent-apps:0』=最初 にデスクトップを追加
Screencapture-20230626-181726
内容的には
Screencapture-20230626-182333
こんな感じ

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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
########################
###Arrayに新規ArrayでDictを追加
/usr/libexec/PlistBuddy -c "add:persistent-apps:0 dict" "$HOME/Library/Preferences/com.apple.dock.plist"
###↑ここで追加したDictにキーと値を入れていく
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:GUID integer $RANDOM$RANDOM" "$HOME/Library/Preferences/com.apple.dock.plist"
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-type string directory-tile" "$HOME/Library/Preferences/com.apple.dock.plist"
###↑この親Dictに子要素としてtile-dataをDictで追加
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
###↑子要素のtile-dataにキーと値を入れていく
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:showas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:file-type integer 2" "$HOME/Library/Preferences/com.apple.dock.plist"
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:displayas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:parent-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:file-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:file-label string Desktop" "$HOME/Library/Preferences/com.apple.dock.plist"
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:is-beta bool false" "$HOME/Library/Preferences/com.apple.dock.plist"
###↑この子要素のtile-dataに孫要素でfile-dataをDictで追加
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:file-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
###値を入れていく
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:file-data:_CFURLStringType integer 15" "$HOME/Library/Preferences/com.apple.dock.plist"
/usr/libexec/PlistBuddy -c "add:persistent-apps:0:tile-data:file-data:_CFURLString string file://$HOME/Desktop" "$HOME/Library/Preferences/com.apple.dock.plist"
###Dock再起動
/usr/bin/killall Dock

|

[PlistBuddy]処理の流れ


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

###警告出すようにする
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:WarnOnEmptyTrash\" \"$HOME/Library/Preferences/com.apple.finder.plist\"") as text
set strBoolWarns to (do shell script strCommandText) as text
if strBoolWarns is "false" then
  ##値の変更 BOOL
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Set:WarnOnEmptyTrash bool true\" \"$HOME/Library/Preferences/com.apple.finder.plist\"") as text
  do shell script strCommandText
  ##確認
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:WarnOnEmptyTrash\" \"$HOME/Library/Preferences/com.apple.finder.plist\"") as text
  do shell script strCommandText
  ##保存
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Save\" \"$HOME/Library/Preferences/com.apple.finder.plist\"") as text
  do shell script strCommandText
end if



####初期設定までのパス
tell application "Finder"
  set aliasPreferencesDirPath to (path to library folder from user domain) as alias
end tell
set strFilePath to (POSIX path of aliasPreferencesDirPath) as text
set strFilePath to (strFilePath & "Containers/com.apple.archiveutility/Data/Library/Preferences/com.apple.archiveutility.plist")
####まずはKey値があるか?を確認する
try
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:dearchive-into\"  \"" & strFilePath & "\"") as text
  set strResponseArray to (do shell script strCommandText) as text
  ###Key値があれば変更する
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Set:dearchive-into '.'\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
on error
  ###Key値がなければ作る
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:dearchive-into string '.'\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end try

###保存する
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Save\"  \"" & strFilePath & "\"") as text
do shell script strCommandText


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
##コマンド
/usr/libexec/PlistBuddy -h
#→ヘルプ
/usr/libexec/PlistBuddy -c
#→コマンド形式(1ライナー用)
/usr/libexec/PlistBuddy -x
#→インタラクティブな応答形式
#################################################
##オプション
/usr/libexec/PlistBuddy -c "Print:"
/usr/libexec/PlistBuddy -c "Set:"
/usr/libexec/PlistBuddy -c "Add:"
/usr/libexec/PlistBuddy -c "Delete:"
/usr/libexec/PlistBuddy -c "Revert:"
/usr/libexec/PlistBuddy -c "Save:"
/usr/libexec/PlistBuddy -c "Clear:"
/usr/libexec/PlistBuddy -c "Copy:"
/usr/libexec/PlistBuddy -c "Merge:"
/usr/libexec/PlistBuddy -c "Import:"
#################################################
##新規作成
/usr/libexec/PlistBuddy -c "Save:" "$HOME/Desktop/サンプルA.plist"
##内容表示
/usr/libexec/PlistBuddy -c "Print:" "$HOME/Desktop/サンプルA.plist"
Dict {
}
##################
##値を入れる KEY=AAAA VALUE=9999
/usr/libexec/PlistBuddy -c "Add:AAAA integer 9999 " "$HOME/Desktop/サンプルA.plist"
##内容表示
/usr/libexec/PlistBuddy -c "Print:" "$HOME/Desktop/サンプルA.plist"
Dict {
    AAAA = 9999
}
##値を入れる KEY=AAAA VALUE=2222
/usr/libexec/PlistBuddy -c "Set:AAAA 2222 " "$HOME/Desktop/サンプルA.plist"
/usr/libexec/PlistBuddy -c "Print:" "$HOME/Desktop/サンプルA.plist"
Dict {
    AAAA = 2222
}
##############
##値を入れる KEY=BBBB VALUE=false
/usr/libexec/PlistBuddy -c "Add:BBBB bool false" "$HOME/Desktop/サンプルA.plist"
##値を入れる KEY=CCCC VALUE=false
/usr/libexec/PlistBuddy -c "Add:CCCC bool false" "$HOME/Desktop/サンプルA.plist"
##値を入れる KEY=DDDD VALUE=false
/usr/libexec/PlistBuddy -c "Add:DDDD bool 0" "$HOME/Desktop/サンプルA.plist"
##値を入れる KEY=EEEE VALUE=false
/usr/libexec/PlistBuddy -c "Add:EEEE bool 0" "$HOME/Desktop/サンプルA.plist"
##内容表示
/usr/libexec/PlistBuddy -c "Print:" "$HOME/Desktop/サンプルA.plist"
Dict {
    CCCC = false
    BBBB = false
    EEEE = false
    DDDD = false
}
##############
##↑の操作で値はBOOL値であることが指定されているので変更時には不要
##値を入れる KEY=BBBB VALUE=true
/usr/libexec/PlistBuddy -c "Set:BBBB true" "$HOME/Desktop/サンプルA.plist"
##値を入れる KEY=CCCC VALUE=true
/usr/libexec/PlistBuddy -c "SET:CCCC true" "$HOME/Desktop/サンプルA.plist"
##値を入れる KEY=DDDD VALUE=true
/usr/libexec/PlistBuddy -c "SET:DDDD 1" "$HOME/Desktop/サンプルA.plist"
##値を入れる KEY=EEEE VALUE=true
/usr/libexec/PlistBuddy -c "SET:EEEE 1" "$HOME/Desktop/サンプルA.plist"
##内容表示
/usr/libexec/PlistBuddy -c "Print:" "$HOME/Desktop/サンプルA.plist"
Dict {
    CCCC = true
    BBBB = true
    EEEE = true
    DDDD = true
}
exit 0


|

[applescript]CDとDVD

Screencapture-20230518-20806

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

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

###イジェクトメニュー有効化
set strFilePath to ("/System/Library/CoreServices/Menu Extras/Eject.menu") as text
tell application "Finder"
  set aliasFilePath to POSIX file strFilePath as alias
  open aliasFilePath
end tell


######################################################
tell application "Finder"
  set aliasPreferencesDirPath to (path to preferences folder from user domain) as alias
  set strFileName to "com.apple.systemuiserver.plist" as text
  set aliasFilePath to (file strFileName of folder aliasPreferencesDirPath) as alias
end tell
set strFilePath to (POSIX path of aliasFilePath) as text
###すでに設定済みか?チェック 項目名にスペースがある場合はシングルクオトに入れる
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:'NSStatusItem Visible com.apple.menuextra.eject'\" \"" & strFilePath & "\"") as text
try
  set boolChk to (do shell script strCommandText) as boolean
on error
  ##エラーしたら項目が無いって事なので判定用のあたいを入れておく
  set boolChk to false as boolean
end try
###設定されていなければ設定する
if boolChk is not true then
  set strBoolNo to "1" as text
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:'NSStatusItem Visible com.apple.menuextra.eject' bool true\"  \"" & strFilePath & "\"") as text
  log strCommandText
  do shell script strCommandText
end if


######################################################
tell application "Finder"
  set aliasPreferencesDirPath to (path to preferences folder from user domain) as alias
  set strFileName to "com.apple.systemuiserver.plist" as text
  set aliasFilePath to (file strFileName of folder aliasPreferencesDirPath) as alias
end tell
set strFilePath to (POSIX path of aliasFilePath) as text
###すでに設定済みか?チェック
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:menuExtras:\"  \"" & strFilePath & "\"") as text
try
  set strResponseArray to (do shell script strCommandText) as text
on error
  ##エラーしたら項目が無いって事なので判定用のあたいを入れておく
  set strResponseArray to "Eject.menu" as text
end try
###設定されていなければ設定する (Array形式なのでADDする)
if strResponseArray does not contain "Eject.menu" then
  set strMenuExtras to "/System/Library/CoreServices/Menu Extras/Eject.menu" as text
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"add:menuExtras:0 string '" & strMenuExtras & "'\"  \"" & strFilePath & "\"") as text
  log strCommandText
  do shell script strCommandText
end if


######################################################
tell application "Finder"
  set aliasPreferencesDirPath to (path to preferences folder from user domain) as alias
  set strFileName to "com.apple.digihub.plist" as text
  set aliasFilePath to (file strFileName of folder aliasPreferencesDirPath) as alias
end tell
set strFilePath to (POSIX path of aliasFilePath) as text
###設定内容チェック
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:com.apple.digihub.blank.cd.appeared:action\"  \"" & strFilePath & "\"") as text
log strCommandText
try
  set numResponse to (do shell script strCommandText) as text
on error
  set numResponse to "0" as text
  ###DICTを作って
  try
    set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.blank.cd.appeared dict\"  \"" & strFilePath & "\"") as text
    do shell script strCommandText
  end try
  ###値のタイプを確定(この場合はinteger)
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.blank.cd.appeared:action integer\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end try
if numResponse is not "100" then
  ###値を入れる
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Set:com.apple.digihub.blank.cd.appeared:action 100\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end if




######################################################
tell application "Finder"
  set aliasPreferencesDirPath to (path to preferences folder from user domain) as alias
  set strFileName to "com.apple.digihub.plist" as text
  set aliasFilePath to (file strFileName of folder aliasPreferencesDirPath) as alias
end tell
set strFilePath to (POSIX path of aliasFilePath) as text
###設定内容チェック
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:com.apple.digihub.blank.dvd.appeared:action\"  \"" & strFilePath & "\"") as text
log strCommandText
try
  set numResponse to (do shell script strCommandText) as text
on error
  set numResponse to "0" as text
  ###DICTを作って
  try
    set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.blank.dvd.appeared dict\"  \"" & strFilePath & "\"") as text
    do shell script strCommandText
  end try
  ###値のタイプを確定(この場合はinteger)
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.blank.dvd.appeared:action integer\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end try
if numResponse is not "100" then
  ###値を入れる
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Set:com.apple.digihub.blank.dvd.appeared:action 100\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end if


######################################################
tell application "Finder"
  set aliasPreferencesDirPath to (path to preferences folder from user domain) as alias
  set strFileName to "com.apple.digihub.plist" as text
  set aliasFilePath to (file strFileName of folder aliasPreferencesDirPath) as alias
end tell
set strFilePath to (POSIX path of aliasFilePath) as text
###設定内容チェック
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:com.apple.digihub.cd.music.appeared:action\"  \"" & strFilePath & "\"") as text
log strCommandText
try
  set numResponse to (do shell script strCommandText) as text
on error
  set numResponse to "0" as text
  ###DICTを作って
  try
    set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.cd.music.appeared dict\"  \"" & strFilePath & "\"") as text
    do shell script strCommandText
  end try
  ###値のタイプを確定(この場合はinteger)
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.cd.music.appeared:action integer\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end try
if numResponse is not "1" then
  ###値を入れる
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Set:com.apple.digihub.cd.music.appeared:action 1\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end if



######################################################
tell application "Finder"
  set aliasPreferencesDirPath to (path to preferences folder from user domain) as alias
  set strFileName to "com.apple.digihub.plist" as text
  set aliasFilePath to (file strFileName of folder aliasPreferencesDirPath) as alias
end tell
set strFilePath to (POSIX path of aliasFilePath) as text
###設定内容チェック
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:com.apple.digihub.cd.picture.appeared:action\"  \"" & strFilePath & "\"") as text
log strCommandText
try
  set numResponse to (do shell script strCommandText) as text
on error
  set numResponse to "0" as text
  ###DICTを作って
  try
    set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.cd.picture.appeared dict\"  \"" & strFilePath & "\"") as text
    do shell script strCommandText
  end try
  ###値のタイプを確定(この場合はinteger)
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.cd.picture.appeared:action integer\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end try
if numResponse is not "1" then
  ###値を入れる
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Set:com.apple.digihub.cd.picture.appeared:action 1\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end if

######################################################
tell application "Finder"
  set aliasPreferencesDirPath to (path to preferences folder from user domain) as alias
  set strFileName to "com.apple.digihub.plist" as text
  set aliasFilePath to (file strFileName of folder aliasPreferencesDirPath) as alias
end tell
set strFilePath to (POSIX path of aliasFilePath) as text
###設定内容チェック
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Print:com.apple.digihub.dvd.video.appeared:action\"  \"" & strFilePath & "\"") as text
log strCommandText
try
  set numResponse to (do shell script strCommandText) as text
on error
  set numResponse to "0" as text
  ###DICTを作って
  try
    set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.dvd.video.appeared dict\"  \"" & strFilePath & "\"") as text
    do shell script strCommandText
  end try
  ###値のタイプを確定(この場合はinteger)
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Add:com.apple.digihub.dvd.video.appeared:action integer\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end try
if numResponse is not "1" then
  ###値を入れる
  set strCommandText to ("/usr/libexec/PlistBuddy -c \"Set:com.apple.digihub.dvd.video.appeared:action 1\"  \"" & strFilePath & "\"") as text
  do shell script strCommandText
end if


##最後に保存
set strCommandText to ("/usr/libexec/PlistBuddy -c \"Save\"  \"" & strFilePath & "\"") as text
do shell script strCommandText




|

[PlistBuddy] /usr/libexec/PlistBuddy -c Import

データ形式で設定したい場合に主に利用します



ダウンロード - plistimport.zip




#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
(*
こちらのURL
https://adobe.ly/3qqoq8p
Acrobat または Reader にてデフォルトで手のひらツールを利用したい場合についてこちらの記事の Macの場合の対処方法
値はDATAなので以下 <48616E6400>
詳しくはこちら
https://force4u.cocolog-nifty.com/skywalker/2022/09/post-d635db.html

*)
#
#
# 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

######ログ表示
doLogView()

property objMe : a reference to current application
property objNSString : a reference to objMe's NSString
property objNSMutableString : a reference to objMe's NSMutableString
property objNSURL : a reference to objMe's NSURL

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

set objFileManager to objMe's NSFileManager's defaultManager()


tell application "Finder"
###このファイルのエイリアス
set aliasMe to path to me as alias
log aliasMe as alias
end tell
### UNIXパスに
set strMePath to POSIX path of aliasMe as text
log strMePath as text

### パスをNSString
set ocidMePathString to objNSString's stringWithString:strMePath
log ocidMePathString as text
log className() of ocidMePathString as text

### NSString NSURL
set ocidMePathNSURL to objNSURL's fileURLWithPath:ocidMePathString
log ocidMePathNSURL as text
log className() of ocidMePathNSURL as text

### このファイルがあるディレクトリ
set ocidMePathContainer to ocidMePathNSURL's URLByDeletingLastPathComponent
log ocidMePathContainer as text
log className() of ocidMePathContainer as text

### インポートするデータのパス
set ocidImportDataPath to ocidMePathContainer's URLByAppendingPathComponent:"ImportData/Hand.bin"
log ocidImportDataPath as text
log className() of ocidImportDataPath as text

###インポートするファイルのUNIXパス
set strImportDataPath to ocidImportDataPath's |path|() as text

############################################
#### ユーザーLibraryパス取得
set ocidUserLibraryPath to (objFileManager's URLsForDirectory:(objMe's NSLibraryDirectory) inDomains:(objMe's NSUserDomainMask))
log ocidUserLibraryPath as text
log className() of ocidUserLibraryPath as text

###Arrayで入るのでパスURLを取り出す
set ocidNsurlLibraryPath to ocidUserLibraryPath's objectAtIndex:0
log ocidNsurlLibraryPath as text
log className() of ocidNsurlLibraryPath as text

#### コンポーネント追加
set ocidPreferencesPath to ocidNsurlLibraryPath's URLByAppendingPathComponent:"Preferences"
log ocidPreferencesPath as text
log className() of ocidPreferencesPath as text

#### コンポーネント追加
set ocidAcrobatReaderPlistPath to ocidPreferencesPath's URLByAppendingPathComponent:"com.adobe.Reader.plist"
log ocidAcrobatReaderPlistPath as text
log className() of ocidAcrobatReaderPlistPath as text

#### コンポーネント追加
set ocidAcrobatProPlistPath to ocidPreferencesPath's URLByAppendingPathComponent:"com.adobe.Acrobat.Pro.plist"
log ocidAcrobatProPlistPath as text
log className() of ocidAcrobatProPlistPath as text

####UNIXパス
set strAcrobatProPlistPath to ocidAcrobatProPlistPath's |path|() as text
set strAcrobatReaderPlistPath to ocidAcrobatReaderPlistPath's |path|() as text
log strAcrobatProPlistPath as text
log strAcrobatReaderPlistPath as text

####ファイルの有無 Pro
set boolChkAcrobatProPlistPath to (ocidAcrobatProPlistPath's checkResourceIsReachableAndReturnError:(missing value))
log boolChkAcrobatProPlistPath as boolean
####ファイルの有無 Reader
set boolChkAcrobatReaderPlistPath to (ocidAcrobatReaderPlistPath's checkResourceIsReachableAndReturnError:(missing value))
log boolChkAcrobatReaderPlistPath as boolean

if boolChkAcrobatProPlistPath is true then
try
###まずは 今の値を読み取ります
set strCommandText to "/usr/libexec/PlistBuddy -c \"Print :DC:Selection:DefaultSelect:1\" \"" & strAcrobatProPlistPath & "\""
set strCommandResult to (do shell script strCommandText) as text
log strCommandResult
on error
log "設定項目が見つかりません"
set strCommandResult to ""
end try
if strCommandResult contains "Hand" then
set strCommandResult to ""
log "設定済みです"
else
set strCommandResult to ""
try
###今ある値を削除して
set strCommandText to "/usr/libexec/PlistBuddy -c \"Delete :DC:Selection:DefaultSelect:1\" \"" & strAcrobatProPlistPath & "\""
do shell script strCommandText
end try
delay 1
####値をインポートします
set strCommandText to "/usr/libexec/PlistBuddy -c \"Import :DC:Selection:DefaultSelect:1 '" & strImportDataPath & "'\" '" & strAcrobatProPlistPath & "'"
do shell script strCommandText
delay 1
####正しくインポート出来たか?確認
set strCommandText to "/usr/libexec/PlistBuddy -c \"Print :DC:Selection:DefaultSelect:1\" \"" & strAcrobatProPlistPath & "\""
set strCommandResult to (do shell script strCommandText) as text
if strCommandResult contains "Hand" then
log "設定完了"
else
log "設定に失敗しました"
end if
set strCommandResult to ""
end if
end if



if boolChkAcrobatReaderPlistPath is true then
try
###まずは 今の値を読み取ります
set strCommandText to "/usr/libexec/PlistBuddy -c \"Print :DC:Selection:DefaultSelect:1\" \"" & strAcrobatReaderPlistPath & "\""
set strCommandResult to (do shell script strCommandText) as text
log strCommandResult
on error
log "設定項目が見つかりません"
set strCommandResult to ""
end try
if strCommandResult contains "Hand" then
log "設定済みです"
else
set strCommandResult to ""
try
###今ある値を削除して
set strCommandText to "/usr/libexec/PlistBuddy -c \"Delete :DC:Selection:DefaultSelect:1\" \"" & strAcrobatReaderPlistPath & "\""
do shell script strCommandText
end try
delay 1
####値をインポートします
set strCommandText to "/usr/libexec/PlistBuddy -c \"Import :DC:Selection:DefaultSelect:1 '" & strImportDataPath & "'\" '" & strAcrobatReaderPlistPath & "'"
do shell script strCommandText
delay 1
####正しくインポート出来たか?確認
set strCommandText to "/usr/libexec/PlistBuddy -c \"Print :DC:Selection:DefaultSelect:1\" \"" & strAcrobatReaderPlistPath & "\""
set strCommandResult to (do shell script strCommandText) as text
if strCommandResult contains "Hand" then
log "設定完了"
else
log "設定に失敗しました"
end if
set strCommandResult to ""
end if
end if


############################################



#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
end if
end repeat

end doLogView
#########################

|

PlistBuddyを使ってみよう(その6:データ)

各種データを追加してみましょう
string
bool
integer
real
date



string文字列です

/usr/libexec/PlistBuddy -c "add:GGG string 美しい日本語" $HOME/Desktop/PlistBuddy.plist

20220301-195002

エスケープが必要な文字列の場合は
/usr/libexec/PlistBuddy -c "add:JJJ string \\\"美しい日本語\\\"" $HOME/Desktop/PlistBuddy.plist
トリプルになりますので留意してください。



bool 可不可 YES NO (内部的には1=True 0=False
/usr/libexec/PlistBuddy -c "add:CCC bool true" $HOME/Desktop/PlistBuddy.plist
sh-3.2$ /usr/libexec/PlistBuddy -c "add:DDD bool false" $HOME/Desktop/PlistBuddy.plist

20220301-195235



integer 整数
/usr/libexec/PlistBuddy -c "add:FFF integer 3.14" $HOME/Desktop/PlistBuddy.plist
小数点以下は切り捨てられます
20220301-195414



real 数値
/usr/libexec/PlistBuddy -c "add:EEE real 3.14" $HOME/Desktop/PlistBuddy.plist

20220301-195745



date 日付
/usr/libexec/PlistBuddy -c "add:KKK date Tue Mar 1 17:12:21 JST 2022" $HOME/Desktop/PlistBuddy.plist

このPlistBuddyで使う日付フォーマットは以下の手順にて取得できます。
export LANG=C
date

sh-3.2$ 

sh-3.2$ export LANG=C

sh-3.2$ 

sh-3.2$ date

Tue Mar  1 20:01:18 JST 2022

sh-3.2$ 

20220301-200318

|

PlistBuddyを使ってみよう(その5:array)

arrayです。
add追加コマンド
/usr/libexec/PlistBuddy -c "add :AAA array" $HOME/Desktop/PlistBuddy.plist
AAAって名前の
/usr/libexec/PlistBuddy -c "add :AAA array" $HOME/Desktop/PlistBuddy.plist
arrayを追加します
/usr/libexec/PlistBuddy -c "add :AAAstrong>array <" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ 

sh-3.2$ /usr/libexec/PlistBuddy -c "add:AAA array" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ 

結果は

sh-3.2$ /usr/libexec/PlistBuddy -c "print :AAA" $HOME/Desktop/PlistBuddy.plist

Array {

}

sh-3.2$ 

こうなります
20220301-194158



ここに値を追加していきます
array0からarray2までの3つの値を追加してみましょう。
/usr/libexec/PlistBuddy -c "add:AAA:0 string BBBの値" $HOME/Desktop/PlistBuddy.plist
/usr/libexec/PlistBuddy -c "add:AAA:1 string CCCの値" $HOME/Desktop/PlistBuddy.plist
/usr/libexec/PlistBuddy -c "add:AAA:2 string DDDの値" $HOME/Desktop/PlistBuddy.plist


sh-3.2$ 

sh-3.2$ /usr/libexec/PlistBuddy -c "add:AAA:0 string BBBの値" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ /usr/libexec/PlistBuddy -c "add:AAA:1 string CCCの値" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ /usr/libexec/PlistBuddy -c "add:AAA:2 string DDDの値" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ 

結果は

sh-3.2$ /usr/libexec/PlistBuddy -c "print :AAA" $HOME/Desktop/PlistBuddy.plist

Array {

    BBBの値

    CCCの値

    DDDの値

}

sh-3.2$ 

このようになります。
20220301-194417

|

PlistBuddyを使ってみよう(その4:dict)

コマンドを打って 結果を確認します
Entriesは
dict 辞書形式
array 配列形式
string 文字列
bool 可否
real 数値
integer 整数
date 日時



dict (dictionary)
AAAって名前でdictを作成します
addで追加
/usr/libexec/PlistBuddy -c "add:AAA dict" $HOME/Desktop/PlistBuddy.plist
AAAの名前で
/usr/libexec/PlistBuddy -c "add:AAA dict" $HOME/Desktop/PlistBuddy.plist
dictを追加しました
/usr/libexec/PlistBuddy -c "add:AAA dict" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ /usr/libexec/PlistBuddy -c "add:AAA dict" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ 



結果は

sh-3.2$ /usr/libexec/PlistBuddy -c "print :AAA" $HOME/Desktop/PlistBuddy.plist

Dict {

}

sh-3.2$ 




dictであるAAAに値を追加していきます

sh-3.2$ /usr/libexec/PlistBuddy -c "add :AAA:BBB string BBBの値" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ /usr/libexec/PlistBuddy -c "add :AAA:CCC string CCCの値" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ /usr/libexec/PlistBuddy -c "add :AAA:DDD string DDDの値" $HOME/Desktop/PlistBuddy.plist

sh-3.2$ 

結果は

sh-3.2$ /usr/libexec/PlistBuddy -c "print :AAA" $HOME/Desktop/PlistBuddy.plist

Dict {

    DDD = DDDの値

    CCC = CCCの値

    BBB = BBBの値

}

sh-3.2$ 



このようになります
20220301-184138

|

その他のカテゴリー

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