Admin Locationd

Locationd 位置情報サービス

ダウンロード - locationd.zip


位置情報サービス(Locationd)のON-OFF
登録されたアプリケーションの停止や削除
Bashで処理するしかない
AppleScript版も作成したが、SUDOの挙動が変わってしまったので
(do shell scriptからのsudoに制限がついた)
無理にAppleScript化した感がある。
ただ
PLISTのDICTのキーの値を取れるから、そこは残念


ポイント
1:ディレクトリである『/private/var/db/locationd』はユーザー名グループ名ともに『_locationd』が必須
2:ユーザーUUIDの取得が必要(マルチユーザー環境時には結構ややこしい)
3:デバイスUUIDの取得が必要
4:AppleScriptのdo shell scriptでは処理できない(ターミナル処理が必要)
ぐらいかなぁ

|

Enable2Clients


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 要管理者権限
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


####################################
###パス
####################################
set recordSystemInfo to (system info) as record
set strUNAME to (short user name of recordSystemInfo) as text
##ファイル名 
set strPlistFileName to ("clients.plist") as text
##パス
set strDbDirPath to ("/private/var/db/locationd/") as text
set strFilePath to ("" & strDbDirPath & strPlistFileName & "") as text
##パス
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
####################################
###アクセス権変更
####################################
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown " & strUNAME & " \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown " & strUNAME & " \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)

####################################
###PLIST
####################################

### 読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL)
###AllKey
set ocidAllKyesArray to ocidPlistDict's allKeys()
set listAllKyesArray to ocidAllKyesArray as list

