« PDFの各ページ 回転 と 各種BOXサイズをTSVタブ区切りテキストに出力する(少し修正) | トップページ | 途中で途切れるハイライト注釈をつなげて1つにする »

[zoom]zoomインストール(pkgutilで解凍する)


AppleScript サンプルコード

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

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#   セルフインストールのサンプル zoom
005# pkgutil  --expand-full で解凍する方法
006#
007# com.cocolog-nifty.quicktimer.icefloe
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013
014property refMe : a reference to current application
015
016
017##################################
018##【1】CPUタイプのよる処理の分岐
019set recordSysInfo to system info
020set strCpuType to (CPU type of recordSysInfo) as text
021if strCpuType contains "Intel" then
022  set strPkgURL to "https://zoom.us/client/latest/Zoom.pkg?archType=x86" as text
023  log strCpuType
024else if strCpuType contains "ARM" then
025  set strPkgURL to "https://zoom.us/client/latest/Zoom.pkg?archType=arm64" as text
026  log strCpuType
027else
028  return "不明なCUP処理終了"
029end if
030
031##################################
032##【2】ダウンロード 
033##起動時に削除する項目
034set appFileManager to refMe's NSFileManager's defaultManager()
035set ocidTempDirURL to appFileManager's temporaryDirectory()
036##フォルダ名はUUIDを使う
037set ocidConcreteUUID to refMe's NSUUID's UUID()
038set ocidUUIDString to ocidConcreteUUID's UUIDString()
039set ocidTempDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
040##フォルダを777アクセス権で作成
041set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
042ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
043set boolDone to appFileManager's createDirectoryAtURL:(ocidTempDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference)
044log boolDone
045set strTempDirPath to (ocidTempDirPathURL's |path|()) as text
046##ファイル名を取得
047try
048  set strCommandText to ("/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' \"" & strPkgURL & "\" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev") as text
049  set strSaveFileName to (do shell script strCommandText) as text
050on error
051  try
052    set strCommandText to ("/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' \"" & strPkgURL & "\"  --http1.1 --connect-timeout 20 | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev") as text
053    set strSaveFileName to (do shell script strCommandText) as text
054  on error
055    set strSaveFileName to "install.pkg"
056  end try
057end try
058##ダウンロード
059try
060  set strCommandText to "/usr/bin/curl -L -o  \"" & strTempDirPath & "/" & strSaveFileName & "\"  \"" & strPkgURL & "\" --connect-timeout 20" as text
061  do shell script strCommandText
062on error
063  try
064    set strCommandText to "/usr/bin/curl -L -o  \"" & strTempDirPath & "/" & strSaveFileName & "\"  \"" & strPkgURL & "\"  --http1.1 --connect-timeout 20" as text
065    do shell script strCommandText
066  on error
067    return "インストーラーのダウンロードに失敗しました"
068  end try
069end try
070
071
072##################################
073##【3】インストール前準備
074###Dockのポジションを記憶 "/Library/Managed Preferences" は考慮しない
075set strFilePath to "~/Library/Preferences/com.apple.dock.plist" as text
076set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
077set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
078set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
079set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL)
080set ocidPerAppsArray to ocidPlistDict's objectForKey:("persistent-apps")
081set intArrayNo to (count of ocidPerAppsArray) as integer
082set intCntNo to 0 as integer
083repeat with itemerAppsArray in ocidPerAppsArray
084  set ocidTitleDataDict to (itemerAppsArray's objectForKey:("tile-data"))
085  set ocidFileDataDict to (ocidTitleDataDict's objectForKey:("file-data"))
086  set ocidCFURLString to (ocidFileDataDict's valueForKey:("_CFURLString"))
087  if (ocidCFURLString as text) contains ("zoom.us.app") then
088    exit repeat
089  end if
090  set intCntNo to intCntNo + 1 as integer
091end repeat
092if intArrayNo = intCntNo then
093  set intDocNo to (intArrayNo) as integer
094  log "Dockに登録されていません。一番下を指定します"
095else
096  set intDocNo to (intCntNo) as integer
097  log "Dockの " & intCntNo & "番目に登録されています"
098end if
099
100###アプリケーション終了
101set listUTI to {"us.zoom.caphost", "us.zoom.xos", "us.zoom.CptHost", "us.zoom.Transcode", "us.zoom.ZMScreenshot"} as list
102###通常終了
103repeat with itemUTI in listUTI
104  ###NSRunningApplication
105  set ocidRunningApplication to refMe's NSRunningApplication
106  ###起動中のすべてのリスト
107  set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(itemUTI))
108  ###複数起動時も順番に終了
109  repeat with itemAppArray in ocidAppArray
110    itemAppArray's terminate()
111  end repeat
112end repeat
113delay 2
114###強制終了
115repeat with itemUTI in listUTI
116  ###NSRunningApplication
117  set ocidRunningApplication to refMe's NSRunningApplication
118  ###起動中のすべてのリスト
119  set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(itemUTI))
120  ###複数起動時も順番に終了
121  repeat with itemAppArray in ocidAppArray
122    itemAppArray's forceTerminate()
123  end repeat
124end repeat
125###ユーザーアプリケーションディレクトリ700で
126set ocidURLsPathArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
127set ocidAppDirPathURL to ocidURLsPathArray's firstObject()
128set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
129ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
130set boolDone to appFileManager's createDirectoryAtURL:(ocidAppDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference)
131###ローカライズファイル
132set ocidLocalizedPathURL to ocidAppDirPathURL's URLByAppendingPathComponent:(".localized")
133set ocidLocalizedPath to ocidLocalizedPathURL's |path|()
134set boolDone to appFileManager's createFileAtPath:(ocidLocalizedPath) |contents|:(missing value) attributes:(ocidAttrDict)
135###Groupsフォルダ
136set ocidGroupsDirPathURL to ocidAppDirPathURL's URLByAppendingPathComponent:("Groups")
137set boolDone to appFileManager's createDirectoryAtURL:(ocidGroupsDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference)
138###ローカライズファイル
139set ocidLocalizedPathURL to ocidGroupsDirPathURL's URLByAppendingPathComponent:(".localized")
140set ocidLocalizedPath to ocidLocalizedPathURL's |path|()
141set boolDone to appFileManager's createFileAtPath:(ocidLocalizedPath) |contents|:(missing value) attributes:(ocidAttrDict)
142
143###ゴミ箱
144set ocidURLsPathArray to (appFileManager's URLsForDirectory:(refMe's NSTrashDirectory) inDomains:(refMe's NSUserDomainMask))
145set ocidTrashDirPathURL to ocidURLsPathArray's firstObject()
146
147################################################
148###クリーニング
149################################################
150to doGoToTrash(arg_strFilePath)
151  set strFilePath to arg_strFilePath as text
152  set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
153  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
154  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
155  set appFileManager to refMe's NSFileManager's defaultManager()
156  set boolDone to appFileManager's trashItemAtURL:(ocidFilePathURL) resultingItemURL:(ocidFilePathURL) |error| :(reference)
157end doGoToTrash
158
159doGoToTrash("/Applications/zoom.us.app")
160doGoToTrash("/Applications/ZoomOutlookPlugin")
161doGoToTrash("~/Applications/zoom.us.app")
162doGoToTrash("~/Applications/Groups/zoom.us.app")
163delay 1 --> Dockからの削除待ち
164doGoToTrash("~/Applications/ZoomOutlookPlugin")
165doGoToTrash("~/Library/Caches/us.zoom.xos")
166doGoToTrash("~/Library/WebKit/us.zoom.xos")
167doGoToTrash("~/Library/Saved Application State/us.zoom.xos.savedState")
168doGoToTrash("~/Library/Receipts/ZoomMacOutlookPlugin.pkg.plist")
169doGoToTrash("~/Library/Receipts/ZoomMacOutlookPlugin.pkg.bom")
170doGoToTrash("~/Library/Logs/ZoomPhone")
171doGoToTrash("~/Library/Logs/zoom.us")
172doGoToTrash("~/Library/HTTPStorages/us.zoom.xos.binarycookies")
173doGoToTrash("~/Library/HTTPStorages/us.zoom.xos")
174
175delay 1 --> Dockからの削除待ち
176
177##################################
178##【4】インストール本処理(ユーザーインストール)
179###パッケージがあるか?確認
180set strPkgPath to ("" & strTempDirPath & "/" & strSaveFileName & "") as text
181set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
182set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
183set boolFileExist to appFileManager's fileExistsAtPath:(ocidFilePath) isDirectory:(false)
184if boolFileExist = true then
185  # set strCommandText to "/usr/sbin/installer -pkg    \"" & strTempDirPath & "/" & strSaveFileName & "\" -target CurrentUserHomeDirectory -dumplog -allowUntrusted  -lang ja" as text
186  set strCommandText to ("/usr/sbin/pkgutil  --expand-full \"" & strTempDirPath & "/" & strSaveFileName & "\" \"" & strTempDirPath & "/EXPAND" & "\"") as text
187  log strCommandText
188  do shell script strCommandText
189else
190  return "パッケージが見つかりません"
191end if
192###移動
193set ocidExpandAppPathURL to ocidTempDirPathURL's URLByAppendingPathComponent:("/EXPAND/zoomus.pkg/Payload/zoom.us.app") isDirectory:(false)
194###ユーザーインストールした場合のURL
195set strAppPath to "~/Applications/Groups/zoom.us.app" as text
196set ocidAppPathstr to refMe's NSString's stringWithString:(strAppPath)
197set ocidAppPath to ocidAppPathstr's stringByStandardizingPath()
198set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAppPath) isDirectory:true
199###移動
200set ListDone to (appFileManager's moveItemAtURL:(ocidExpandAppPathURL) toURL:(ocidAppPathURL) |error| :(reference))
201
202##開く
203set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
204set ocidOpenURLsArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
205(ocidOpenURLsArray's addObject:(ocidAppPathURL))
206appSharedWorkspace's activateFileViewerSelectingURLs:(ocidOpenURLsArray)
207
208##################################
209##【5】後処理
210
211set coidAbsoluteStringPath to ocidAppPathURL's absoluteString()
212
213################################
214###PLIST 読み込み
215set strFilePath to "~/Library/Preferences/com.apple.dock.plist" as text
216set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
217set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
218set ocidPlistPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
219set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithContentsOfURL:(ocidPlistPathURL)
220set ocidPersistentArray to ocidPlistDict's objectForKey:"persistent-apps"
221
222################################
223####persistent-appsデータ生成
224set ocidAddDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
225###GUID実際はランダム番号だがNSFileSystemFileNumberを使う
226set listPathAttar to appFileManager's attributesOfItemAtPath:(ocidAppPath) |error| :(reference)
227set ocidAttar to item 1 of listPathAttar
228set numGUID to ocidAttar's valueForKey:(refMe's NSFileSystemFileNumber)
229set ocidIntValue to (refMe's NSNumber's numberWithInteger:(numGUID))
230ocidAddDict's setValue:(numGUID) forKey:("GUID")
231###
232set ocidStringValue to (refMe's NSString's stringWithString:("file-tile"))
233ocidAddDict's setValue:(ocidStringValue) forKey:("tile-type")
234################################
235set ocidAddTitleDataDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
236####dock-extra
237set ocidBoolValue to (refMe's NSNumber's numberWithBool:false)
238ocidAddTitleDataDict's setValue:(ocidBoolValue) forKey:("dock-extra")
239####dock-extra
240set ocidBoolValue to (refMe's NSNumber's numberWithBool:false)
241ocidAddTitleDataDict's setValue:(ocidBoolValue) forKey:("is-beta")
242####bundle-identifier
243set ocidAppBundle to (refMe's NSBundle's bundleWithURL:(ocidAppPathURL))
244set ocidBundleID to ocidAppBundle's bundleIdentifier
245set ocidStringValue to ocidBundleID's UTF8String()
246ocidAddTitleDataDict's setValue:(ocidStringValue) forKey:("bundle-identifier")
247####file-label"
248set listAttributesDict to ocidAppPathURL's resourceValuesForKeys:({refMe's NSURLLocalizedNameKey}) |error| :(reference)
249set ocidAttributesDict to (item 1 of listAttributesDict)
250set ocidLocalizedName to (ocidAttributesDict's objectForKey:(refMe's NSURLLocalizedNameKey))
251set ocidFileLabel to (ocidLocalizedName's stringByDeletingPathExtension())
252set ocidStringValue to ocidFileLabel's UTF8String()
253ocidAddTitleDataDict's setValue:(ocidStringValue) forKey:("file-label")
254####file-mod-date
255set listAttributesDict to ocidAppPathURL's resourceValuesForKeys:({refMe's NSURLContentModificationDateKey}) |error| :(reference)
256set ocidAttributesDict to (item 1 of listAttributesDict)
257set ocidModificationDate to (ocidAttributesDict's objectForKey:(refMe's NSURLContentModificationDateKey))
258set ocidModDate to ocidModificationDate's timeIntervalSince1970
259set ocidIntValue to ocidModDate's intValue()
260ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("file-mod-date")
261####parent-mod-date
262set ocidNow to refMe's NSDate's now
263set ocidNowNo to ocidNow's timeIntervalSince1970
264set ocidIntValue to ocidNowNo's intValue
265ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("parent-mod-date")
266####book
267set listBookMarkData to (ocidAppPathURL's bookmarkDataWithOptions:(11) includingResourceValuesForKeys:({missing value}) relativeToURL:(missing value) |error| :(reference))
268set ocidkDataValue to item 1 of listBookMarkData
269(ocidAddTitleDataDict's setObject:(ocidkDataValue) forKey:("book"))
270####file-type
271# 169   Launchpad とMission Control
272# 41      それ以外はまぁ41で間違いなさそう
273set ocidIntValue to (refMe's NSNumber's numberWithInteger:41)
274(ocidAddTitleDataDict's setValue:(ocidIntValue) forKey:("file-type"))
275#########
276set ocidAddFileDataDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
277(ocidAddFileDataDict's setValue:(coidAbsoluteStringPath) forKey:("_CFURLString"))
278####
279#   0 /File/Path
280#   15 file:// のURL形式
281set ocidIntValue to (refMe's NSNumber's numberWithInteger:15)
282(ocidAddFileDataDict's setValue:(ocidIntValue) forKey:("_CFURLStringType"))
283#########
284(ocidAddTitleDataDict's setObject:(ocidAddFileDataDict) forKey:("file-data"))
285ocidAddDict's setObject:(ocidAddTitleDataDict) forKey:("tile-data")
286####追加データを元のPLISTに戻す
287ocidPersistentArray's insertObject:(ocidAddDict) atIndex:(intDocNo)
288####保存
289set boolDone to ocidPlistDict's writeToURL:(ocidPlistPathURL) atomically:true
290
291
292###CFPreferencesを再起動
293try
294  set strCommandText to "/usr/bin/killall cfprefsd" as text
295  do shell script strCommandText
296on error
297  set strPlistPath to "/System/Library/LaunchAgents/com.apple.cfprefsd.xpc.agent.plist"
298  set strCommandText to ("/bin/launchctl stop -w \"" & strAgentPath & "\"")
299  try
300    do shell script strCommandText
301  end try
302  set strCommandText to ("/bin/launchctl start -w \"" & strAgentPath & "\"")
303  try
304    do shell script strCommandText
305  end try
306end try
307
308########################
309## Dock 再起動
310########################
311
312set strBundleID to "com.apple.dock"
313
314########################
315## 再起動
316########################
317set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
318##バンドルからアプリケーションのURLを取得
319set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
320if ocidAppBundle ≠ (missing value) then
321  set ocidAppPathURL to ocidAppBundle's bundleURL()
322else if ocidAppBundle = (missing value) then
323  set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
324end if
325##予備(アプリケーションのURL)
326if ocidAppPathURL = (missing value) then
327  tell application "Finder"
328    try
329      set aliasAppApth to (application file id strBundleID) as alias
330      set strAppPath to POSIX path of aliasAppApth as text
331      set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
332      set strAppPath to strAppPathStr's stringByStandardizingPath()
333      set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
334    on error
335      return "アプリケーションが見つかりませんでした"
336    end try
337  end tell
338end if
339##Dock終了
340set ocidRunningApplication to refMe's NSRunningApplication
341###起動中のすべてのリスト
342set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
343###複数起動時も順番に終了
344repeat with itemAppArray in ocidAppArray
345  ###終了
346  itemAppArray's terminate()
347end repeat
348##1秒まって終了を確認
349delay 1
350##終了できない場合は強制終了
351repeat with itemAppArray in ocidAppArray
352  set boolTerminate to itemAppArray's terminated
353  if boolTerminate = false then
354    itemAppArray's forceTerminate()
355  end if
356end repeat
357
358###起動
359set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
360###コンフィグ
361(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
362###起動
363(appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value))
364
365return "再起動"
AppleScriptで生成しました

|

« PDFの各ページ 回転 と 各種BOXサイズをTSVタブ区切りテキストに出力する(少し修正) | トップページ | 途中で途切れるハイライト注釈をつなげて1つにする »

zoom」カテゴリの記事