AppleScript Bash

[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


|

[bash]DWViewerLightインストール


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
# https://www.fujifilm.com/fb/download/software/docuworks/download102
#
#################################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー(whoami): $USER_WHOAMI"
###実行しているユーザー名
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
###実行しているユーザー名
HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
/bin/echo "実行ユーザー(HOME): $HOME_USER"
###logname
LOGIN_NAME=$(/usr/bin/logname)
/bin/echo "ログイン名(logname): $LOGIN_NAME"
###UID
USER_NAME=$(/usr/bin/id -un)
/bin/echo "ユーザー名(id): $USER_NAME"
###STAT
STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
/bin/echo "STAT_USR(console): $STAT_USR"
#################################################
#インストール先
/bin/mkdir -p "$HOME/Applications"
/bin/chmod 700 "$HOME/Applications"
#################################################
#今あるものをゴミ箱に
STR_INSTALL_PATH="/Users/$CONSOLE_USER/Applications/DocuWorks Viewer Light"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/FFMPEG.XXXXXXXX")
/bin/mkdir -p "$STR_INSTALL_PATH"
/bin/mv "$STR_INSTALL_PATH" "$USER_TRASH_DIR"
#今あるものをゴミ箱に
STR_INSTALL_DIR_PATH="/Applications/DocuWorks Viewer Ligh"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/FFMPEG.XXXXXXXX")
/bin/mkdir -p "$STR_INSTALL_DIR_PATH"
/bin/mv "$STR_INSTALL_DIR_PATH" "$USER_TRASH_DIR"
#################################################
#ダウンロード
STR_URL="https://assets-fb.fujifilm.com/download/pub/exe/docuworks/1/dwvl911.dmg"
/bin/echo "ダウンロード開始:" "$STR_URL"
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/install.dmg" "$STR_URL" --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/install.dmg" "$STR_URL" --http1.1 --connect-timeout 20; then
/bin/echo "ファイルのダウンロードに失敗しました"
exit 1
  fi
fi
#################################################
#基本2 マシンが速ければ1 遅ければ3
STR_SLEEPTIME=2
#DMGオープン
/bin/echo "インストール開始:" "$CONSOLE_USER"
###ディスクをマウント
/usr/bin/hdiutil attach "$USER_TEMP_DIR/install.dmg" -noverify -nobrowse -noautoopen
sleep "$STR_SLEEPTIME"
####解凍
USER_EXPAND_DIR=$(/usr/bin/mktemp -d)
sleep "$STR_SLEEPTIME"
STR_PKG_PATH="/Volumes/dwvl911/DWViewerLight.pkg"
/usr/sbin/pkgutil --expand  "$STR_PKG_PATH" "$USER_EXPAND_DIR/EXPAND"
sleep "$STR_SLEEPTIME"
###ディスクをアンマウント
STR_MOUNT_PATH="/Volumes/dwvl911"
/usr/bin/hdiutil detach "$STR_MOUNT_PATH" -force
sleep "$STR_SLEEPTIME"
#################################################
#Payload解凍
USER_UNARCHIVE_DIR=$(/usr/bin/mktemp -d)
STR_PAYLOAD_PATH="$USER_EXPAND_DIR/EXPAND/DWViewerLight.pkg/Payload"
/usr/bin/ditto -xz "$STR_PAYLOAD_PATH" "$USER_UNARCHIVE_DIR"
#################################################
#移動
STR_EXPAND_DIR="$USER_UNARCHIVE_DIR"
STR_DIST_PATH="/Users/$CONSOLE_USER/Applications/DocuWorks Viewer Light"
/bin/mv -f "$STR_EXPAND_DIR" "$STR_DIST_PATH"
exit 0


|

Apple Service Utility削除


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#
#################################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー(whoami): $USER_WHOAMI"
if [ "$USER_WHOAMI" != "root" ]; then
  /bin/echo "このスクリプトを実行するには管理者権限が必要です。"
  /bin/echo "sudo で実行してください"
  ### path to me
  SCRIPT_PATH="${BASH_SOURCE[0]}"
  /bin/echo "/usr/bin/sudo \"$SCRIPT_PATH\""
  /bin/echo "↑を実行してください"
  ###実行しているユーザー名
  CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
  /bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
  exit 1
else
  ###実行しているユーザー名
  CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
  /bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
  ###実行しているユーザー名
  HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
  /bin/echo "実行ユーザー(HOME): $HOME_USER"
  ###logname
  LOGIN_NAME=$(/usr/bin/logname)
  /bin/echo "ログイン名(logname): $LOGIN_NAME"
  ###UID
  USER_NAME=$(/usr/bin/id -un)
  /bin/echo "ユーザー名(id): $USER_NAME"
  ###STAT
  STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
  /bin/echo "STAT_USR(console): $STAT_USR"
fi

STR_GO2_TRASH_DIR="/usr/local/libexec/repaird"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Users/Shared/AppleServiceUtility"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Applications/Apple Service Utility.app"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Library/Preferences/com.apple.fielddiagnostics.appleserviceutility.updaterd.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Library/Preferences/com.apple.RepairKit.repaird.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Library/Preferences/com.apple.RepairKit.Diagnostic-8155.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Users/$STAT_USR/Library/Preferences/com.apple.fielddiagnostics.MacConfigurationUtility.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Users/$STAT_USR/Library/Preferences/com.apple.fielddiagnostics.appleserviceutility.uiapp.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Users/$STAT_USR/Library/Preferences/com.apple.fielddiagnostics.appleserviceutility.uiapp.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Users/$STAT_USR/Library/Preferences/com.apple.MobileDeviceUpdater.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Library/LaunchDaemons/com.apple.fielddiagnostics.appleserviceutility.updaterXPCService.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Library/LaunchDaemons/com.apple.repaird.plist"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Users/Shared/AppleInternal"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Users/Shared/Library/Preferences/Logging"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"


STR_GO2_TRASH_DIR="/var/log/ASUUXPCService.log"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

STR_GO2_TRASH_DIR="/Library/PrivilegedHelperTools/com.apple.fielddiagnostics.appleserviceutility.updaterd"
/usr/bin/touch "$STR_GO2_TRASH_DIR"
USER_TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/AppleServiceUtility.XXXXXXXX")
/bin/chmod 777 "$USER_TRASH_DIR"
/bin/mv "$STR_GO2_TRASH_DIR" "$USER_TRASH_DIR"

exit 0


|

新規Bashファイルを作成する


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

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


set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDownloadsDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDownloadsDirPathURL's absoluteURL()) as alias
##################
###ダイアログ
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 strDefaultFileName to "ファイル名.bash" as text
set strPromptText to "名前を決めてください(拡張子もお忘れなく)" as text
set strMesText to "名前を決めてください" as text
###ファイル名 ダイアログ
try
  set aliasSaveFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultFileName with prompt strPromptText) as «class furl»