####################################
###ダイアログ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
try
  set listResponse to (choose from list listAllKyesArray with title "選んでください" with prompt "有効にする項目を選んでください" default items (item 1 of listAllKyesArray) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
on error
  ####################################
  ###アクセス権 を戻す
  ####################################
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
  ####################################
  ###アクセス権 を戻す
  ####################################
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
  log "キャンセルしました"
return "キャンセルしました"
end if

####################################
### 本処理項目削除
####################################
repeat with itemResponse in listResponse
  set strItemKey to itemResponse as text
  set ocidSubDict to (ocidPlistDict's objectForKey:(strItemKey))
(ocidSubDict's setValue:(refMe's NSNumber's numberWithBool:true) forKey:("Authorized"))
end repeat


####################################
### 保存
####################################
set listDone to ocidPlistDict's writeToURL:(ocidFilePathURL) |error|:(reference)

####################################
###アクセス権 を戻す
####################################
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)



####################################
## locationd 再起動
####################################
##コマンド
set strCommandText to ("/usr/bin/sudo /usr/bin/killall -HUP locationd") as text
set strResponse to (do shell script strCommandText with administrator privileges) as text
log strResponse







to doCommand2Terminal(argCommandText)
  ##############################
  ## 実行するコマンド
  set strCommandText to argCommandText as text
  ##############################
  tell application "Terminal" to activate
  delay 0.2
  ## 実行中チェック
  tell application "Terminal"
    set numCntWindow to (count of every window) as integer
  end tell
  delay 0.5
  if numCntWindow = 0 then
    log "Windowないので新規で作る"
    tell application "Terminal"
      set objNewWindow to (do script "\n")
    end tell
  else
    log "Windowがある場合は、何か実行中か?をチェック"
    tell application "Terminal"
      tell front window
tell front tab
set boolTabStatus to busy as boolean
set listProcess to processes as list
end tell
      end tell
      set objNewWindow to selected tab of front window
    end tell
    ###前面のタブがbusy=実行中なら新規Window作る
    if boolTabStatus = true then
      tell application "Terminal"
set objNewWindow to (do script "\n")
      end tell
      ###前面のタブにプロセスが無い場合=exit済みの場合は新規Window作る
    else if listProcess = {} then
      tell application "Terminal"
set objNewWindow to (do script "\n")
      end tell
    end if
  end if
  delay 0.5
  ##############################
  ## コマンド実行
  tell application "Terminal"
do script strCommandText in objNewWindow
  end tell
  delay 1
  log "コマンド実行中"
  
  ##############################
  ## コマンド終了チェック
  (*
objNewWindowにWindowIDとTabIDが入っているので
objNewWindowに対してbusyを確認する事で
処理が終わっているか?がわかる
*)
  ## 無限ループ防止で100回
  repeat 100 times
    tell application "Terminal"
      set boolTabStatus to busy of objNewWindow
    end tell
    if boolTabStatus is false then
      log "コマンド処理終了しました"
      tell application "Terminal"
tell front window
tell front tab
set listProcess to processes as list
end tell
end tell
      end tell
      set numCntProcess to (count of listProcess) as integer
      if numCntProcess ≤ 2 then
exit repeat
      else
delay 1
      end if
      --->このリピートを抜けて次の処理へ
    else if boolTabStatus is true then
      log "コマンド処理中"
      delay 1
      --->busyなのであと1秒まつ
    end if
  end repeat
  
  ##############################
  ## exit打って終了
  tell application "Terminal"
do script "exit" in objNewWindow
  end tell
  ##############################
  ## exitの処理待ちしてClose
  repeat 20 times
    tell application "Terminal"
      tell front window
tell front tab
set listProcess to processes as list
end tell
      end tell
    end tell
    if listProcess = {} then
      tell application "Terminal"
tell front window
# tell front tab
close saving no
# end tell
end tell
      end tell
      exit repeat
    else
      delay 1
    end if
  end repeat
  
  
  
end doCommand2Terminal


|

Disable2Clients


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 要管理者権限
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


####################################
###パス
####################################
set recordSystemInfo to (system info) as record
set strUNAME to (short user name of recordSystemInfo) as text
##ファイル名 
set strPlistFileName to ("clients.plist") as text
##パス
set strDbDirPath to ("/private/var/db/locationd/") as text
set strFilePath to ("" & strDbDirPath & strPlistFileName & "") as text
##パス
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
####################################
###アクセス権変更
####################################
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown " & strUNAME & " \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown " & strUNAME & " \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)

####################################
###PLIST
####################################

### 読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL)
###AllKey
set ocidAllKyesArray to ocidPlistDict's allKeys()
set listAllKyesArray to ocidAllKyesArray as list

####################################
###ダイアログ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
try
  set listResponse to (choose from list listAllKyesArray with title "選んでください" with prompt "無効にする項目を選んでください" default items (item 1 of listAllKyesArray) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
on error
  ####################################
  ###アクセス権 を戻す
  ####################################
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
  ####################################
  ###アクセス権 を戻す
  ####################################
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
  log "キャンセルしました"
return "キャンセルしました"
end if

####################################
### 本処理項目削除
####################################
repeat with itemResponse in listResponse
  set strItemKey to itemResponse as text
  set ocidSubDict to (ocidPlistDict's objectForKey:(strItemKey))
(ocidSubDict's setValue:(refMe's NSNumber's numberWithBool:false) forKey:("Authorized"))
end repeat


####################################
### 保存
####################################
set listDone to ocidPlistDict's writeToURL:(ocidFilePathURL) |error|:(reference)

####################################
###アクセス権 を戻す
####################################
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)



####################################
## locationd 再起動
####################################
##コマンド
set strCommandText to ("/usr/bin/sudo /usr/bin/killall -HUP locationd") as text
set strResponse to (do shell script strCommandText with administrator privileges) as text
log strResponse







to doCommand2Terminal(argCommandText)
  ##############################
  ## 実行するコマンド
  set strCommandText to argCommandText as text
  ##############################
  tell application "Terminal" to activate
  delay 0.2
  ## 実行中チェック
  tell application "Terminal"
    set numCntWindow to (count of every window) as integer
  end tell
  delay 0.5
  if numCntWindow = 0 then
    log "Windowないので新規で作る"
    tell application "Terminal"
      set objNewWindow to (do script "\n")
    end tell
  else
    log "Windowがある場合は、何か実行中か?をチェック"
    tell application "Terminal"
      tell front window
tell front tab
set boolTabStatus to busy as boolean
set listProcess to processes as list
end tell
      end tell
      set objNewWindow to selected tab of front window
    end tell
    ###前面のタブがbusy=実行中なら新規Window作る
    if boolTabStatus = true then
      tell application "Terminal"
set objNewWindow to (do script "\n")
      end tell
      ###前面のタブにプロセスが無い場合=exit済みの場合は新規Window作る
    else if listProcess = {} then
      tell application "Terminal"
set objNewWindow to (do script "\n")
      end tell
    end if
  end if
  delay 0.5
  ##############################
  ## コマンド実行
  tell application "Terminal"
do script strCommandText in objNewWindow
  end tell
  delay 1
  log "コマンド実行中"
  
  ##############################
  ## コマンド終了チェック
  (*
objNewWindowにWindowIDとTabIDが入っているので
objNewWindowに対してbusyを確認する事で
処理が終わっているか?がわかる
*)
  ## 無限ループ防止で100回
  repeat 100 times
    tell application "Terminal"
      set boolTabStatus to busy of objNewWindow
    end tell
    if boolTabStatus is false then
      log "コマンド処理終了しました"
      tell application "Terminal"
tell front window
tell front tab
set listProcess to processes as list
end tell
end tell
      end tell
      set numCntProcess to (count of listProcess) as integer
      if numCntProcess ≤ 2 then
exit repeat
      else
delay 1
      end if
      --->このリピートを抜けて次の処理へ
    else if boolTabStatus is true then
      log "コマンド処理中"
      delay 1
      --->busyなのであと1秒まつ
    end if
  end repeat
  
  ##############################
  ## exit打って終了
  tell application "Terminal"
do script "exit" in objNewWindow
  end tell
  ##############################
  ## exitの処理待ちしてClose
  repeat 20 times
    tell application "Terminal"
      tell front window
tell front tab
set listProcess to processes as list
end tell
      end tell
    end tell
    if listProcess = {} then
      tell application "Terminal"
tell front window
# tell front tab
close saving no
# end tell
end tell
      end tell
      exit repeat
    else
      delay 1
    end if
  end repeat
  
  
  
end doCommand2Terminal


|

Delete2Clients


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 要管理者権限
# 苦肉の策でターミナル起動するので一般利用には向かない
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "Appkit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


####################################
###パス
####################################
set recordSystemInfo to (system info) as record
set strUNAME to (short user name of recordSystemInfo) as text
##ファイル名 
set strPlistFileName to ("clients.plist") as text
##パス
set strDbDirPath to ("/private/var/db/locationd/") as text
set strFilePath to ("" & strDbDirPath & strPlistFileName & "") as text
##パス
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
####################################
###アクセス権変更
####################################
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown " & strUNAME & " \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown " & strUNAME & " \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)

####################################
###PLIST
####################################

### 読み込み
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL)
###AllKey
set ocidAllKyesArray to ocidPlistDict's allKeys()
set listAllKyesArray to ocidAllKyesArray as list

####################################
###ダイアログ
####################################
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder"
    activate
  end tell
else
  tell current application
    activate
  end tell
end if
try
  tell application "Script Editor" to activate
  set listResponse to (choose from list listAllKyesArray with title "選んでください" with prompt "削除する項目を選んでください" default items (item 1 of listAllKyesArray) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed) as list
on error
  ####################################
  ###アクセス権 を戻す
  ####################################
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
  log "エラーしました"
return "エラーしました"
end try
if (item 1 of listResponse) is false then
  ####################################
  ###アクセス権 を戻す
  ####################################
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
  set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)
  log "キャンセルしました"
