Bash

[zsh]テンポラリーフォルダをFinderで開く


サンプルコード

サンプルソース(参考)
行番号ソース
001#!/bin/zsh
002#com.cocolog-nifty.quicktimer.icefloe
003#
004#################################################
005###
006/usr/bin/open "$(/usr/bin/dirname "$(/usr/bin/dirname "$(/usr/bin/mktemp -d)")")" || exit
007
008
009exit 0
AppleScriptで生成しました

|

run commands の書き換え


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004# run commands の書き換え
005#
006#com.cocolog-nifty.quicktimer.icefloe
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
008##自分環境がos12なので2.8にしているだけです
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use framework "PrintKit"
013use scripting additions
014
015property refMe : a reference to current application
016
017##############################
018# export
019set listProfile to {"~/.zshrc", "~/.zsh_profile", "~/.bash_profile", "~/.bashrc", "~/.tcshrc", "~/.tcsh_profile", "~/.cshrc", "~/.csh_profile"} as list
020
021set strPrinterName to ("PsPrinterAcrobat9J") as text
022
023repeat with itemProfile in listProfile
024  #
025  set strFilePath to (itemProfile) as text
026  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
027  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
028  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
029  #
030  set listResponse to (refMe's NSMutableString's alloc()'s initWithContentsOfURL:(ocidFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference))
031  set ocidReadString to (item 1 of listResponse)
032  set ocidReadArray to (ocidReadString's componentsSeparatedByString:("\n"))
033  set numCntArray to ocidReadArray's |count|()
034  if numCntArray = 1 then
035    set ocidReadArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0))
036  else
037    repeat with itemNo from (numCntArray - 1) to 0 by -1
038      set ocidLineItem to (ocidReadArray's objectAtIndex:(itemNo))
039      if (ocidLineItem as text) contains "PRINTER" then
040        (ocidReadArray's removeObjectAtIndex:(itemNo))
041      end if
042    end repeat
043  end if
044  if itemProfile contains ".zsh" then
045    (ocidReadArray's addObject:("export PRINTER=" & strPrinterName & "\n"))
046  else if itemProfile contains ".bash" then
047    (ocidReadArray's addObject:("export PRINTER=" & strPrinterName & "\n"))
048  else if itemProfile contains ".csh" then
049    (ocidReadArray's addObject:("setenv PRINTER " & strPrinterName & "\n"))
050  else if itemProfile contains ".tcsh" then
051    (ocidReadArray's addObject:("setenv PRINTER " & strPrinterName & "\n"))
052  end if
053  #
054  set ocidJoinText to (ocidReadArray's componentsJoinedByString:("\n"))
055  log ocidJoinText as text
056  
057  set listDone to (ocidJoinText's writeToURL:(ocidFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference))
058  
059end repeat
AppleScriptで生成しました

|

[bash]タイムアウトさせる


サンプルコード

サンプルソース(参考)
行番号ソース
001#!/bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003
004STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
005
006STR_BIN_PATH="/Users/${STAT_USR}/Applications/Sites/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
007STR_SAVE_PATH="/Users/${STAT_USR}/Desktop/SAVE.PDF"
008STR_READ_URL="file:///Library/WebServer/Documents/_index.html"
009
010
011##タイムアウト設定
012NUM_TIMEOUT=5
013##タイムアウトでエラーさせてエスケープ
014/usr/bin/perl -e 'alarm shift; exec @ARGV' "$NUM_TIMEOUT" "$STR_BIN_PATH" --headless --print-to-pdf="$STR_SAVE_PATH" "$STR_READ_URL"
015
016exit 0
AppleScriptで生成しました

|

[bash]exiftoolインストール(シングルファイル形式のPKG対応)


サンプルコード

サンプルソース(参考)
行番号ソース
001#!/bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003#ユーザード ~/binにインストールする
004# PKGの形式変更に対応したV2
005########################################
006###管理者インストールしているか?チェック
007USER_WHOAMI=$(/usr/bin/whoami)
008/bin/echo "実行ユーザーは:$USER_WHOAMI"
009###実行しているユーザー名
010CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
011/bin/echo "コンソールユーザー:$CONSOLE_USER"
012###ログイン名ユーザー名※Visual Studio Codeの出力パネルではrootになる設定がある
013LOGIN_NAME=$(/usr/bin/logname)
014/bin/echo "ログイン名:$LOGIN_NAME"
015###UID
016USER_NAME=$(/usr/bin/id -un)
017/bin/echo "ユーザー名:$USER_NAME"
018###SUDOUSER
019/bin/echo "SUDO_USER: $SUDO_USER"
020########################################
021##OS
022PLIST_PATH="/System/Library/CoreServices/SystemVersion.plist"
023STR_OS_VER=$(/usr/bin/defaults read "$PLIST_PATH" ProductVersion)
024/bin/echo "OS VERSION :" "$STR_OS_VER"
025STR_MAJOR_VERSION="${STR_OS_VER%%.*}"
026/bin/echo "STR_MAJOR_VERSION :" "$STR_MAJOR_VERSION"
027STR_MINOR_VERSION="${STR_OS_VER#*.}"
028/bin/echo "STR_MINOR_VERSION :" "$STR_MINOR_VERSION"
029########################################
030###ダウンロード起動時に削除する項目
031USER_TEMP_DIR=$(/usr/bin/mktemp -d)
032/bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
033########################################
034##デバイス
035#起動ディスクの名前を取得する
036/bin/mkdir -p "/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID"
037/usr/bin/touch "/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID/diskutil.plist"
038/usr/sbin/chown -R "$CONSOLE_USER" "/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID"
039/bin/chmod -Rf 700 "/Users/$CONSOLE_USER/Documents/Apple"
040/usr/sbin/diskutil info -plist / >"/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID/diskutil.plist"
041STARTUPDISK_NAME=$(/usr/bin/defaults read "/Users/$CONSOLE_USER/Documents/Apple/IOPlatformUUID/diskutil.plist" VolumeName)
042/bin/echo "ボリューム名:" "$STARTUPDISK_NAME"
043############################################################
044############################################################
045###BIN
046/bin/mkdir -p "/Users/$CONSOLE_USER/bin/"
047for ((numTimes = 1; numTimes <= 3; numTimes++)); do
048  sleep 1
049  /bin/mkdir -p "/Users/$CONSOLE_USER/bin/"
050  /usr/bin/touch "/Users/$CONSOLE_USER/bin/"
051  /usr/sbin/chown "$CONSOLE_USER" "/Users/$CONSOLE_USER/bin/"
052  /bin/chmod 700 "/Users/$CONSOLE_USER/bin/"
053done
054# binは不可視にする
055/usr/bin/chflags hidden "/Users/$CONSOLE_USER/bin"
056/usr/bin/SetFile -a V "/Users/$CONSOLE_USER/bin"
057###
058STR_BIN_VERSION=$(/usr/bin/curl -sL "https://exiftool.org/ver.txt")
059/bin/echo "BIN-VERSION:$STR_BIN_VERSION"
060STR_PKG_FILENAME="ExifTool-$STR_BIN_VERSION.pkg"
061###ダウンロードURL
062STR_URL="https://exiftool.org/$STR_PKG_FILENAME"
063###ファイル名を取得
064DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
065/bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
066###ダウンロード
067if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
068  /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
069  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
070    /bin/echo "ファイルのダウンロードに失敗しました"
071    exit 1
072  fi
073fi
074##全ユーザー実行可能にしておく
075/bin/chmod 755 "$USER_TEMP_DIR/$DL_FILE_NAME"
076/bin/echo "ダウンロードOK"
077
078############################################################
079#PGK解凍
080/usr/sbin/pkgutil --expand-full "$USER_TEMP_DIR/$DL_FILE_NAME" "$USER_TEMP_DIR/ExifTool"
081
082###旧バージョンをゴミ箱に
083USER_TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/EXIFTOOL.XXXXXXXX")
084/bin/mv "/Users/$CONSOLE_USER/bin/exiftool" "$USER_TRASH_DIR"
085####
086/bin/mkdir -p "/Users/$CONSOLE_USER/bin/exiftool"
087####複製
088/usr/bin/ditto "$USER_TEMP_DIR/ExifTool/Payload/usr/local/bin" "/Users/$CONSOLE_USER/bin/exiftool"
089####終了
090/bin/echo "インストール終了:" "$CONSOLE_USER"
091
092STR_DONE_VER=$("/Users/$CONSOLE_USER/bin/exiftool/exiftool" -ver)
093/bin/echo "INSTALL-VERSION:$STR_DONE_VER"
094
095open "/Users/$CONSOLE_USER/bin/exiftool"
096exit 0
AppleScriptで生成しました

|

パージョンを取得する(defaults , PlistBuddy,plutil)


あくまでも参考にしてください

サンプルソース(参考)
行番号ソース
001#! /bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003#バージョンを調べる
004#################################################
005#OS  ProductVersion
006/usr/bin/defaults read "/System/Library/CoreServices/SystemVersion.plist" ProductVersion
007#OS ProductUserVisibleVersion
008/usr/libexec/PlistBuddy -c "Print:ProductUserVisibleVersion" "/System/Library/CoreServices/SystemVersion.plist"
009#OS
010/usr/bin/plutil -extract ProductVersion raw -expect string "/System/Library/CoreServices/SystemVersion.plist" 
011
012#################################################
013#アプリケーション CFBundleShortVersionStringの値を取る
014STR_APP_PATH="/Applications/Safari.app"
015STR_PLIST_PATH="${STR_APP_PATH}/Contents/Info.plist"
016#
017/usr/bin/defaults read "$STR_PLIST_PATH" CFBundleShortVersionString
018#
019/usr/libexec/PlistBuddy -c "Print:CFBundleShortVersionString" "$STR_PLIST_PATH"
020#
021/usr/bin/plutil -extract CFBundleShortVersionString raw -expect string "$STR_PLIST_PATH" 
022#################################################
023#アプリケーション CFBundleVersionの値を取る version.plistがある場合
024STR_APP_PATH="/Applications/Safari.app"
025STR_PLIST_PATH="${STR_APP_PATH}/Contents/version.plist"
026#
027/usr/bin/defaults read "$STR_PLIST_PATH" CFBundleVersion
028#
029/usr/libexec/PlistBuddy -c "Print:CFBundleVersion" "$STR_PLIST_PATH"
030#
031/usr/bin/plutil -extract CFBundleVersion raw -expect string "$STR_PLIST_PATH" 
032
033#################################################
034#アプリケーション CFBundleVersionを取得する一般的にはこの方法
035STR_APP_PATH="/Applications/Adobe Acrobat Reader.app"
036STR_PLIST_PATH="${STR_APP_PATH}/Contents/Info.plist"
037#
038/usr/bin/defaults read "$STR_PLIST_PATH" CFBundleVersion
039#
040/usr/libexec/PlistBuddy -c "Print:CFBundleVersion" "$STR_PLIST_PATH"
041#
042/usr/bin/plutil -extract CFBundleVersion raw -expect string "$STR_PLIST_PATH" 
043
044exit 0
AppleScriptで生成しました

|

[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




|

より以前の記事一覧

その他のカテゴリー

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