on error
return "キャンセルしました"
end try
##################
###パス
set strSaveFilePath to (POSIX path of aliasSaveFilePath) as text
set ocidSaveFilePathStr to refMe's NSString's stringWithString:(strSaveFilePath)
set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
set ocidSaveFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveFilePath) isDirectory:false)

##################
###コンテンツ 保存するテキストはここ
set strSaveData to ("#!/bin/bash\nSTR_DATE=$(/bin/date)\n/bin/echo \"$STR_DATE\"") as text
set ocidSaveData to refMe's NSString's stringWithString:(strSaveData)
##################
###保存
set listDone to ocidSaveData's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
###アクセス権755
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions)
set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidSaveFilePath) |error|:(reference)

return

|

[shell]改行区切りの処理

shに限っては、配列リストにするといった事ではなく
区切り文字で区切って順番に取り出すといったイメージ

bash

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

#!/usr/bin/env bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
##区切りテキスト
STR_SUB_DIR_NAME="Applications\nDesktop\nDeveloper\nDocuments\nDownloads\nGroups\nLibrary\nMovies\nMusic\nPictures\nShared\nSites\nSystem\nPublic"
STR_SUB_DIR_NAME_DEM=$(/usr/bin/printf "$STR_SUB_DIR_NAME" | /usr/bin/tr '\n' ' ')
IFS="$(/usr/bin/printf ' ')"
read -d '\ ' -r -a LIST_SUB_DIR_NAME <<<"$STR_SUB_DIR_NAME_DEM"
##リストをループ
for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done



#################################################
##改行区切りテキスト
STR_SUB_DIR_NAME="Applications
Desktop
Developer
Documents
Downloads
Groups
Library
Movies
Music
Pictures
Shared
Sites
System
Public"
##スペース区切りでリスト化
IFS=$'\n'
read -d "\n" -r -a LIST_SUB_DIR_NAME <<< "$STR_SUB_DIR_NAME"
echo "$LIST_SUB_DIR_NAME"
##リストをループ
for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done
exit 0