return "キャンセルしました"
end if

####################################
### 本処理項目削除
####################################
repeat with itemResponse in listResponse
  set strItemKey to itemResponse as text
(ocidPlistDict's removeObjectForKey:(strItemKey))
  
end repeat


####################################
### 保存
####################################
set listDone to ocidPlistDict's writeToURL:(ocidFilePathURL) |error|:(reference)

####################################
###アクセス権 を戻す
####################################
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strFilePath & "\"") as text
doCommand2Terminal(strCommandText)
set strCommandText to ("/usr/bin/sudo /usr/sbin/chown _locationd \"" & strDbDirPath & "\"") as text
doCommand2Terminal(strCommandText)



####################################
## locationd 再起動
####################################
##コマンド
set strCommandText to ("/usr/bin/sudo /usr/bin/killall -HUP locationd") as text
set strResponse to (do shell script strCommandText with administrator privileges) as text
log strResponse







to doCommand2Terminal(argCommandText)
  ##############################
  ## 実行するコマンド
  set strCommandText to argCommandText as text
  ##############################
  tell application "Terminal" to activate
  delay 0.2
  ## 実行中チェック
  tell application "Terminal"
    set numCntWindow to (count of every window) as integer
  end tell
  delay 0.5
  if numCntWindow = 0 then
    log "Windowないので新規で作る"
    tell application "Terminal"
      set objNewWindow to (do script "\n")
    end tell
  else
    log "Windowがある場合は、何か実行中か?をチェック"
    tell application "Terminal"
      tell front window
tell front tab
set boolTabStatus to busy as boolean
set listProcess to processes as list
end tell
      end tell
      set objNewWindow to selected tab of front window
    end tell
    ###前面のタブがbusy=実行中なら新規Window作る
    if boolTabStatus = true then
      tell application "Terminal"
set objNewWindow to (do script "\n")
      end tell
      ###前面のタブにプロセスが無い場合=exit済みの場合は新規Window作る
    else if listProcess = {} then
      tell application "Terminal"
set objNewWindow to (do script "\n")
      end tell
    end if
  end if
  delay 0.5
  ##############################
  ## コマンド実行
  tell application "Terminal"
do script strCommandText in objNewWindow
  end tell
  delay 1
  log "コマンド実行中"
  
  ##############################
  ## コマンド終了チェック
  (*
objNewWindowにWindowIDとTabIDが入っているので
objNewWindowに対してbusyを確認する事で
処理が終わっているか?がわかる
*)
  ## 無限ループ防止で100回
  repeat 100 times
    tell application "Terminal"
      set boolTabStatus to busy of objNewWindow
    end tell
    if boolTabStatus is false then
      log "コマンド処理終了しました"
      tell application "Terminal"
tell front window
tell front tab
set listProcess to processes as list
end tell
end tell
      end tell
      set numCntProcess to (count of listProcess) as integer
      if numCntProcess ≤ 2 then
exit repeat
      else
delay 1
      end if
      --->このリピートを抜けて次の処理へ
    else if boolTabStatus is true then
      log "コマンド処理中"
      delay 1
      --->busyなのであと1秒まつ
    end if
  end repeat
  
  ##############################
  ## exit打って終了
  tell application "Terminal"
do script "exit" in objNewWindow
  end tell
  ##############################
  ## exitの処理待ちしてClose
  repeat 20 times
    tell application "Terminal"
      tell front window
tell front tab
set listProcess to processes as list
end tell
      end tell
    end tell
    if listProcess = {} then
      tell application "Terminal"
tell front window
# tell front tab
close saving no
# end tell
end tell
      end tell
      exit repeat
    else
      delay 1
    end if
  end repeat
  
  
  
end doCommand2Terminal


|

[bash]clientsKeyList

基本はユーザーのUUIDとバンドルIDの組み合わせ

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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
# 要管理者権限
########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー:$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 "↑を実行してください"
  exit 1
else
  ###実行しているユーザー名
  SUDO_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
  /bin/echo "実行したユーザー:" "$SUDO_USER"
