DropBox

[bash] インストールDropBox


サンプルコード

サンプルソース(参考)
行番号ソース
001#!/bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003# ランチコントロール 無効にするタイプ
004# よくわからない人は使わない方がいいです
005#################################################
006###管理者インストールしているか?チェック
007USER_WHOAMI=$(/usr/bin/whoami)
008/bin/echo "実行ユーザー(whoami): $USER_WHOAMI"
009if [ "$USER_WHOAMI" != "root" ]; then
010  /bin/echo "このスクリプトを実行するには管理者権限が必要です。"
011  /bin/echo "sudo で実行してください"
012  ### path to me
013  SCRIPT_PATH="${BASH_SOURCE[0]}"
014  /bin/echo "/usr/bin/sudo \"$SCRIPT_PATH\""
015  /bin/echo "↑を実行してください"
016  exit 1
017else
018  ###実行しているユーザー名
019  CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
020  /bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
021  ###実行しているユーザー名
022  HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
023  /bin/echo "実行ユーザー(HOME): $HOME_USER"
024  ###logname
025  LOGIN_NAME=$(/usr/bin/logname)
026  /bin/echo "ログイン名(logname): $LOGIN_NAME"
027  ###UID
028  USER_NAME=$(/usr/bin/id -un)
029  /bin/echo "ユーザー名(id): $USER_NAME"
030  ###STAT
031  STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
032  /bin/echo "STAT_USR(console): $STAT_USR"
033fi
034#################################
035###プロセス終了
036STR_APP_NAME="Dropbox.app"
037###
038STR_PLIST_PATH="/Applications/$STR_APP_NAME/Contents/Info.plist"
039STR_BUNDLE_ID=$(/usr/bin/defaults read "$STR_PLIST_PATH" CFBundleIdentifier)
040/bin/echo "STR_BUNDLE_ID" "$STR_BUNDLE_ID"
041##念の為 KILLもする
042/usr/bin/killall "Dropbox" 2>/dev/null
043/usr/bin/killall "Dropbox Helper" 2>/dev/null
044/usr/bin/killall "Dropbox Helper (Renderer)" 2>/dev/null
045/usr/bin/killall "Dropbox Helper (Plugin)" 2>/dev/null
046/usr/bin/killall "Dropbox Helper (GPU)" 2>/dev/null
047/usr/bin/killall "DropboxActivityProvider" 2>/dev/null
048/usr/bin/killall "DropboxFileProviderCH" 2>/dev/null
049/usr/bin/killall "DropboxFileProvider" 2>/dev/null
050/usr/bin/killall "DropboxTransferExtension" 2>/dev/null
051/bin/echo "アプリケーション終了"
052/bin/sleep 2
053
054#################################
055function DO_MOVE_TO_TRASH() {
056  if [ -e "$1" ]; then
057    TRASH_DIR=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/DropBoxXXXXXX")
058    /usr/bin/chflags nouimmutable "$1"
059    /usr/bin/chflags nouchg "$1"
060    /usr/bin/chflags nouchange "$1"
061    /bin/chmod -N "$1"
062    /bin/chmod 777 "$TRASH_DIR"
063    /bin/mv "$1" "$TRASH_DIR"
064  fi
065}
066#####古いファイルをゴミ箱に  LOCAL
067DO_MOVE_TO_TRASH "/Library/DropboxHelperTools"
068DO_MOVE_TO_TRASH "/Applications/Dropbox.app"
069#####古いファイルをゴミ箱に  USER
070DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Dropbox"
071DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/HTTPStorages/com.dropbox.DropboxMacUpdate"
072DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/HTTPStorages/com.getdropbox.dropbox"
073DO_MOVE_TO_TRASH "/Users/${STAT_USR}/.dropbox/logs"
074DO_MOVE_TO_TRASH "/Users/${STAT_USR}/.dropbox/Crashpad"
075DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Scripts/com.dropbox.client.crashpad"
076DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Support/Dropbox/Code Cache"
077DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Support/Dropbox/GPUCache"
078DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Support/Dropbox/DropboxMacUpdate"
079DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Support/Dropbox/Dropbox/Crashpad"
080DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/Crashpad"
081DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/events"
082DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/Library/Caches"
083DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/Library/Application Scripts"
084DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/logs"
085DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/LaunchAgents/com.dropbox.DropboxMacUpdate.agent.plist"
086
087#################################
088## RSSから最新のバージョンを取得する
089STR_RSS_URL="https://www.dropboxforum.com/mxpez29397/rss/board?board.id=101003016"
090STR_USERAGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
091STR_USERAGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"
092STR_USERAGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
093STR_USERAGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15"
094
095XML_RSS_DATA=$(/usr/bin/curl -L -A "$STR_USERAGENT" -s "$STR_RSS_URL" | xmllint --format -)
096STR_TITLE=$(echo "$XML_RSS_DATA" | xmllint --xpath "//item/title/text()" -)
097IFS=$'\n' read -r -d '' -a LIST_TITLE <<<"$STR_TITLE"
098
099for ITEM_TITLE in "${LIST_TITLE[@]}"; do
100  if [[ $ITEM_TITLE == *"Stable"* ]]; then
101    /bin/echo "$ITEM_TITLE"
102    read -ra ARRAY_TITLE <<<"$ITEM_TITLE"
103    STR_VERSION=${ARRAY_TITLE[2]}
104    /bin/echo "$STR_VERSION"
105    break
106  fi
107done
108#################################
109##URLを生成する
110STR_BASE_URL="https://edge.dropboxstatic.com/dbx-releng/client/"
111###CPUタイプでの分岐
112ARCHITEC=$(/usr/bin/arch)
113if [ "$ARCHITEC" == "arm64" ]; then
114  STR_DMG_FILE_NAME="Dropbox%20$STR_VERSION.arm64.dmg"
115  DL_FILE_NAME="Dropbox $STR_VERSION.arm64.dmg"
116  STR_URL="$STR_BASE_URL$STR_DMG_FILE_NAME"
117else
118  STR_DMG_FILE_NAME="Dropbox%20$STR_VERSION.dmg"
119  DL_FILE_NAME="Dropbox $STR_VERSION.dmg"
120  STR_URL="$STR_BASE_URL$STR_DMG_FILE_NAME"
121fi
122/bin/echo "$STR_URL"
123#################################
124##ダウンロード
125STR_MKTEMP_DIR_PATH=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d)
126STR_TEMP_DIR_T=$(/usr/bin/dirname "$STR_MKTEMP_DIR_PATH")
127LOCAL_TMP_DIR=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d "${STR_TEMP_DIR_T}/dropbox.XXXXXXXXX")
128/bin/echo "TMPDIR:" "$LOCAL_TMP_DIR"
129
130if [ "$ARCHITEC" == "arm64" ]; then
131  /bin/echo "Running on $ARCHITEC"
132  ###ダウンロード
133  if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
134    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
135    if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
136      /bin/echo "ファイルのダウンロードに失敗しました"
137      exit 1
138    fi
139  fi
140else
141  /bin/echo "Running on $ARCHITEC"
142  ###ダウンロード
143  if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
144    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
145    if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
146      /bin/echo "ファイルのダウンロードに失敗しました"
147      exit 1
148    fi
149  fi
150fi
151
152############################################################
153#########
154/bin/echo "インストール開始:DMG in ditto:" "$CURRENT_USER"
155#マウントポイント
156STR_MOUNTPOINT_PATH="$LOCAL_TMP_DIR/MountPoint/Dropbox"
157###マウントポイント作成
158/bin/mkdir -p "$STR_MOUNTPOINT_PATH"
159/bin/chmod 777 "$STR_MOUNTPOINT_PATH"
160
161/usr/bin/hdiutil attach "$LOCAL_TMP_DIR/$DL_FILE_NAME" -noverify -nobrowse -noautoopen -mountpoint "$STR_MOUNTPOINT_PATH"
162
163###########この方法だとサイレントにならない
164#/usr/bin/sudo "$STR_MOUNTPOINT_PATH/Dropbox Offline Installer/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch
165/usr/bin/ditto "$STR_MOUNTPOINT_PATH/Dropbox.app" "/Applications/Dropbox.app"
166
167/usr/bin/hdiutil detach "$STR_MOUNTPOINT_PATH" -force
168
169###ここは好みの問題か?
170#/usr/bin/sudo chown -Rf root "/Applications/Dropbox.app"
171#/usr/bin/sudo  chown -Rf "$SUDO_USER" "/Applications/Dropbox.app"
172
173###実行はユーザーにまかせるのもあり?
174##/usr/bin/sudo "/Applications/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch
175##/usr/bin/sudo -u "$SUDO_USER" "/Applications/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch
176
177#################################################
178###テンポラリーのクリーニング
179STR_MKTEMP_DIR_PATH=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d)
180STR_TEMP_DIR_T=$(/usr/bin/dirname "$STR_MKTEMP_DIR_PATH")
181STR_CHK_DIR_PATH="$STR_TEMP_DIR_T"
182STR_CHK_STRING="dropbox"
183LIST_FILE_NAME=$(/bin/ls "$STR_CHK_DIR_PATH" | grep "$STR_CHK_STRING")
184if [ -n "$LIST_FILE_NAME" ]; then
185  /bin/echo "$LIST_FILE_NAME" | while read -r ITEM_FILE_NAME; do
186    /bin/echo "$STR_CHK_DIR_PATH/$ITEM_FILE_NAME"
187    DO_MOVE_TO_TRASH "$STR_CHK_DIR_PATH/$ITEM_FILE_NAME"
188  done
189fi
190###
191STR_MKTEMP_DIR_PATH=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d)
192STR_TEMP_DIR_T=$(/usr/bin/dirname "$STR_MKTEMP_DIR_PATH")
193STR_TEMP_DIR=$(/usr/bin/dirname "$STR_TEMP_DIR_T")
194STR_TEMP_DIR_C="$STR_TEMP_DIR/C"
195STR_CHK_DIR_PATH="$STR_TEMP_DIR_C"
196STR_CHK_STRING="dropbox"
197LIST_FILE_NAME=$(/bin/ls "$STR_CHK_DIR_PATH" | grep "$STR_CHK_STRING")
198if [ -n "$LIST_FILE_NAME" ]; then
199  /bin/echo "$LIST_FILE_NAME" | while read -r ITEM_FILE_NAME; do
200    /bin/echo "$STR_CHK_DIR_PATH/$ITEM_FILE_NAME"
201    DO_MOVE_TO_TRASH "$STR_CHK_DIR_PATH/$ITEM_FILE_NAME"
202  done
203fi
204
205STR_AGENT_PLIST_PATH="/Users/${STAT_USR}/Library/LaunchAgents/com.dropbox.DropboxMacUpdate.agent.plist"
206if [ -e "$STR_AGENT_PLIST_PATH" ]; then
207  /bin/launchctl stop -wF com.dropbox.DropboxMacUpdate.agent
208  /bin/launchctl unload -wF "$STR_AGENT_PLIST_PATH"
209fi
210
211################################################
212### ランチコントロール停止 LaunchAgents
213/usr/bin/sudo -u "$STAT_USR" /bin/mkdir -p "/Users/${STAT_USR}/Library/LaunchAgents Disabled"
214/usr/bin/sudo -u "$STAT_USR" /bin/chmod 700 "/Users/${STAT_USR}/Library/LaunchAgents Disabled"
215
216function DO_MOVE_TO_DISABLED_A() {
217  if [ -e "$1" ]; then
218    MOVE_DIR="/Users/${STAT_USR}/Library/LaunchAgents Disabled"
219    /usr/bin/chflags nouimmutable "$1"
220    /usr/bin/chflags nouchg "$1"
221    /usr/bin/chflags nouchange "$1"
222    /bin/chmod -N "$1"
223    if ! /bin/mv "$1" "$MOVE_DIR"; then
224      /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "$1"
225      /usr/bin/sudo -u "$STAT_USR" /bin/chmod 644 "$1"
226      /usr/bin/sudo -u "$STAT_USR" /usr/bin/chflags uchg "$1"
227      /bin/echo "$1" "移動しました"
228    else
229      /bin/rm "$1"
230      /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "$1"
231      /usr/bin/sudo -u "$STAT_USR" /bin/chmod 644 "$1"
232      /usr/bin/sudo -u "$STAT_USR" /usr/bin/chflags uchg "$1"
233      /bin/echo "$1" "移動に失敗しました"
234    fi
235    else
236      /bin/rm "$1"
237      /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "$1"
238      /usr/bin/sudo -u "$STAT_USR" /bin/chmod 644 "$1"
239      /usr/bin/sudo -u "$STAT_USR" /usr/bin/chflags uchg "$1"
240      /bin/echo "$1" "最初からなかった"
241  fi
242}
243
244
245DO_MOVE_TO_DISABLED_A "/Users/${STAT_USR}/Library/LaunchAgents/com.dropbox.DropboxMacUpdate.agent.plist"
246
247exit 0
AppleScriptで生成しました