sh

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

#!/usr/bin/env sh
#com.cocolog-nifty.quicktimer.icefloe
#################################################
##区切りテキスト
STR_SUB_DIR_NAME="Applications\nDesktop\nDeveloper\nDocuments\nDownloads\nGroups\nLibrary\nMovies\nMusic\nPictures\nShared\nSites\nSystem\nPublic"
STR_SUB_DIR_NAME_DEM=$(/usr/bin/printf "$STR_SUB_DIR_NAME" | /usr/bin/tr '\n' ' ')
##区切り
IFS=' '
###区切り文字で区切って順番にループ
for ITEM_DIR_NAME in $STR_SUB_DIR_NAME_DEM; do
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done


#################################################
##改行区切りテキスト
STR_SUB_DIR_NAME="Applications
Desktop
Developer
Documents
Downloads
Groups
Library
Movies
Music
Pictures
Shared
Sites
System
Public"
##区切り
IFS='
'
###区切り文字で区切って順番にループ
for ITEM_DIR_NAME in $STR_SUB_DIR_NAME; do
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done
exit 0


zsh

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

#!/usr/bin/env zsh
#com.cocolog-nifty.quicktimer.icefloe
#################################################
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
export LANG=en_US.UTF-8
#################################################
##区切りテキスト
STR_SUB_DIR_NAME="Applications\nDesktop\nDeveloper\nDocuments\nDownloads\nGroups\nLibrary\nMovies\nMusic\nPictures\nShared\nSites\nSystem\nPublic"
STR_SUB_DIR_NAME_DEM=$(/usr/bin/printf "$STR_SUB_DIR_NAME" | /usr/bin/tr '\n' ' ')
###リストにする
IFS=" "
read -d '\ ' -r -A LIST_SUB_DIR_NAME <<<"$STR_SUB_DIR_NAME_DEM"
##リストをループ
for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done

#################################################
##区切りテキスト
STR_SUB_DIR_NAME="Applications
Desktop
Developer
Documents
Downloads
Groups
Library
Movies
Music
Pictures
Shared
Sites
System
Public"
##=展開
LIST_SUB_DIR_NAME=(${=STR_SUB_DIR_NAME})
##リストをループ
for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done
exit 0




|

[shell]スペース区切りの処理

shに限っては、配列リストにするといった事ではなく
区切り文字で区切って順番に取り出すといったイメージ

BASH

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

#!/usr/bin/env bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
##半角スペース区切りテキスト
STR_SUB_DIR_NAME="Applications Desktop Developer Documents Downloads Groups Library Movies Music Pictures Shared Sites System Public"
##スペース区切りでリスト化
IFS=' '
read -d '\ ' -r -a LIST_SUB_DIR_NAME <<<"$STR_SUB_DIR_NAME"
##リストをループ
for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
ITEM_DIR_NAME=$(/bin/echo "$ITEM_DIR_NAME" | /usr/bin/tr -d '\n')
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done
exit 0

SH

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

#!/usr/bin/env sh
#com.cocolog-nifty.quicktimer.icefloe
#################################################
##半角スペース区切りテキスト
STR_SUB_DIR_NAME="Applications Desktop Developer Documents Downloads Groups Library Movies Music Pictures Shared Sites System Public"
##区切り
IFS=' '
###区切り文字で区切って順番にループ
for ITEM_DIR_NAME in $STR_SUB_DIR_NAME; do
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done
exit 0


zsh

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

#!/usr/bin/env zsh
#com.cocolog-nifty.quicktimer.icefloe
#################################################
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
export LANG=en_US.UTF-8
##半角スペース区切りテキスト
STR_SUB_DIR_NAME="Applications Desktop Developer Documents Downloads Groups Library Movies Music Pictures Shared Sites System Public"
##=展開
LIST_SUB_DIR_NAME=(${=STR_SUB_DIR_NAME})
##リストをループ
for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
/bin/echo  "ディレクトリ名:$ITEM_DIR_NAME"
done
exit 0




|

[zsh]スクリプト vs code出力タブ内でのパスの文字化け

Screen-20231006-170723 これで解決

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

#!/usr/bin/env zsh
#com.cocolog-nifty.quicktimer.icefloe
########################################
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
export LANG=en_US.UTF-8
/bin/echo $LANG

|

sudo 処理

ZSH

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