fi
########################################
###デバイスUUIDを取得する
STR_DEVICE_UUID=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID/{print $3}')
/bin/echo "デバイスUUID:" "$STR_DEVICE_UUID"
########################################
###USERのUUID
STR_USER_UUID=$(/usr/bin/dscl localhost -list /Local/Default/Users GeneratedUID | grep "$SUDO_USER" | /usr/bin/awk '/ / { print $2 }')
/bin/echo "ユーザーUUID:" "$STR_USER_UUID"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###notbackedup 分
STR_DIR_PATH="/private/var/db/locationd/Library/Preferences/ByHost/"
STR_FILE_NAME="com.apple.locationd.notbackedup.$STR_DEVICE_UUID.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
###Backup
/usr/bin/sudo -u "$SUDO_USER"  /bin/mkdir -p "/Users/$SUDO_USER/Documents/Apple/Locationd"
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
###通常分
STR_DIR_PATH="/private/var/db/locationd/Library/Preferences/ByHost/"
STR_FILE_NAME="com.apple.locationd.$STR_DEVICE_UUID.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
###Backup
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
########################################
###locationd
STR_DIR_PATH="/private/var/db/locationd/"
STR_FILE_NAME="clients.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
########################################
###Backup
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
###アクセス権
/usr/sbin/chown -R  "$SUDO_USER"  "/Users/$SUDO_USER/Documents/Apple/Locationd"
/bin/chmod -R 755 "/Users/$SUDO_USER/Documents/Apple/Locationd"
/bin/echo "PLISTバックアップ:/Users/$SUDO_USER/Documents/Apple/Locationd"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###notbackedup 分
STR_DIR_PATH="/private/var/db/locationd/"
STR_FILE_NAME="clients.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
STR_RESPONSE=$(/usr/bin/sudo -u _locationd /usr/bin/defaults read "$STR_PLIST_PATH")
# STR_CNT=$(/bin/echo "$STR_RESPONSE" | /usr/bin/tr -d -c '}' | /usr/bin/wc -m)
STR_CNT=$(/bin/echo "$STR_RESPONSE" | /usr/bin/grep -o 'BundleId' | /usr/bin/wc -l)
/bin/echo "登録されているアプリケーション数:$STR_CNT"
###主要リストを取得する場合
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###ユーザーが呼び出している項目
STR_KEY=$(/usr/libexec/PlistBuddy -c "Print :" "$STR_PLIST_PATH" |/usr/bin/grep Dict | /usr/bin/awk '{print $1}' | grep "$STR_USER_UUID")
/bin/echo "キーの一覧"
/bin/echo "$STR_KEY"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###rootで呼び出している項目
STR_KEY=$(/usr/libexec/PlistBuddy -c "Print :" "$STR_PLIST_PATH" |/usr/bin/grep Dict | /usr/bin/awk '{print $1}' | grep root )
/bin/echo "$STR_KEY"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###アクセス権メンテナンス
/bin/echo "アクセス権メンテナンス:$STR_PLIST_PATH"
/usr/bin/chgrp -R _locationd "$STR_PLIST_PATH"
/bin/echo "/usr/bin/chgrp -R _locationd $STR_PLIST_PATH"
/bin/echo "↑ 実行したコマンド"

/usr/sbin/chown -R _locationd "$STR_PLIST_PATH"
/bin/echo "/usr/sbin/chown -R _locationd $STR_PLIST_PATH"
/bin/echo "↑ 実行したコマンド"

STR_DIR_PATH="/private/var/db/locationd"
/usr/sbin/chown -R _locationd "$STR_DIR_PATH"
/bin/echo "/usr/sbin/chown -R _locationd $STR_DIR_PATH"
/bin/echo "↑ 実行したコマンド"

exit 0

|

[bash]clients設定確認


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
# 要管理者権限
########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー:$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 "↑を実行してください"
  exit 1
else
  ###実行しているユーザー名
  SUDO_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
  /bin/echo "実行したユーザー:" "$SUDO_USER"