|

DropBOXの最新版をインストール(RSSの仕様変更対応)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#https://www.dropboxforum.com/t5/Dropbox-desktop-client-builds/bd-p/101003016
004#com.cocolog-nifty.quicktimer.icefloe
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use scripting additions
010
011property refMe : a reference to current application
012##########################
013#URL
014set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
015ocidURLComponents's setScheme:("https")
016ocidURLComponents's setHost:("www.dropboxforum.com")
017ocidURLComponents's setPath:("/mxpez29397/rss/board")
018set ocidQueryItems to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
019set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("board.id") value:("101003016")
020ocidQueryItems's addObject:(ocidQueryItem)
021ocidURLComponents's setQueryItems:(ocidQueryItems)
022set ocidURL to ocidURLComponents's |URL|()
023set strURL to ocidURL's absoluteString() as text
024
025##############
026#ユーザーエージェント付きでCURLでダウンロード
027set strUserAgent to ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
028set strCommandText to ("/bin/zsh -c '/usr/bin/curl  -L -A \"" & strUserAgent & "\" \"" & strURL & "\"'") as text
029log strCommandText
030try
031  set strResponse to (do shell script strCommandText) as text
032on error
033  return "コマンド実行でエラーしました"
034end try
035#戻り値=XMLのRSS
036set ocidResponseString to refMe's NSString's stringWithString:(strResponse)
037
038###XML読み込み
039set ocidOption to (refMe's NSXMLDocumentTidyXML as integer) + (refMe's NSXMLNodePreserveNamespaceOrder as integer) + (refMe's NSXMLNodePreserveAttributeOrder as integer) + (refMe's NSXMLNodePreserveEntities as integer) + (refMe's NSXMLNodePreservePrefixes as integer) + (refMe's NSXMLNodePreserveCDATA as integer) + (refMe's NSXMLNodePreserveEmptyElements as integer) + (refMe's NSXMLNodePreserveQuotes as integer) + (refMe's NSXMLNodePreserveWhitespace as integer) + (refMe's NSXMLNodePreserveDTD as integer) + (refMe's NSXMLNodePreserveCharacterReferences as integer)
040set listResponse to refMe's NSXMLDocument's alloc()'s initWithXMLString:(ocidResponseString) options:(ocidOption) |error| :(reference)
041
042if (item 2 of listResponse) = (missing value) then
043  log "正常処理"
044  set ocidReadXMLDoc to (item 1 of listResponse)
045else if (item 2 of listResponse) ≠ (missing value) then
046  set strErrorNO to (item 2 of listResponse)'s code() as text
047  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
048  refMe's NSLog("■:" & strErrorNO & strErrorMes)
049  return "エラーしました" & strErrorNO & strErrorMes
050end if
051
052###ROOT
053set ocidRootElement to ocidReadXMLDoc's rootElement()
054set numChild to (count of ocidRootElement's children) as integer
055###第一階層 channel
056set ocidChannel to (ocidRootElement's childAtIndex:0)
057set numChild to (count of ocidChannel's children) as integer
058###子要素の数だけ繰り返し
059repeat with numCntChild from 0 to (numChild - 1)
060  set strChldName to (ocidChannel's childAtIndex:numCntChild)'s |name| as text
061  ####要素名がitemなら
062  if strChldName is "item" then
063    ###itemのtitleをテキストで取得して
064    set ocidItemObject to ((ocidChannel's childAtIndex:numCntChild)'s childAtIndex:0)
065    set ocidTitle to ocidItemObject's stringValue()
066    ###最初のStable項目=最新
067    if (ocidTitle as text) contains "Stable" then
068      set ocidTitleArray to (ocidTitle's componentsSeparatedByString:(" "))
069      ###バージョンテキストを取得したらリピート終了
070      set strVersion to (ocidTitleArray's lastObject()) as text
071      exit repeat
072    end if
073  end if
074end repeat
075###取得したバージョン番号
076
077##########################
078## ダウンロードするURLを生成
079##########################
080##CPUタイプのよる処理の分岐
081set objSysInfo to system info
082set theCpuType to (CPU type of objSysInfo) as text
083
084if theCpuType contains "Intel" then
085  # set strURL to "https://www.dropbox.com/downloading?plat=mac&type=full"
086  set strFileName to "Dropbox " & strVersion & ".dmg" as text
087  # set strURL to ("https://edge.dropboxstatic.com/dbx-releng/client/" & strFileName & "") as text
088else
089  #set strURL to "https://www.dropbox.com/downloading?plat=mac&type=full&arch=arm64"
090  set strFileName to "Dropbox " & strVersion & ".arm64.dmg" as text
091  #set strURL to ("https://edge.dropboxstatic.com/dbx-releng/client/" & strFileName & "") as text
092end if
093####ダウンロードするDMGファイル名とURLが確定
094set ocidURL to refMe's NSURL's alloc()'s initWithString:("https://edge.dropboxstatic.com/dbx-releng/client/")
095##ファイル名
096set ocidURL to ocidURL's URLByAppendingPathComponent:(strFileName)
097set strURL to ocidURL's absoluteString() as text
098log strURL as text
099
100##########################
101## ダウンロードするファイル
102##########################
103###テンポラリ
104set appFileManager to refMe's NSFileManager's defaultManager()
105set ocidTemporaryDirPathURL to appFileManager's temporaryDirectory
106set ocidTemporaryItemsPathURL to ocidTemporaryDirPathURL's URLByAppendingPathComponent:("TemporaryItems")
107###同一パスにならないようにUUIDを足す
108set ocidUUID to refMe's NSUUID's alloc()'s init()
109set coidUUID to ocidUUID's UUIDString()
110set ocidLocalUUIDPathURL to ocidTemporaryItemsPathURL's URLByAppendingPathComponent:(coidUUID)
111###DMG保存ディレクトリ
112set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
113ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
114appFileManager's createDirectoryAtURL:(ocidLocalUUIDPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference)
115###ファイル名を足してDMGの保存パス
116set ocidLocalPathURL to ocidLocalUUIDPathURL's URLByAppendingPathComponent:(strFileName)
117set strLocalPath to (ocidLocalPathURL's |path|) as text
118##########################
119## ダウンロード
120##########################
121try
122  set strCommandText to ("/usr/bin/curl -L -o \"" & strLocalPath & "\"   \"" & strURL & "\" --connect-timeout 10") as text
123  do shell script strCommandText
124on error
125  set strCommandText to ("/usr/bin/curl -L -o \"" & strLocalPath & "\"   \"" & strURL & "\" --http1.1 --connect-timeout 10") as text
126  do shell script strCommandText
127end try
128
129##########################
130## 関連プロセス終了
131##########################
132set listBundleID to {"com.dropbox.Electron.helper", "com.getdropbox.dropbox"}
133
134repeat with itemUTI in listBundleID
135  ###NSRunningApplication
136  set ocidRunningApplication to refMe's NSRunningApplication
137  ###起動中のすべてのリスト
138  set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(itemUTI))
139  ###複数起動時も順番に終了
140  repeat with itemAppArray in ocidAppArray
141    itemAppArray's terminate()
142  end repeat
143end repeat
144(*
145##########################
146## 関連プロセス終了
147##########################
148try
149  tell application id "com.getdropbox.dropbox" to quit
150end try
151try
152  do shell script "killall \"Dropbox Helper\""
153  do shell script "killall \"Dropbox Helper (Renderer)\""
154  do shell script "killall \"Dropbox Helper (Plugin)\""
155  do shell script "killall \"Dropbox Helper (GPU)\""
156  do shell script "killall \"Dropbox\""
157  do shell script "killall \"DropboxActivityProvider\""
158  do shell script "killall \"DropboxFileProviderCH\""
159  do shell script "killall \"DropboxFileProvider\""
160  do shell script "killall \"DropboxTransferExtension\""
161end try
162*)
163##########################
164## 本処理
165##########################
166##appNSWorkspaceでドライブを表示しないマウント方法がわからない
167set theComandText to ("/usr/bin/hdiutil attach  \"" & strLocalPath & "\" -noverify -nobrowse -noautoopen\n") as text
168do shell script theComandText
169####この方法だとサイレントにならない
170###set theComandText to ("\"/Volumes/Dropbox Offline Installer/Dropbox.app/Contents/MacOS/Dropbox\" - nolaunch") as text
171###do shell script theComandText with administrator privileges
172
173
174##############################
175## 実行するコマンド
176#set strCommandText to ("/usr/bin/sudo /usr/bin/ditto \"/Volumes/Dropbox Offline Installer/Dropbox.app\" \"/Applications/Dropbox.app\"") as text
177set strCommandText to ("/usr/bin/ditto \"/Volumes/Dropbox Offline Installer/Dropbox.app\" \"/Applications/Dropbox.app\"") as text
178##############################
179## 実行中チェック
180tell application "Terminal"
181  set numCntWindow to (count of every window) as integer
182end tell
183delay 0.5
184if numCntWindow = 0 then
185  log "Windowないので新規で作る"
186  tell application "Terminal"
187    set objNewWindow to (do script "\n")
188  end tell
189else
190  log "Windowがある場合は、何か実行中か?をチェック"
191  tell application "Terminal"
192    tell front window
193      tell front tab
194        set boolTabStatus to busy as boolean
195        set listProcess to processes as list
196      end tell
197    end tell
198    set objNewWindow to selected tab of front window
199  end tell
200  ###前面のタブがbusy=実行中なら新規Window作る
201  if boolTabStatus = true then
202    tell application "Terminal"
203      set objNewWindow to (do script "\n")
204    end tell
205  else if listProcess = {} then
206    tell application "Terminal"
207      set objNewWindow to (do script "\n")
208    end tell
209  end if
210end if
211delay 0.5
212##############################
213## コマンド実行
214tell application "Terminal"
215  activate
216  do script strCommandText in objNewWindow
217end tell
218delay 1
219log "コマンド実行中"
220##############################
221## コマンド終了チェック
222(*
223objNewWindowにWindowIDとTabIDが入っているので
224objNewWindowに対してbusyを確認する事で
225処理が終わっているか?がわかる
226*)
227## 無限ループ防止で100回
228repeat 100 times
229  tell application "Terminal"
230    set boolTabStatus to busy of objNewWindow
231  end tell
232  if boolTabStatus is false then
233    log "コマンド処理終了しました"
234    tell application "Terminal"
235      tell front window
236        tell front tab
237          set listProcess to processes as list
238        end tell
239      end tell
240    end tell
241    set numCntProcess to (count of listProcess) as integer
242    if numCntProcess ≤ 2 then
243      exit repeat
244    else
245      delay 1
246    end if
247    --->このリピートを抜けて次の処理へ
248  else if boolTabStatus is true then
249    log "コマンド処理中"
250    delay 1
251    --->busyなのであと1秒まつ
252  end if
253end repeat
254tell application "Terminal" to activate
255
256
257##############################
258## exit打って終了
259tell application "Terminal"
260  do script "exit" in objNewWindow
261end tell
262##############################
263## exitの処理待ちしてClose
264repeat 20 times
265  tell application "Terminal"
266    tell front window
267      tell front tab
268        set listProcess to processes as list
269      end tell
270    end tell
271  end tell
272  if listProcess = {} then
273    tell application "Terminal"
274      tell front window
275        # tell front tab
276        close saving no
277        # end tell
278      end tell
279    end tell
280    exit repeat
281  else
282    delay 1
283  end if
284end repeat
285
286##########################
287## アンマウント
288##########################
289set strDiskPath to "/Volumes/Dropbox Offline Installer"
290set ocidDiskPathStr to refMe's NSString's stringWithString:(strDiskPath)
291set ocidDiskPath to ocidDiskPathStr's stringByExpandingTildeInPath()
292set ocidDiskPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDiskPath) isDirectory:false)
293set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
294(appNSWorkspace's unmountAndEjectDeviceAtURL:(ocidDiskPathURL) |error| :(reference))
295try
296  set theComandText to ("/usr/bin/hdiutil detach \"" & strDiskPath & "\" -force") as text
297  do shell script theComandText
298end try
299
AppleScriptで生成しました

|

[Bash]DropBox ドロップボックスインストール(ditto版)


サンプルコード

サンプルソース(参考)
行番号ソース
001#!/bin/bash
002#com.cocolog-nifty.quicktimer.icefloe
003# ランチコントロール 無効にするタイプ
004# よくわからない人は使わない方がいいです
005#################################################
006###管理者インストールしているか?チェック
007USER_WHOAMI=$(/usr/bin/whoami)
008/bin/echo "実行ユーザー(whoami): $USER_WHOAMI"
009if [ "$USER_WHOAMI" != "root" ]; then
010  /bin/echo "このスクリプトを実行するには管理者権限が必要です。"
011  /bin/echo "sudo で実行してください"
012  ### path to me
013  SCRIPT_PATH="${BASH_SOURCE[0]}"
014  /bin/echo "/usr/bin/sudo \"$SCRIPT_PATH\""
015  /bin/echo "↑を実行してください"
016  exit 1
017else
018  ###実行しているユーザー名
019  CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
020  /bin/echo "コンソールユーザー(scutil): $CONSOLE_USER"
021  ###実行しているユーザー名
022  HOME_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
023  /bin/echo "実行ユーザー(HOME): $HOME_USER"
024  ###logname
025  LOGIN_NAME=$(/usr/bin/logname)
026  /bin/echo "ログイン名(logname): $LOGIN_NAME"
027  ###UID
028  USER_NAME=$(/usr/bin/id -un)
029  /bin/echo "ユーザー名(id): $USER_NAME"
030  ###STAT
031  STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
032  /bin/echo "STAT_USR(console): $STAT_USR"
033fi
034#################################
035###プロセス終了
036STR_APP_NAME="Dropbox.app"
037###
038STR_PLIST_PATH="/Applications/$STR_APP_NAME/Contents/Info.plist"
039STR_BUNDLE_ID=$(/usr/bin/defaults read "$STR_PLIST_PATH" CFBundleIdentifier)
040/bin/echo "STR_BUNDLE_ID" "$STR_BUNDLE_ID"
041##念の為 KILLもする
042/usr/bin/killall "Dropbox" 2>/dev/null
043/usr/bin/killall "Dropbox Helper" 2>/dev/null
044/usr/bin/killall "Dropbox Helper (Renderer)" 2>/dev/null
045/usr/bin/killall "Dropbox Helper (Plugin)" 2>/dev/null
046/usr/bin/killall "Dropbox Helper (GPU)" 2>/dev/null
047/usr/bin/killall "DropboxActivityProvider" 2>/dev/null
048/usr/bin/killall "DropboxFileProviderCH" 2>/dev/null
049/usr/bin/killall "DropboxFileProvider" 2>/dev/null
050/usr/bin/killall "DropboxTransferExtension" 2>/dev/null
051/bin/echo "アプリケーション終了"
052/bin/sleep 2
053
054#################################
055function DO_MOVE_TO_TRASH() {
056  if [ -e "$1" ]; then
057    TRASH_DIR=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d "/Users/$STAT_USR/.Trash/DropBoxXXXXXX")
058    /usr/bin/chflags nouimmutable "$1"
059    /usr/bin/chflags nouchg "$1"
060    /usr/bin/chflags nouchange "$1"
061    /bin/chmod -N "$1"
062    /bin/chmod 777 "$TRASH_DIR"
063    /bin/mv "$1" "$TRASH_DIR"
064  fi
065}
066#####古いファイルをゴミ箱に  LOCAL
067DO_MOVE_TO_TRASH "/Library/DropboxHelperTools"
068DO_MOVE_TO_TRASH "/Applications/Dropbox.app"
069#####古いファイルをゴミ箱に  USER
070DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Dropbox"
071DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/HTTPStorages/com.dropbox.DropboxMacUpdate"
072DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/HTTPStorages/com.getdropbox.dropbox"
073DO_MOVE_TO_TRASH "/Users/${STAT_USR}/.dropbox/logs"
074DO_MOVE_TO_TRASH "/Users/${STAT_USR}/.dropbox/Crashpad"
075DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Scripts/com.dropbox.client.crashpad"
076DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Support/Dropbox/Code Cache"
077DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Support/Dropbox/GPUCache"
078DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Support/Dropbox/DropboxMacUpdate"
079DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Application Support/Dropbox/Dropbox/Crashpad"
080DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/Crashpad"
081DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/events"
082DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/Library/Caches"
083DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/Library/Application Scripts"
084DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/Group Containers/G7HH3F8CAK.com.getdropbox.dropbox.sync/logs"
085DO_MOVE_TO_TRASH "/Users/${STAT_USR}/Library/LaunchAgents/com.dropbox.DropboxMacUpdate.agent.plist"
086
087#################################
088## RSSから最新のバージョンを取得する
089STR_RSS_URL="https://www.dropboxforum.com/mxpez29397/rss/board?board.id=101003016"
090XML_RSS_DATA=$(/usr/bin/curl -s "$STR_RSS_URL" | xmllint --format -)
091STR_TITLE=$(echo "$XML_RSS_DATA" | xmllint --xpath "//item/title/text()" -)
092IFS=$'\n' read -r -d '' -a LIST_TITLE <<<"$STR_TITLE"
093
094for ITEM_TITLE in "${LIST_TITLE[@]}"; do
095  if [[ $ITEM_TITLE == *"Stable"* ]]; then
096    /bin/echo "$ITEM_TITLE"
097    read -ra ARRAY_TITLE <<<"$ITEM_TITLE"
098    STR_VERSION=${ARRAY_TITLE[2]}
099    /bin/echo "$STR_VERSION"
100    break
101  fi
102done
103#################################
104##URLを生成する
105STR_BASE_URL="https://edge.dropboxstatic.com/dbx-releng/client/"
106###CPUタイプでの分岐
107ARCHITEC=$(/usr/bin/arch)
108if [ "$ARCHITEC" == "arm64" ]; then
109  STR_DMG_FILE_NAME="Dropbox%20$STR_VERSION.arm64.dmg"
110  DL_FILE_NAME="Dropbox $STR_VERSION.arm64.dmg"
111  STR_URL="$STR_BASE_URL$STR_DMG_FILE_NAME"
112else
113  STR_DMG_FILE_NAME="Dropbox%20$STR_VERSION.dmg"
114  DL_FILE_NAME="Dropbox $STR_VERSION.dmg"
115  STR_URL="$STR_BASE_URL$STR_DMG_FILE_NAME"
116fi
117/bin/echo "$STR_URL"
118#################################
119##ダウンロード
120STR_MKTEMP_DIR_PATH=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d)
121STR_TEMP_DIR_T=$(/usr/bin/dirname "$STR_MKTEMP_DIR_PATH")
122LOCAL_TMP_DIR=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d "${STR_TEMP_DIR_T}/dropbox.XXXXXXXXX")
123/bin/echo "TMPDIR:" "$LOCAL_TMP_DIR"
124
125if [ "$ARCHITEC" == "arm64" ]; then
126  /bin/echo "Running on $ARCHITEC"
127  ###ダウンロード
128  if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
129    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
130    if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
131      /bin/echo "ファイルのダウンロードに失敗しました"
132      exit 1
133    fi
134  fi
135else
136  /bin/echo "Running on $ARCHITEC"
137  ###ダウンロード
138  if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
139    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
140    if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
141      /bin/echo "ファイルのダウンロードに失敗しました"
142      exit 1
143    fi
144  fi
145fi
146
147############################################################
148#########
149/bin/echo "インストール開始:DMG in ditto:" "$CURRENT_USER"
150#マウントポイント
151STR_MOUNTPOINT_PATH="$LOCAL_TMP_DIR/MountPoint/Dropbox"
152###マウントポイント作成
153/bin/mkdir -p "$STR_MOUNTPOINT_PATH"
154/bin/chmod 777 "$STR_MOUNTPOINT_PATH"
155
156/usr/bin/hdiutil attach "$LOCAL_TMP_DIR/$DL_FILE_NAME" -noverify -nobrowse -noautoopen -mountpoint "$STR_MOUNTPOINT_PATH"
157
158###########この方法だとサイレントにならない
159#/usr/bin/sudo "$STR_MOUNTPOINT_PATH/Dropbox Offline Installer/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch
160/usr/bin/ditto "$STR_MOUNTPOINT_PATH/Dropbox.app" "/Applications/Dropbox.app"
161
162/usr/bin/hdiutil detach "$STR_MOUNTPOINT_PATH" -force
163
164###ここは好みの問題か?
165#/usr/bin/sudo chown -Rf root "/Applications/Dropbox.app"
166#/usr/bin/sudo  chown -Rf "$SUDO_USER" "/Applications/Dropbox.app"
167
168###実行はユーザーにまかせるのもあり?
169##/usr/bin/sudo "/Applications/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch
170##/usr/bin/sudo -u "$SUDO_USER" "/Applications/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch
171
172#################################################
173###テンポラリーのクリーニング
174STR_MKTEMP_DIR_PATH=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d)
175STR_TEMP_DIR_T=$(/usr/bin/dirname "$STR_MKTEMP_DIR_PATH")
176STR_CHK_DIR_PATH="$STR_TEMP_DIR_T"
177STR_CHK_STRING="dropbox"
178LIST_FILE_NAME=$(/bin/ls "$STR_CHK_DIR_PATH" | grep "$STR_CHK_STRING")
179if [ -n "$LIST_FILE_NAME" ]; then
180  /bin/echo "$LIST_FILE_NAME" | while read -r ITEM_FILE_NAME; do
181    /bin/echo "$STR_CHK_DIR_PATH/$ITEM_FILE_NAME"
182    DO_MOVE_TO_TRASH "$STR_CHK_DIR_PATH/$ITEM_FILE_NAME"
183  done
184fi
185###
186STR_MKTEMP_DIR_PATH=$(/usr/bin/sudo -u "$STAT_USR" /usr/bin/mktemp -d)
187STR_TEMP_DIR_T=$(/usr/bin/dirname "$STR_MKTEMP_DIR_PATH")
188STR_TEMP_DIR=$(/usr/bin/dirname "$STR_TEMP_DIR_T")
189STR_TEMP_DIR_C="$STR_TEMP_DIR/C"
190STR_CHK_DIR_PATH="$STR_TEMP_DIR_C"
191STR_CHK_STRING="dropbox"
192LIST_FILE_NAME=$(/bin/ls "$STR_CHK_DIR_PATH" | grep "$STR_CHK_STRING")
193if [ -n "$LIST_FILE_NAME" ]; then
194  /bin/echo "$LIST_FILE_NAME" | while read -r ITEM_FILE_NAME; do
195    /bin/echo "$STR_CHK_DIR_PATH/$ITEM_FILE_NAME"
196    DO_MOVE_TO_TRASH "$STR_CHK_DIR_PATH/$ITEM_FILE_NAME"
197  done
198fi
199
200STR_AGENT_PLIST_PATH="/Users/${STAT_USR}/Library/LaunchAgents/com.dropbox.DropboxMacUpdate.agent.plist"
201if [ -e "$STR_AGENT_PLIST_PATH" ]; then
202  /bin/launchctl stop -wF com.dropbox.DropboxMacUpdate.agent
203  /bin/launchctl unload -wF "$STR_AGENT_PLIST_PATH"
204fi
205
206################################################
207### ランチコントロール停止 LaunchAgents
208/usr/bin/sudo -u "$STAT_USR" /bin/mkdir -p "/Users/${STAT_USR}/Library/LaunchAgents Disabled"
209/usr/bin/sudo -u "$STAT_USR" /bin/chmod 700 "/Users/${STAT_USR}/Library/LaunchAgents Disabled"
210
211function DO_MOVE_TO_DISABLED_A() {
212  if [ -e "$1" ]; then
213    MOVE_DIR="/Users/${STAT_USR}/Library/LaunchAgents Disabled"
214    /usr/bin/chflags nouimmutable "$1"
215    /usr/bin/chflags nouchg "$1"
216    /usr/bin/chflags nouchange "$1"
217    /bin/chmod -N "$1"
218    if ! /bin/mv "$1" "$MOVE_DIR"; then
219      /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "$1"
220      /usr/bin/sudo -u "$STAT_USR" /bin/chmod 644 "$1"
221      /usr/bin/sudo -u "$STAT_USR" /usr/bin/chflags uchg "$1"
222      /bin/echo "$1" "移動しました"
223    else
224      /bin/rm "$1"
225      /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "$1"
226      /usr/bin/sudo -u "$STAT_USR" /bin/chmod 644 "$1"
227      /usr/bin/sudo -u "$STAT_USR" /usr/bin/chflags uchg "$1"
228      /bin/echo "$1" "移動に失敗しました"
229    fi
230    else
231      /bin/rm "$1"
232      /usr/bin/sudo -u "$STAT_USR" /usr/bin/touch "$1"
233      /usr/bin/sudo -u "$STAT_USR" /bin/chmod 644 "$1"
234      /usr/bin/sudo -u "$STAT_USR" /usr/bin/chflags uchg "$1"
235      /bin/echo "$1" "最初からなかった"
236  fi
237}
238
239
240DO_MOVE_TO_DISABLED_A "/Users/${STAT_USR}/Library/LaunchAgents/com.dropbox.DropboxMacUpdate.agent.plist"
241
242exit 0
AppleScriptで生成しました

|

[DropBox]最新版のURLを取得する


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

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

set strBundleID to ("com.getdropbox.dropbox") as text

set strURL to ("https://www.dropboxforum.com/mxpez29397/rss/board?board.id=101003016") as text
set coidBaseURLStr to refMe's NSString's stringWithString:(strURL)
set ocidBaseURL to refMe's NSURL's URLWithString:(coidBaseURLStr)

################################################
###### URLRequest部分
################################################
set ocidURLRequest to refMe's NSMutableURLRequest's alloc()'s init()
ocidURLRequest's setHTTPMethod:"GET"
ocidURLRequest's setURL:(ocidBaseURL)
ocidURLRequest's addValue:"application/xml" forHTTPHeaderField:"Content-Type"
###ポストするデータは空
ocidURLRequest's setHTTPBody:(missing value)

################################################
###### データ取得
################################################
set ocidServerResponse to refMe's NSURLConnection's sendSynchronousRequest:(ocidURLRequest) returningResponse:(missing value) |error|:(reference)
set ocidXMLData to (item 1 of ocidServerResponse)
###ROOTエレメント
set listXMLDoc to refMe's NSXMLDocument's alloc()'s initWithData:(ocidXMLData) options:(refMe's NSXMLDocumentTidyXML) |error|:(reference)
set ocidXMLDoc to item 1 of listXMLDoc
set ocidRootElement to ocidXMLDoc's rootElement()
##channelエレメント
set ocidChannel to ocidRootElement's elementsForName:("channel")
set ocidChannelElement to ocidChannel's firstObject()
set strMainTitle to (ocidChannelElement's elementsForName:("title"))'s stringValue as text
log strMainTitle
###itemエレメント
set ocidItemArray to (ocidChannelElement's elementsForName:("item"))
##
set strContantsHtml to ("") as text
repeat with itemArray in ocidItemArray
  set strItemTitle to (itemArray's elementsForName:("title"))'s stringValue as text
  if strItemTitle contains "Stable" then
    set strItemDescription to (itemArray's elementsForName:("description"))'s stringValue as text
    set strContantsHtml to (strContantsHtml & "<hr>" & strItemDescription) as text
    exit repeat
  end if
end repeat

###テキストにして
set ocidHTML to refMe's NSString's stringWithString:(strContantsHtml)
###ある程度の整形
set ocidHTML to (ocidHTML's stringByReplacingOccurrencesOfString:("\r") withString:(""))
set ocidHTML to (ocidHTML's stringByReplacingOccurrencesOfString:("\n") withString:(""))
set ocidHTML to (ocidHTML's stringByReplacingOccurrencesOfString:("\t") withString:(""))
##修正が必要な項目は修正
set ocidHTML to (ocidHTML's stringByReplacingOccurrencesOfString:("</A>") withString:("</a>\n"))
set ocidHTML to (ocidHTML's stringByReplacingOccurrencesOfString:("<A") withString:("\n<a"))

##改行毎のARRAYにして
set ocidHTMLArray to ocidHTML's componentsSeparatedByString:("\n")
##URL格納用のDICT
set ocidURLDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
##処理
repeat with itemArray in ocidHTMLArray
  #aタグのみ処理
  set ocidRange to (itemArray's rangeOfString:("<a"))
  if (ocidRange's location()) ≠ refNSNotFound then
    try
      #aタグの内容をエレメントに格納
      set listAElement to (refMe's NSXMLElement's alloc()'s initWithXMLString:(itemArray) |error|:(reference))
      set ocidAelement to (item 1 of listAElement)
      #URLを取得
      set ocidValue to (ocidAelement's attributeForName:("href"))'s stringValue
      #対象のパス名が含まれているか?
      set ocidRange to (ocidValue's rangeOfString:("downloading"))
      if (ocidRange's location()) ≠ refNSNotFound then
        set ocidKeyName to ocidAelement's stringValue()
        #相対パス記述の場合にベースURLを付与
        if (ocidValue as text) starts with "/" then
(ocidURLComponents's setPath:(ocidValue))
          set ocidValue to (ocidURLComponents's |URL|)'s absoluteString()
        end if
        #格納用のDICTに格納していく
(ocidURLDict's setValue:(ocidValue) forKey:(ocidKeyName))
      end if
    on error
log ("hrefアトリヴュートが無いか?エレメント構造にエラーがあります: " & itemArray) as text
    end try
  end if
  
end repeat
###ここまでの内容
log ocidURLDict as record
set ocidUrlAllKey to ocidURLDict's allKeys()

set ocidOutputText to refMe's NSMutableString's alloc()'s initWithCapacity:0
repeat with itemKey in ocidUrlAllKey
(ocidOutputText's appendString:(itemKey))
(ocidOutputText's appendString:("\n"))
  set ocidSetValue to (ocidURLDict's valueForKey:(itemKey))
(ocidOutputText's appendString:(ocidSetValue))
(ocidOutputText's appendString:("\n"))
end repeat

set ocidARMurl to (ocidURLDict's valueForKey:(" Offline Installer (Apple Silicon) "))

################################################
###### インストール済みのパージョン
################################################
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
##バンドルからアプリケーションのURLを取得
set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
if ocidAppBundle ≠ (missing value) then
  set ocidAppPathURL to ocidAppBundle's bundleURL()
else if ocidAppBundle = (missing value) then
  set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
end if
##予備(アプリケーションのURL)
if ocidAppPathURL = (missing value) then
  tell application "Finder"
    try
      set aliasAppApth to (application file id strBundleID) as alias
      set strAppPath to POSIX path of aliasAppApth as text
      set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
      set strAppPath to strAppPathStr's stringByStandardizingPath()
      set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
    on error
return "アプリケーションが見つかりませんでした"
    end try
  end tell
end if
set ocidFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:("Contents/Info.plist")
#####PLISTの内容を読み込んで
set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
set listReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:ocidFilePathURL |error|:(reference)
set ocidPlistDict to item 1 of listReadPlistData
set ocidCfbundleversionPlist to ocidPlistDict's valueForKey:"CFBundleVersion"


################################################
###### ダイアログ
################################################
set appFileManager to refMe's NSFileManager's defaultManager()


####ダイアログに指定アプリのアイコンを表示する
###アイコン名をPLISTから取得
set strIconFileName to (ocidPlistDict's valueForKey:("CFBundleIconFile")) as text
###ICONのURLにして
set strPath to ("Contents/Resources/" & strIconFileName) as text
set ocidIconFilePathURL to ocidAppPathURL's URLByAppendingPathComponent:(strPath) isDirectory:false
###拡張子の有無チェック
set strExtensionName to (ocidIconFilePathURL's pathExtension()) as text
if strExtensionName is "" then
  set ocidIconFilePathURL to ocidIconFilePathURL's URLByAppendingPathExtension:"icns"
end if
##-->これがアイコンパス
log ocidIconFilePathURL's absoluteString() as text
###ICONファイルが実際にあるか?チェック
set boolExists to appFileManager's fileExistsAtPath:(ocidIconFilePathURL's |path|)
###ICONがみつかない時用にデフォルトを用意する
if boolExists is false then
  set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
else
  set aliasIconPath to ocidIconFilePathURL's absoluteURL() as alias
  set strIconPath to ocidIconFilePathURL's |path|() as text
end if
set strCom to "最新バージョンのURLです\nインテルMacはOffline Installer (Intel)\nARMはOffline Installer (Apple Silicon)です"
set strTitle to "戻り値です"
set strMes to ocidOutputText as text
set recordResult to (display dialog strCom with title strTitle default answer strMes buttons {"クリップボードにコピー", "終了", "ダウンロード"} default button "ダウンロード" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer)

if button returned of recordResult is "ダウンロード" then
  tell application "Finder"
open location (ocidARMurl as text)
  end tell
end if
if button returned of recordResult is "クリップボードにコピー" then
  try
    set strText to text returned of recordResult as text
    ####ペーストボード宣言
    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
    set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
  on error
    tell application "Finder"
      set the clipboard to strTitle as text
    end tell
  end try
end if


|

[DropBox]最新版のURLをHTML表示する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
DROP BOXの最新版リンクをHTML表示します
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application


set strURL to ("https://www.dropboxforum.com/mxpez29397/rss/board?board.id=101003016") as text
set coidBaseURLStr to refMe's NSString's stringWithString:(strURL)
set ocidBaseURL to refMe's NSURL's URLWithString:(coidBaseURLStr)

################################################
###### URLRequest部分
################################################
set ocidURLRequest to refMe's NSMutableURLRequest's alloc()'s init()
ocidURLRequest's setHTTPMethod:"GET"
ocidURLRequest's setURL:(ocidBaseURL)
ocidURLRequest's addValue:"application/xml" forHTTPHeaderField:"Content-Type"
###ポストするデータは空
ocidURLRequest's setHTTPBody:(missing value)

################################################
###### データ取得
################################################
set ocidServerResponse to refMe's NSURLConnection's sendSynchronousRequest:(ocidURLRequest) returningResponse:(missing value) |error|:(reference)
set ocidXMLData to (item 1 of ocidServerResponse)
###ROOTエレメント
set listXMLDoc to refMe's NSXMLDocument's alloc()'s initWithData:(ocidXMLData) options:(refMe's NSXMLDocumentTidyXML) |error|:(reference)
set ocidXMLDoc to item 1 of listXMLDoc
set ocidRootElement to ocidXMLDoc's rootElement()
##channelエレメント
set ocidChannel to ocidRootElement's elementsForName:("channel")
set ocidChannelElement to ocidChannel's firstObject()
set strMainTitle to (ocidChannelElement's elementsForName:("title"))'s stringValue as text
log strMainTitle
###itemエレメント
set ocidItemArray to (ocidChannelElement's elementsForName:("item"))
##
set strContantsHtml to ("") as text
repeat with itemArray in ocidItemArray
  set strItemTitle to (itemArray's elementsForName:("title"))'s stringValue as text
  if strItemTitle contains "Stable" then
    set strItemDescription to (itemArray's elementsForName:("description"))'s stringValue as text
    set strContantsHtml to (strContantsHtml & "<hr>" & strItemDescription) as text
    exit repeat
  end if
end repeat

################################################
##保存先
################################################
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
#
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)

##ファイル名デスクトップが保存先
set strSaveFileName to ("dropbox.html") as text
##保存ファイルパス
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName)


########################################
##HTML 基本構造
###スタイル
set strStylle to "<style>table {padding: 10px;width: 100%;margin: 0;border-collapse: collapse;border-spacing: 0;word-wrap: break-word;} table { width: 80%;margin: 0px;padding: 0px;border: 0px;border-spacing:0px;border-collapse: collapse;} caption { font-weight: 900;} thead { font-weight: 600;border-spacing:0px;} td {border: solid 1px #666666;padding: 5px;margin: 0px;word-wrap: break-word;border-spacing:0px;} tr {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;} th {border: solid 1px #666666;padding: 0px;margin: 0px;border-spacing:0px;}</style>" as text
###ヘッダー部
set strHead to "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><title>" & strMainTitle & "</title>" & strStylle & "</head><body>" as text

###HTML書き出し用のテキスト初期化
set ocidHTMLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
####
ocidHTMLString's appendString:(strHead)
ocidHTMLString's appendString:(strContantsHtml)
###最後
set strHtmlEndBody to "</body></html>"
ocidHTMLString's appendString:(strHtmlEndBody)

set listDone to ocidHTMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


####【9】Finderで開く
set strFilePath to ocidSaveFilePathURL's |path| as text
set strFilePathURL to ocidSaveFilePathURL's absoluteString() as text
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias

tell application "Finder"
open location aliasFilePath
end tell

|

[AS]エラーメッセージをダイアログに表示


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

#!/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 ocidHomeDirUrl to appFileManager's homeDirectoryForCurrentUser()
set ocidSauceDirPathURL to ocidHomeDirUrl's URLByAppendingPathComponent:"Library/Scripts"
set strSauceDirPath to (ocidSauceDirPathURL's |path|()) as text
###################################
#####コピー先フォルダ
###################################
set ocidDistDirPathURL to ocidHomeDirUrl's URLByAppendingPathComponent:"Library/CloudStorage/Dropbox/Scripts"
set strDistDirPath to (ocidDistDirPathURL's |path|()) as text

###################################
#####コマンド実行
###################################

set strCommandText to "/usr/bin/ditto \"" & strSauceDirPath & "\" \"" & strDistDirPath & "\"" as text
try
  set strResponse to (do shell script strCommandText) as text
  ###エラーが発生したらダイアログにエラーメッセージを渡す
on error strResponse
  #####ダイアログを前面に
  tell current application
    set strName to name as text
  end tell
  ####スクリプトメニューから実行したら
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  set aliasIconPath to POSIX file "/Applications/Dropbox.app/Contents/Resources/AppIcon.icns" as alias
  display dialog "一部エラーが発生しました\r確認してください" with title "エラーメッセージ" default answer strResponse buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer
end try




|

[DropBox]エイリアスをデスクトップに作る(修正)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# デスクトップにDropBoxのエイリアスをアイコン付きで作ります
#
#
# 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 strAddAliasFilePath to "~/Desktop/Dropbox" as text
###元ファイルは?
set strOrgFilePath to "~/Library/CloudStorage/Dropbox" as text
###アイコンどうする?
set boolSetIcon to true as boolean
if boolSetIcon is true then
  set strIconFilePath to "/Applications/Dropbox.app/Contents/Resources/AppIcon.icns" as text
end if

####################################
####エイリアスが作られる場所
set ocidAddAliasFilePathStr to refMe's NSString's stringWithString:strAddAliasFilePath
set ocidAddAliasFilePath to ocidAddAliasFilePathStr's stringByStandardizingPath
set ocidAddAliasFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidAddAliasFilePath isDirectory:false
set strAddAliasFilePathURL to ocidAddAliasFilePathURL's |path|() as text

###ディレクトリを作る必要があれば作る
set ocidAddAliasDirFilePathURL to ocidAddAliasFilePathURL's URLByDeletingLastPathComponent()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:511 forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidAddAliasDirFilePathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)

####################################
####エイリアスの元ファイル
####################################
set ocidFilePathStr to refMe's NSString's stringWithString:strOrgFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false

####################################
#### エイリアスを作る
####################################
set listBookMarkNSData to (ocidFilePathURL's bookmarkDataWithOptions:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:{refMe's NSURLCustomIconKey} relativeToURL:(missing value) |error|:(reference))
set ocdiBookMarkData to (item 1 of listBookMarkNSData)
set listResults to (refMe's NSURL's writeBookmarkData:(ocdiBookMarkData) toURL:(ocidAddAliasFilePathURL) options:(refMe's NSURLBookmarkCreationSuitableForBookmarkFile) |error|:(reference))

####################################
#### アイコンを付与
####################################
if boolSetIcon is true then
  ###ICONパス
  set ocidIconPathStr to refMe's NSString's stringWithString:(strIconFilePath)
  set ocidIconPath to ocidIconPathStr's stringByStandardizingPath()
  set ocidIconPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIconPath) isDirectory:false)
  ##アイコン用のイメージデータ取得
  set ocidImageData to (refMe's NSImage's alloc()'s initWithContentsOfURL:(ocidIconPathURL))
  ###NSWorkspace初期化
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  ###アイコン付与
  set boolAddIcon to (appSharedWorkspace's setIcon:(ocidImageData) forFile:(ocidAddAliasFilePath) options:(refMe's NSExclude10_4ElementsIconCreationOption))
end if

return

|

[Dropbox]サインレト・インストール(bash)


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

#!/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
#################################
## RSSから最新のバージョンを取得する
STR_RSS_URL="https://www.dropboxforum.com/mxpez29397/rss/board?board.id=101003016"
XML_RSS_DATA=$(/usr/bin/curl -s "$STR_RSS_URL" | xmllint --format -)
STR_TITLE=$(echo "$XML_RSS_DATA" | xmllint --xpath "//item/title/text()" -)
IFS=$'\n' read -r -d '' -a LIST_TITLE <<<"$STR_TITLE"

for ITEM_TITLE in "${LIST_TITLE[@]}"; do
  if [[ $ITEM_TITLE == *"Stable"* ]]; then
  /bin/echo "$ITEM_TITLE"
    read -ra ARRAY_TITLE <<<"$ITEM_TITLE"
    STR_VERSION=${ARRAY_TITLE[2]}
  /bin/echo "$STR_VERSION"
    break
  fi
done
#################################
##URLを生成する
STR_BASE_URL="https://edge.dropboxstatic.com/dbx-releng/client/"
###CPUタイプでの分岐
ARCHITEC=$(/usr/bin/arch)
if [ "$ARCHITEC" == "arm64" ]; then
STR_DMG_FILE_NAME="Dropbox%20$STR_VERSION.arm64.dmg"
DL_FILE_NAME="Dropbox $STR_VERSION.arm64.dmg"
STR_URL="$STR_BASE_URL$STR_DMG_FILE_NAME"
else
STR_DMG_FILE_NAME="Dropbox%20$STR_VERSION.dmg" 
DL_FILE_NAME="Dropbox $STR_VERSION.dmg"
STR_URL="$STR_BASE_URL$STR_DMG_FILE_NAME"
fi
  /bin/echo "$STR_URL"
#################################
##ダウンロード
LOCAL_TMP_DIR=$(/usr/bin/sudo -u "$SUDO_USER" /usr/bin/mktemp -d)
/bin/echo "TMPDIR:" "$LOCAL_TMP_DIR"

if [ "$ARCHITEC" == "arm64" ]; then
  /bin/echo "Running on $ARCHITEC"
  ###ダウンロード
  if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
    if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
      /bin/echo "ファイルのダウンロードに失敗しました"
      exit 1
    fi
  fi
else
  /bin/echo "Running on $ARCHITEC"
  ###ダウンロード
  if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
    if ! /usr/bin/curl -L -o "$LOCAL_TMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
      /bin/echo "ファイルのダウンロードに失敗しました"
      exit 1
    fi
  fi
fi
#################################
###プロセス終了
STR_APP_NAME="Dropbox.app"
###
STR_PLIST_PATH="/Applications/$STR_APP_NAME/Contents/Info.plist"
STR_BUNDLE_ID=$(/usr/bin/defaults read "$STR_PLIST_PATH" CFBundleIdentifier)
/bin/echo "STR_BUNDLE_ID" "$STR_BUNDLE_ID"
##念の為 KILLもする
/usr/bin/killall "Dropbox" 2>/dev/null
/usr/bin/killall "Dropbox Helper" 2>/dev/null
/usr/bin/killall "Dropbox Helper (Renderer)" 2>/dev/null
/usr/bin/killall "Dropbox Helper (Plugin)" 2>/dev/null
/usr/bin/killall "Dropbox Helper (GPU)" 2>/dev/null
/usr/bin/killall "DropboxActivityProvider" 2>/dev/null
/usr/bin/killall "DropboxFileProviderCH" 2>/dev/null
/usr/bin/killall "DropboxFileProvider" 2>/dev/null
/usr/bin/killall "DropboxTransferExtension" 2>/dev/null
/bin/echo "アプリケーション終了"
/bin/sleep 2

#################################
  function DO_MOVE_TO_TRASH() {
    if [ -e "$1" ]; then
      TRASH_DIR=$(/usr/bin/sudo -u "$SUDO_USER" /usr/bin/mktemp -d "/var/folders/TemporaryItems/XXXXXXXX")
      /usr/bin/sudo /bin/chmod 777 "$TRASH_DIR"
      /usr/bin/sudo /bin/mv "$1" "$TRASH_DIR"
      ##削除
      /usr/bin/sudo /usr/bin/find "$TRASH_DIR" -mindepth 1 -delete
    fi
}
#####古いファイルをゴミ箱に LOCAL
DO_MOVE_TO_TRASH "/Library/DropboxHelperTools"
DO_MOVE_TO_TRASH "/Applications/Dropbox.app"
DO_MOVE_TO_TRASH "/Users/$SUDO_USER/Library/Dropbox"
DO_MOVE_TO_TRASH "/Users/$SUDO_USER/Library/HTTPStorages/com.dropbox.DropboxMacUpdate"
DO_MOVE_TO_TRASH "/Users/$SUDO_USER/Library/HTTPStorages/com.getdropbox.dropbox"
#################################
/usr/bin/hdiutil attach  "$LOCAL_TMP_DIR/$DL_FILE_NAME" -noverify -nobrowse -noautoopen


###########この方法だとサイレントにならない
#/usr/bin/sudo "/Volumes/Dropbox Offline Installer/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch

/usr/bin/ditto "/Volumes/Dropbox Offline Installer/Dropbox.app" "/Applications/Dropbox.app"

/usr/bin/hdiutil detach "/Volumes/Dropbox Offline Installer" -force

###ここは好みの問題か?
/usr/bin/sudo  chown -Rf root "/Applications/Dropbox.app"
#/usr/bin/sudo chown -Rf "$SUDO_USER" "/Applications/Dropbox.app"

###実行はユーザーにまかせるのもあり?
##/usr/bin/sudo "/Applications/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch
##/usr/bin/sudo -u "$SUDO_USER" "/Applications/Dropbox.app/Contents/MacOS/Dropbox" - nolaunch

exit 0




|

[Dropbox]サインレト・インストール(途中)

コマンド的には
set theComandText to ("\"/Volumes/Dropbox Offline Installer/Dropbox.app/Contents/MacOS/Dropbox\" - nolaunch") as text
do shell script theComandText

なんだろうけど… Acrobatと同様にパスワードを要求してくるので、完全サイレントとはいかない dittoした方がいいのだろうか?

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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#https://www.dropboxforum.com/t5/Dropbox-desktop-client-builds/bd-p/101003016
#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
##########################
## 最新のバージョン取得
##########################
##RSSのURL
set strRssURL to "https://www.dropboxforum.com/mxpez29397/rss/board?board.id=101003016" as text
set ocidRssURL to refMe's NSURL's URLWithString:(strRssURL)
###XML読み込み
set ocidOption to refMe's NSXMLDocumentTidyXML
set listXmlDoc to refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidRssURL) options:(ocidOption) |error|:(reference)
set ocidReadXMLDoc to (item 1 of listXmlDoc)
###ROOT
set ocidRootElement to ocidReadXMLDoc's rootElement()
set numChild to (count of ocidRootElement's children) as integer
###第一階層 channel
set ocidChannel to (ocidRootElement's childAtIndex:0)
set numChild to (count of ocidChannel's children) as integer
###子要素の数だけ繰り返し
repeat with numCntChild from 0 to (numChild - 1)
  set strChldName to (ocidChannel's childAtIndex:numCntChild)'s |name| as text
  ####要素名がitemなら
  if strChldName is "item" then
    ###itemのtitleをテキストで取得して
    set ocidItemObject to ((ocidChannel's childAtIndex:numCntChild)'s childAtIndex:0)
    set ocidTitle to ocidItemObject's stringValue()
    ###最初のStable項目=最新
    if (ocidTitle as text) contains "Stable" then
      set ocidTitleArray to (ocidTitle's componentsSeparatedByString:(" "))
      ###バージョンテキストを取得したらリピート終了
      set strVersion to (ocidTitleArray's lastObject()) as text
      exit repeat
    end if
  end if
end repeat
###取得したバージョン番号
log strVersion
##########################
## ダウンロードするURLを生成
##########################
##CPUタイプのよる処理の分岐
set objSysInfo to system info
set theCpuType to (CPU type of objSysInfo) as text

if theCpuType contains "Intel" then
  # set strURL to "https://www.dropbox.com/downloading?plat=mac&type=full"
  set strFileName to "Dropbox " & strVersion & ".dmg" as text
  # set strURL to ("https://edge.dropboxstatic.com/dbx-releng/client/" & strFileName & "") as text
else
  #set strURL to "https://www.dropbox.com/downloading?plat=mac&type=full&arch=arm64"
  set strFileName to "Dropbox " & strVersion & ".arm64.dmg" as text
  #set strURL to ("https://edge.dropboxstatic.com/dbx-releng/client/" & strFileName & "") as text
end if
####ダウンロードするDMGファイル名とURLが確定
set ocidURL to refMe's NSURL's alloc()'s initWithString:("https://edge.dropboxstatic.com/dbx-releng/client/")
##ファイル名
set ocidURL to ocidURL's URLByAppendingPathComponent:(strFileName)
set strURL to ocidURL's absoluteString() as text
log strURL as text

##########################
## ダウンロードするファイル
##########################
###テンポラリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTemporaryDirPathURL to appFileManager's temporaryDirectory
set ocidTemporaryItemsPathURL to ocidTemporaryDirPathURL's URLByAppendingPathComponent:("TemporaryItems")
###同一パスにならないようにUUIDを足す
set ocidUUID to refMe's NSUUID's alloc()'s init()
set coidUUID to ocidUUID's UUIDString()
set ocidLocalUUIDPathURL to ocidTemporaryItemsPathURL's URLByAppendingPathComponent:(coidUUID)
###DMG保存ディレクトリ
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
appFileManager's createDirectoryAtURL:(ocidLocalUUIDPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
###ファイル名を足してDMGの保存パス
set ocidLocalPathURL to ocidLocalUUIDPathURL's URLByAppendingPathComponent:(strFileName)
set strLocalPath to (ocidLocalPathURL's |path|) as text
##########################
## ダウンロード
##########################
try
  set strCommandText to ("/usr/bin/curl -L -o \"" & strLocalPath & "\"   \"" & strURL & "\" --connect-timeout 10") as text
  do shell script strCommandText
on error
  set strCommandText to ("/usr/bin/curl -L -o \"" & strLocalPath & "\"   \"" & strURL & "\" --http1.1 --connect-timeout 10") as text
  do shell script strCommandText
end try

##########################
## 関連プロセス終了
##########################
set listBundleID to {"com.dropbox.Electron.helper", "com.getdropbox.dropbox"}

repeat with itemUTI in listBundleID
  ###NSRunningApplication
  set ocidRunningApplication to refMe's NSRunningApplication
  ###起動中のすべてのリスト
  set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(itemUTI))
  ###複数起動時も順番に終了
  repeat with itemAppArray in ocidAppArray
itemAppArray's terminate()
  end repeat
end repeat

##########################
## 関連プロセス終了
##########################
try
  tell application id "com.getdropbox.dropbox" to quit
end try
try
  do shell script "killall \"Dropbox Helper\""
  do shell script "killall \"Dropbox Helper (Renderer)\""
  do shell script "killall \"Dropbox Helper (Plugin)\""
  do shell script "killall \"Dropbox Helper (GPU)\""
  do shell script "killall \"Dropbox\""
  do shell script "killall \"DropboxActivityProvider\""
  do shell script "killall \"DropboxFileProviderCH\""
  do shell script "killall \"DropboxFileProvider\""
  do shell script "killall \"DropboxTransferExtension\""
end try
##########################
## 本処理
##########################
##appNSWorkspaceでドライブを表示しないマウント方法がわからない
set theComandText to ("/usr/bin/hdiutil attach \"" & strLocalPath & "\" -noverify -nobrowse -noautoopen\n") as text
do shell script theComandText



set theComandText to ("\"/Volumes/Dropbox Offline Installer/Dropbox.app/Contents/MacOS/Dropbox\" - nolaunch") as text
do shell script theComandText


delay 10

##########################
## アンマウント
##########################
set strDiskPath to "/Volumes/Dropbox Offline Installer"
set ocidDiskPathStr to refMe's NSString's stringWithString:(strDiskPath)
set ocidDiskPath to ocidDiskPathStr's stringByExpandingTildeInPath()
set ocidDiskPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDiskPath) isDirectory:false)
set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
(appNSWorkspace's unmountAndEjectDeviceAtURL:(ocidDiskPathURL) |error|:(reference))
try
  set theComandText to ("/usr/bin/hdiutil detach \"" & strDiskPath & "\" -force") as text
  do shell script theComandText
end try



|

[CloudStorage]クラウドドライブを開く

複数アカウントに対応した
CloudStorageの複数アカウントは
『サービス名』-『アカウント名』となっている
OneDriveなら
OneDrive-個人用 OneDrive-企業名 OneDrive-組織名
GoogleDriveなら
GoogleDrive-メールアドレス
Boxなら
Box-Boxが個人用 Box-アカウント名が組織用



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

#!/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 strDriveName to "GoogleDrive" as text
(*
set strDriveName to "Box"
set strDriveName to "OneDrive"
set strDriveName to "DropBox"
set strDriveName to "GoogleDrive"
*)


set appFileManager to refMe's NSFileManager's defaultManager()
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()

###################################
#####パス
###################################
set ocidHomeDirUrl to appFileManager's homeDirectoryForCurrentUser()
set ocidCloudStorageDirURL to ocidHomeDirUrl's URLByAppendingPathComponent:"Library/CloudStorage"

###################################
#####複数アカウントあるか調べる
###################################
###プロパティ設定
set ocidPropertieKey to {(refMe's NSURLPathKey), (refMe's NSURLIsDirectoryKey)}
###オプション設定
set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles
###ディレクトリのコンテンツを取得(第一階層のみ)
set listPathUrlArray to (appFileManager's contentsOfDirectoryAtURL:ocidCloudStorageDirURL includingPropertiesForKeys:ocidPropertieKey options:ocidOption |error|:(reference))
###Arrayに格納
set ocidPathUrlArray to item 1 of listPathUrlArray
###パス格納用のArrayを作って
set ocidPathArray to (refMe's NSMutableArray's arrayWithCapacity:0)
####コンテンツの数だけ繰り返し
repeat with itemPathUrlArray in ocidPathUrlArray
  ###最後のパスを取得して
  set ocidLastPathName to itemPathUrlArray's lastPathComponent()
  ###テキストに
  set strLastPathName to ocidLastPathName as text
  ###最後のパスにBoxが含まれていたら
  if strLastPathName starts with strDriveName then
    ###Arrayに格納
    (ocidPathArray's addObject:itemPathUrlArray)
  end if
end repeat
###################################
#####複数アカウント時
###################################
set numCntArray to (ocidPathArray count) as integer
#####アカウント数0
if numCntArray = 0 then
  return "CloudStorageに対象のアカウントがありません。ソフトウェアをアップデートしてください"
  ####アカウント数1
else if numCntArray = 1 then
  set ocidFilePathURL to ocidPathArray's objectAtIndex:0
  set aliasFilePathURL to ocidFilePathURL as alias
  set boolResults to (appShardWorkspace's openURL:ocidFilePathURL)
  if boolResults is false then
    tell application "Finder"
      make new Finder window to aliasFilePathURL
    end tell
  end if
  return "処理終了"
else
  ####複数アカウント
  set listDirName to {} as list
  repeat with itemPathArray in ocidPathArray
    set strDirName to (itemPathArray's lastPathComponent()) as text
    copy strDirName to end of listDirName
  end repeat
  ####ダイアログを前面に出す
  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 listDirName with title "選んでください" with prompt "開くフォルダを選んでください" default items (item 1 of listDirName) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed)
    log class of listResponse
  on error
    log "エラーしました"
    return "エラーしました"
  end try
  if listResponse is false then
    return "キャンセルしました"
  end if
  set itemPathArray to (item 1 of listResponse) as text
  set ocidCloudStorageDirURL to ocidCloudStorageDirURL's URLByAppendingPathComponent:strDirName
end if

###################################
#####開く
###################################
repeat with itemPathArray in ocidPathArray
  set aliasFilePathURL to itemPathArray as alias
  set boolResults to (appShardWorkspace's openURL:itemPathArray)
  if boolResults is false then
    tell application "Finder"
      make new Finder window to aliasFilePathURL
    end tell
  end if
end repeat

return "選択オープン処理終了"





|

その他のカテゴリー

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 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