#!/bin/zsh
#Vs Codeのコンソールで実行すると文字化けする
# テスト中 何か違う気もする
########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行したユーザーは:$USER_WHOAMI"
if [ "$USER_WHOAMI" != "root" ]; then
  /bin/echo "このスクリプトを実行するには管理者権限が必要です。" 1>&2
  /bin/echo "sudo で実行してください" 1>&2
  ### path to me (VS CODEコンソールだとマルチバイト文字は文字化けする)
    /bin/echo " " 1>&2
  SCRIPT_PATH="${(%):-%N}"
  /bin/echo "/usr/bin/sudo \"$SCRIPT_PATH\"" 1>&2
  /bin/echo "↑を実行してください" 1>&2
  CRIPT_CONTEINER_DIR_PATH=$(print -r -- ${(%)PWD})
  /bin/echo "コンテナディレクトリ: $CRIPT_CONTEINER_DIR_PATH" 1>&2
  
  exit 1
fi


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

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

##################################################
###sudo インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー(whoami): $USER_WHOAMI"
if [ "$USER_WHOAMI" != "root" ]; then
  /bin/echo "このスクリプトを実行するには管理者権限が必要です。" 1>&2
  /bin/echo "sudo で実行してください" 1>&2
  /bin/echo "" 1>&2
  ### path to me 実行中のスクリプト
  SCRIPT_PATH="${BASH_SOURCE[0]}"
  /bin/echo "/usr/bin/sudo \"$SCRIPT_PATH\"" 1>&2
  /bin/echo "↑を実行してください" 1>&2
  exit 1
fi

##################################################
###sudo インストールしているか?チェック
if [ "$(/usr/bin/id -u)" != "0" ]; then
  /bin/echo "このスクリプトを実行するには管理者権限が必要です。" 1>&2
  /bin/echo "sudo で実行してください" 1>&2
  /bin/echo "" 1>&2
  ### path to me 実行中のスクリプト
  SCRIPT_PATH="${BASH_SOURCE[0]}"
  /bin/echo "/usr/bin/sudo \"$SCRIPT_PATH\"" 1>&2
  /bin/echo "↑を実行してください" 1>&2
  exit 1
fi


|

[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

|

[Bash]ワイルドカードを使えない場合


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

#!/bin/bash
###テンポラリーディレクトリを作り
MKTEMP_DIR=$(/usr/bin/mktemp -d)
###direnameでコンテナパス
TEMP_DIR_T="$(/usr/bin/dirname "$MKTEMP_DIR")"
###実行しているユーザー
CURRENT_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
###ゴミ箱を作る(同名のファイルがある場合のエラーよけ方法)
TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$CURRENT_USER/.Trash/CODE.T.XXXXXXXX")
###テンポラリの不要なファイルを探して
TMP_T_TYPESCRIPT_DIR=$(/bin/ls "$TEMP_DIR_T" | /usr/bin/grep "vscode-typescript")
/bin/echo "$TRASH_DIR"
/bin/echo "$TMP_T_TYPESCRIPT_DIR"
###改行区切りでリストにして
IFS=$'\n'
read -d '\n' -r -a LIST_TYPESCRIPT_DIR <<<"$TMP_T_TYPESCRIPT_DIR"
IFS=''
###リストの中身を順番に処理
for ITEM_LIST_TYPESCRIPT_DIR in "${LIST_TYPESCRIPT_DIR[@]}"; do
  /bin/echo "$ITEM_LIST_TYPESCRIPT_DIR"
  ###ゴミ箱に入れる
  /bin/mv "$TEMP_DIR_T/$ITEM_LIST_TYPESCRIPT_DIR" "$TRASH_DIR"
done


TMP_T_TYPESCRIPT_DIR=$(/bin/ls "$TEMP_DIR_T" | /usr/bin/grep "vscode-git")
/bin/echo "$TRASH_DIR"
/bin/echo "$TMP_T_TYPESCRIPT_DIR"
###改行区切りでリストにして
IFS=$'\n'
read -d '\n' -r -a LIST_TYPESCRIPT_DIR <<<"$TMP_T_TYPESCRIPT_DIR"
IFS=''
###リストの中身を順番に処理
for ITEM_LIST_TYPESCRIPT_DIR in "${LIST_TYPESCRIPT_DIR[@]}"; do
  /bin/echo "$ITEM_LIST_TYPESCRIPT_DIR"
  ###ゴミ箱に入れる
  /bin/mv "$TEMP_DIR_T/$ITEM_LIST_TYPESCRIPT_DIR" "$TRASH_DIR"
done

|

より以前の記事一覧

その他のカテゴリー

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