fi
########################################
###デバイスUUIDを取得する
STR_DEVICE_UUID=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID/{print $3}')
/bin/echo "デバイスUUID:" "$STR_DEVICE_UUID"
########################################
###USERのUUID
STR_USER_UUID=$(/usr/bin/dscl localhost -list /Local/Default/Users GeneratedUID | grep "$SUDO_USER" | /usr/bin/awk '/ / { print $2 }')
/bin/echo "ユーザーUUID:" "$STR_USER_UUID"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###notbackedup 分
STR_DIR_PATH="/private/var/db/locationd/Library/Preferences/ByHost/"
STR_FILE_NAME="com.apple.locationd.notbackedup.$STR_DEVICE_UUID.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
###Backup
/usr/bin/sudo -u "$SUDO_USER"  /bin/mkdir -p "/Users/$SUDO_USER/Documents/Apple/Locationd"
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
###通常分
STR_DIR_PATH="/private/var/db/locationd/Library/Preferences/ByHost/"
STR_FILE_NAME="com.apple.locationd.$STR_DEVICE_UUID.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
###Backup
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
########################################
###locationd
STR_DIR_PATH="/private/var/db/locationd/"
STR_FILE_NAME="clients.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
########################################
###Backup
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
###アクセス権
/usr/sbin/chown -R  "$SUDO_USER"  "/Users/$SUDO_USER/Documents/Apple/Locationd"
/bin/chmod -R 755 "/Users/$SUDO_USER/Documents/Apple/Locationd"
/bin/echo "PLISTバックアップ:/Users/$SUDO_USER/Documents/Apple/Locationd"
########################################
###
STR_RESPONSE=$(/usr/bin/sudo -u _locationd /usr/bin/defaults read "$STR_PLIST_PATH")
# STR_CNT=$(/bin/echo "$STR_RESPONSE" | /usr/bin/tr -d -c '}' | /usr/bin/wc -m)
STR_CNT=$(/bin/echo "$STR_RESPONSE" | /usr/bin/grep -o '};' | /usr/bin/wc -l)
/bin/echo "登録されているアプリケーション数:$STR_CNT"
###主要リストを取得する場合
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###ユーザーが呼び出している項目
STR_KEY=$(/usr/libexec/PlistBuddy -c "Print :" "$STR_PLIST_PATH" |/usr/bin/grep Dict | /usr/bin/awk '{print $1}' | grep "$STR_USER_UUID")
/bin/echo "キーの一覧"
###戻り値をリストにする
IFS=$'\n' read -r -d '' -a LIST_UUID_BUNDLEID <<< "$STR_KEY"
###リストの数だけ繰り返し
for ITEM_UUID_BUNDLEID in "${LIST_UUID_BUNDLEID[@]}"; do
/bin/echo "キー:$ITEM_UUID_BUNDLEID"
###PlistBuddy用に:をエスケープしておく
ESCAPED_UUID_BUNDLEID="${ITEM_UUID_BUNDLEID//:/\\:}"
###許可しているか?
    STR_AUTHORIZED=$(/usr/libexec/PlistBuddy -c "Print:$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "使用:$STR_AUTHORIZED"
###バンドルID
    STR_BUNDLEID=$(/usr/libexec/PlistBuddy -c "Print:$ESCAPED_UUID_BUNDLEID:BundleId" "$STR_PLIST_PATH")
/bin/echo "バンドルID:$STR_BUNDLEID"
###バンドルパス
    STR_BUNDLEPATH=$(/usr/libexec/PlistBuddy -c "Print:$ESCAPED_UUID_BUNDLEID:BundlePath" "$STR_PLIST_PATH")
/bin/echo "パス:$STR_BUNDLEPATH"
done
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###rootで呼び出している項目
STR_KEY=$(/usr/libexec/PlistBuddy -c "Print :" "$STR_PLIST_PATH" |/usr/bin/grep Dict | /usr/bin/awk '{print $1}' | grep root )
/bin/echo "キーの一覧"
###戻り値をリストにする
IFS=$'\n' read -r -d '' -a LIST_UUID_BUNDLEID <<< "$STR_KEY"
###リストの数だけ繰り返し
for ITEM_UUID_BUNDLEID in "${LIST_UUID_BUNDLEID[@]}"; do
/bin/echo "キー:$ITEM_UUID_BUNDLEID"
###PlistBuddy用に:をエスケープしておく
ESCAPED_UUID_BUNDLEID="${ITEM_UUID_BUNDLEID//:/\\:}"
###許可しているか?
    STR_AUTHORIZED=$(/usr/libexec/PlistBuddy -c "Print:$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "使用:$STR_AUTHORIZED"
###バンドルID
    STR_BUNDLEID=$(/usr/libexec/PlistBuddy -c "Print:$ESCAPED_UUID_BUNDLEID:BundleId" "$STR_PLIST_PATH")
/bin/echo "バンドルID:$STR_BUNDLEID"
###バンドルパス
    STR_BUNDLEPATH=$(/usr/libexec/PlistBuddy -c "Print:$ESCAPED_UUID_BUNDLEID:BundlePath" "$STR_PLIST_PATH")
/bin/echo "パス:$STR_BUNDLEPATH"
done

########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###アクセス権メンテナンス
/bin/echo "アクセス権メンテナンス:$STR_PLIST_PATH"
/usr/bin/chgrp -R _locationd "$STR_PLIST_PATH"
/bin/echo "/usr/bin/chgrp -R _locationd $STR_PLIST_PATH"
/bin/echo "↑ 実行したコマンド"

/usr/sbin/chown -R _locationd "$STR_PLIST_PATH"
/bin/echo "/usr/sbin/chown -R _locationd $STR_PLIST_PATH"
/bin/echo "↑ 実行したコマンド"

STR_DIR_PATH="/private/var/db/locationd"
/usr/sbin/chown -R _locationd "$STR_DIR_PATH"
/bin/echo "/usr/sbin/chown -R _locationd $STR_DIR_PATH"
/bin/echo "↑ 実行したコマンド"

exit 0

|

[bash]clients全部無効設定


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
# 要管理者権限
########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー:$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 "↑を実行してください"
  exit 1
else
  ###実行しているユーザー名
  SUDO_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
  /bin/echo "実行したユーザー:" "$SUDO_USER"
fi
########################################
###デバイスUUIDを取得する
STR_DEVICE_UUID=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID/{print $3}')
/bin/echo "デバイスUUID:" "$STR_DEVICE_UUID"
########################################
###USERのUUID
STR_USER_UUID=$(/usr/bin/dscl localhost -list /Local/Default/Users GeneratedUID | grep "$SUDO_USER" | /usr/bin/awk '/ / { print $2 }')
/bin/echo "ユーザーUUID:" "$STR_USER_UUID"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###notbackedup 分
STR_DIR_PATH="/private/var/db/locationd/Library/Preferences/ByHost/"
STR_FILE_NAME="com.apple.locationd.notbackedup.$STR_DEVICE_UUID.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
###Backup
/usr/bin/sudo -u "$SUDO_USER"  /bin/mkdir -p "/Users/$SUDO_USER/Documents/Apple/Locationd"
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
###通常分
STR_DIR_PATH="/private/var/db/locationd/Library/Preferences/ByHost/"
STR_FILE_NAME="com.apple.locationd.$STR_DEVICE_UUID.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
###Backup
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
########################################
###locationd
STR_DIR_PATH="/private/var/db/locationd/"
STR_FILE_NAME="clients.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
########################################
###Backup
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
###アクセス権
/usr/sbin/chown -R  "$SUDO_USER"  "/Users/$SUDO_USER/Documents/Apple/Locationd"
/bin/chmod -R 755 "/Users/$SUDO_USER/Documents/Apple/Locationd"
/bin/echo "PLISTバックアップ:/Users/$SUDO_USER/Documents/Apple/Locationd"

########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###locationd
STR_DIR_PATH="/private/var/db/locationd/"
STR_FILE_NAME="clients.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
STR_RESPONSE=$(/usr/bin/sudo -u _locationd /usr/bin/defaults read "$STR_PLIST_PATH")
# STR_CNT=$(/bin/echo "$STR_RESPONSE" | /usr/bin/tr -d -c '}' | /usr/bin/wc -m)
STR_CNT_A=$(/bin/echo "$STR_RESPONSE" | /usr/bin/grep -o 'BundleId' | /usr/bin/wc -l)
STR_CNT_B=$(/bin/echo "$STR_RESPONSE" | /usr/bin/grep -o 'SLC' | /usr/bin/wc -l)
STR_CNT=$((STR_CNT_A + STR_CNT_B))
/bin/echo "登録されているアプリケーション数:$STR_CNT"

########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###ユーザーが呼び出している項目
STR_KEY=$(/usr/libexec/PlistBuddy -c "Print :" "$STR_PLIST_PATH" |/usr/bin/grep Dict | /usr/bin/awk '{print $1}' | grep "$STR_USER_UUID")
/bin/echo "キーの一覧"
###戻り値をリストにする
IFS=$'\n' read -r -d '' -a LIST_UUID_BUNDLEID <<< "$STR_KEY"
###リストの数だけ繰り返し
for ITEM_UUID_BUNDLEID in "${LIST_UUID_BUNDLEID[@]}"; do
/bin/echo "キー:$ITEM_UUID_BUNDLEID"
###PlistBuddy用に:をエスケープしておく
ESCAPED_UUID_BUNDLEID="${ITEM_UUID_BUNDLEID//:/\\:}"
###許可しているか?
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Print :$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "設定前:$STR_AUTHORIZED"
#STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/bin/defaults write "$STR_PLIST_PATH" "$ITEM_UUID_BUNDLEID" -dict-add Authorized -boolean false)
#STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/bin/defaults write "$STR_PLIST_PATH" "$ITEM_UUID_BUNDLEID" -dict Authorized -boolean false)
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Add :$ESCAPED_UUID_BUNDLEID:Authorized bool" "$STR_PLIST_PATH")
/bin/echo "設定:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Set :$ESCAPED_UUID_BUNDLEID:Authorized false" "$STR_PLIST_PATH")
/bin/echo "設定:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Print :$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "設定後:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Save" "$STR_PLIST_PATH")
/bin/echo "保存:$STR_AUTHORIZED"
sleep 0.25
done

########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###rootで呼び出している項目
STR_KEY=$(/usr/libexec/PlistBuddy -c "Print :" "$STR_PLIST_PATH" |/usr/bin/grep Dict | /usr/bin/awk '{print $1}' | grep root )
/bin/echo "キーの一覧"
###戻り値をリストにする
IFS=$'\n' read -r -d '' -a LIST_UUID_BUNDLEID <<< "$STR_KEY"
###リストの数だけ繰り返し
for ITEM_UUID_BUNDLEID in "${LIST_UUID_BUNDLEID[@]}"; do
/bin/echo "キー:$ITEM_UUID_BUNDLEID"
###PlistBuddy用に:をエスケープしておく
ESCAPED_UUID_BUNDLEID="${ITEM_UUID_BUNDLEID//:/\\:}"
###許可しているか?
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Print :$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "設定前:$STR_AUTHORIZED"
#STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/bin/defaults write "$STR_PLIST_PATH" "$ITEM_UUID_BUNDLEID" -dict-add Authorized -boolean false)
#STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/bin/defaults write "$STR_PLIST_PATH" "$ITEM_UUID_BUNDLEID" -dict Authorized -boolean false)
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Add :$ESCAPED_UUID_BUNDLEID:Authorized bool" "$STR_PLIST_PATH")
/bin/echo "設定:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Set :$ESCAPED_UUID_BUNDLEID:Authorized false" "$STR_PLIST_PATH")
/bin/echo "設定:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Print :$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "設定後:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Save" "$STR_PLIST_PATH")
/bin/echo "保存:$STR_AUTHORIZED"
sleep 0.25
done
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###アクセス権メンテナンス
/bin/echo "アクセス権メンテナンス:$STR_PLIST_PATH"
/usr/bin/chgrp -R _locationd "$STR_PLIST_PATH"
/bin/echo "/usr/bin/chgrp -R _locationd $STR_PLIST_PATH"
/bin/echo "↑ 実行したコマンド"

/usr/sbin/chown -R _locationd "$STR_PLIST_PATH"
/bin/echo "/usr/sbin/chown -R _locationd $STR_PLIST_PATH"
/bin/echo "↑ 実行したコマンド"

STR_DIR_PATH="/private/var/db/locationd"
/usr/sbin/chown -R _locationd "$STR_DIR_PATH"
/bin/echo "/usr/sbin/chown -R _locationd $STR_DIR_PATH"
/bin/echo "↑ 実行したコマンド"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
/bin/echo "locationd 再起動"
STR_RESPONSE=$(/usr/bin/killall -HUP locationd)
/bin/echo "/usr/bin/killall -HUP locationd"
/bin/echo "↑ 実行したコマンド "
/bin/echo "$STR_RESPONSE"
exit 0



|

[bash]clients全部有効設定


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
# 要管理者権限
########################################
###管理者インストールしているか?チェック
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行ユーザー:$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 "↑を実行してください"
  exit 1
else
  ###実行しているユーザー名
  SUDO_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
  /bin/echo "実行したユーザー:" "$SUDO_USER"
fi
########################################
###デバイスUUIDを取得する
STR_DEVICE_UUID=$(/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID/{print $3}')
/bin/echo "デバイスUUID:" "$STR_DEVICE_UUID"
########################################
###USERのUUID
STR_USER_UUID=$(/usr/bin/dscl localhost -list /Local/Default/Users GeneratedUID | grep "$SUDO_USER" | /usr/bin/awk '/ / { print $2 }')
/bin/echo "ユーザーUUID:" "$STR_USER_UUID"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###notbackedup 分
STR_DIR_PATH="/private/var/db/locationd/Library/Preferences/ByHost/"
STR_FILE_NAME="com.apple.locationd.notbackedup.$STR_DEVICE_UUID.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
###Backup
/usr/bin/sudo -u "$SUDO_USER"  /bin/mkdir -p "/Users/$SUDO_USER/Documents/Apple/Locationd"
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
###通常分
STR_DIR_PATH="/private/var/db/locationd/Library/Preferences/ByHost/"
STR_FILE_NAME="com.apple.locationd.$STR_DEVICE_UUID.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
###Backup
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
########################################
###locationd
STR_DIR_PATH="/private/var/db/locationd/"
STR_FILE_NAME="clients.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
########################################
###Backup
/usr/bin/ditto "$STR_PLIST_PATH" "/Users/$SUDO_USER/Documents/Apple/Locationd/$STR_FILE_NAME"
###アクセス権
/usr/sbin/chown -R  "$SUDO_USER"  "/Users/$SUDO_USER/Documents/Apple/Locationd"
/bin/chmod -R 755 "/Users/$SUDO_USER/Documents/Apple/Locationd"
/bin/echo "PLISTバックアップ:/Users/$SUDO_USER/Documents/Apple/Locationd"

########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###locationd
STR_DIR_PATH="/private/var/db/locationd/"
STR_FILE_NAME="clients.plist"
STR_PLIST_PATH="$STR_DIR_PATH$STR_FILE_NAME"
/bin/echo "PLISTファイルパス:$STR_PLIST_PATH"
STR_RESPONSE=$(/usr/bin/sudo -u _locationd /usr/bin/defaults read "$STR_PLIST_PATH")
# STR_CNT=$(/bin/echo "$STR_RESPONSE" | /usr/bin/tr -d -c '}' | /usr/bin/wc -m)
STR_CNT_A=$(/bin/echo "$STR_RESPONSE" | /usr/bin/grep -o 'BundleId' | /usr/bin/wc -l)
STR_CNT_B=$(/bin/echo "$STR_RESPONSE" | /usr/bin/grep -o 'SLC' | /usr/bin/wc -l)
STR_CNT=$((STR_CNT_A + STR_CNT_B))
/bin/echo "登録されているアプリケーション数:$STR_CNT"

########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###ユーザーが呼び出している項目
STR_KEY=$(/usr/libexec/PlistBuddy -c "Print :" "$STR_PLIST_PATH" |/usr/bin/grep Dict | /usr/bin/awk '{print $1}' | grep "$STR_USER_UUID")
/bin/echo "キーの一覧"
###戻り値をリストにする
IFS=$'\n' read -r -d '' -a LIST_UUID_BUNDLEID <<< "$STR_KEY"
###リストの数だけ繰り返し
for ITEM_UUID_BUNDLEID in "${LIST_UUID_BUNDLEID[@]}"; do
/bin/echo "キー:$ITEM_UUID_BUNDLEID"
###PlistBuddy用に:をエスケープしておく
ESCAPED_UUID_BUNDLEID="${ITEM_UUID_BUNDLEID//:/\\:}"
###許可しているか?
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Print :$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "設定前:$STR_AUTHORIZED"
#STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/bin/defaults write "$STR_PLIST_PATH" "$ITEM_UUID_BUNDLEID" -dict-add Authorized -boolean true)
#STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/bin/defaults write "$STR_PLIST_PATH" "$ITEM_UUID_BUNDLEID" -dict Authorized -boolean true)
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Add :$ESCAPED_UUID_BUNDLEID:Authorized bool" "$STR_PLIST_PATH")
/bin/echo "設定:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Set :$ESCAPED_UUID_BUNDLEID:Authorized true" "$STR_PLIST_PATH")
/bin/echo "設定:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Print :$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "設定後:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Save" "$STR_PLIST_PATH")
/bin/echo "保存:$STR_AUTHORIZED"
sleep 0.25
done

########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###rootで呼び出している項目
STR_KEY=$(/usr/libexec/PlistBuddy -c "Print :" "$STR_PLIST_PATH" |/usr/bin/grep Dict | /usr/bin/awk '{print $1}' | grep root )
/bin/echo "キーの一覧"
###戻り値をリストにする
IFS=$'\n' read -r -d '' -a LIST_UUID_BUNDLEID <<< "$STR_KEY"
###リストの数だけ繰り返し
for ITEM_UUID_BUNDLEID in "${LIST_UUID_BUNDLEID[@]}"; do
/bin/echo "キー:$ITEM_UUID_BUNDLEID"
###PlistBuddy用に:をエスケープしておく
ESCAPED_UUID_BUNDLEID="${ITEM_UUID_BUNDLEID//:/\\:}"
###許可しているか?
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Print :$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "設定前:$STR_AUTHORIZED"
#STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/bin/defaults write "$STR_PLIST_PATH" "$ITEM_UUID_BUNDLEID" -dict-add Authorized -boolean true)
#STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/bin/defaults write "$STR_PLIST_PATH" "$ITEM_UUID_BUNDLEID" -dict Authorized -boolean true)
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Add :$ESCAPED_UUID_BUNDLEID:Authorized bool" "$STR_PLIST_PATH")
/bin/echo "設定:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Set :$ESCAPED_UUID_BUNDLEID:Authorized true" "$STR_PLIST_PATH")
/bin/echo "設定:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Print :$ESCAPED_UUID_BUNDLEID:Authorized" "$STR_PLIST_PATH")
/bin/echo "設定後:$STR_AUTHORIZED"
STR_AUTHORIZED=$(/usr/bin/sudo -u _locationd /usr/libexec/PlistBuddy -c "Save" "$STR_PLIST_PATH")
/bin/echo "保存:$STR_AUTHORIZED"
sleep 0.25
done
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
###アクセス権メンテナンス
/bin/echo "アクセス権メンテナンス:$STR_PLIST_PATH"
/usr/bin/chgrp -R _locationd "$STR_PLIST_PATH"
/bin/echo "/usr/bin/chgrp -R _locationd $STR_PLIST_PATH"
/bin/echo "↑ 実行したコマンド"

/usr/sbin/chown -R _locationd "$STR_PLIST_PATH"
/bin/echo "/usr/sbin/chown -R _locationd $STR_PLIST_PATH"
/bin/echo "↑ 実行したコマンド"

STR_DIR_PATH="/private/var/db/locationd"
/usr/sbin/chown -R _locationd "$STR_DIR_PATH"
/bin/echo "/usr/sbin/chown -R _locationd $STR_DIR_PATH"
/bin/echo "↑ 実行したコマンド"
########################################
/bin/echo "----+----1----+----2----+-----3----+----4----+----5----+----6----+----7"
/bin/echo "locationd 再起動"
STR_RESPONSE=$(/usr/bin/killall -HUP locationd)
/bin/echo "/usr/bin/killall -HUP locationd"
/bin/echo "↑ 実行したコマンド "
/bin/echo "$STR_RESPONSE"
exit 0



|

locationd再起動


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

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

####################################
## locationd 再起動
####################################
##コマンド
set strCommandText to ("/usr/bin/sudo /usr/bin/killall -HUP locationd") as text
set strResponse to (do shell script strCommandText with administrator privileges) as text
log strResponse

|

Locationd設定確認


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

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



###デバイスUUIDを取得する
set strCommandText to ("/usr/sbin/system_profiler SPHardwareDataType | /usr/bin/awk '/Hardware UUID/{print $3}'") as text
set strDeviceUUID to (do shell script strCommandText) as text
###ディレクトリ
set strPrefDirPath to ("/private/var/db/locationd/Library/Preferences/ByHost/") as text
####################################
##ファイル名
set strFileName to ("com.apple.locationd.notbackedup." & strDeviceUUID & ".plist") as text
##パス
set strPlistFilePath to (strPrefDirPath & strFileName) as text
##コマンド
set strCommandText to ("/usr/bin/sudo -u _locationd /usr/bin/defaults read \"" & strPlistFilePath & "\" LocationServicesEnabled -boolean") as text
##実行
set strResponse to (do shell script strCommandText with administrator privileges) as text
log "notbackedup:" & strResponse

####################################
##ファイル名
set strFileName to ("com.apple.locationd." & strDeviceUUID & ".plist") as text
##パス
set strPlistFilePath to (strPrefDirPath & strFileName) as text
##コマンド
set strCommandText to ("/usr/bin/sudo -u _locationd /usr/bin/defaults read \"" & strPlistFilePath & "\" LocationServicesEnabled -boolean") as text
##実行
set strResponse to (do shell script strCommandText with administrator privileges) as text
log "LocationServicesEnabled:" & strResponse

log "0=FALSE=無効 1=TRUE=有効"


|

より以前の記事一覧

その他のカテゴリー

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