Slack

appleScriptでバージョンチェック(例:Slack)


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

SackVersion.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004Slackのバージョンチェック
005
006
007com.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
015property strBundleID : "com.tinyspeck.slackmacgap"
016
017
018##########################
019#インストール済みバージョン
020set appFileManager to refMe's NSFileManager's defaultManager()
021set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
022#NSバンドルを取得して
023set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
024if ocidAppBundle ≠ (missing value) then
025   #NSBundleが取得できればそのまま処理継続
026   set ocidAppPathURL to ocidAppBundle's bundleURL()
027   #NSBundleでアプリケーションが取得できない場合は
028else if ocidAppBundle = (missing value) then
029   #NSワークスペースでアプリケーションのURLを取得する
030   set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
031end if
032#この時点でアプリケーションを取得できない場合は
033if ocidAppPathURL = (missing value) then
034   tell application "Finder"
035      try
036         #Fidenerで取得を試みる
037         set aliasAppApth to (application file id strBundleID) as alias
038      on error
039         #Finderでも見つけられない=ディスク上にあっても未起動の場合とか?
040         log "アプリケーションが見つかりませんでした"
041         #ここで諦めてエラーとしてmissing valueを戻す
042         return (missing value)
043      end try
044   end tell
045   #アプケーションを取得できたなら=FinderNSURLにしておく
046   set strAppPath to POSIX path of aliasAppApth as text
047   set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
048   set strAppPath to strAppPathStr's stringByStandardizingPath()
049   set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(true)
050end if
051#この時点でアプリケーション取得できない場合はエラー
052########################
053#Plistを調べてバイナリー名を取得
054set ocidAppBundle to (refMe's NSBundle's bundleWithURL:(ocidAppPathURL))
055set ocidInfoDict to ocidAppBundle's infoDictionary()
056#   log ocidInfoDict's allKeys() as list
057#   log (ocidInfoDict's valueForKey:"CFBundleInfoDictionaryVersion") as text
058#   log (ocidInfoDict's valueForKey:"CFBundleVersion") as text
059#   log (ocidInfoDict's valueForKey:"CFBundleNumericVersion") as text
060set ocidVersionString to (ocidInfoDict's valueForKey:"CFBundleShortVersionString")
061
062##########################
063#カレントの最新版
064set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
065ocidURLComponents's setScheme:("https")
066ocidURLComponents's setHost:("slack.com")
067ocidURLComponents's setPath:("/ssb/download-osx-silicon")
068set ocidURL to ocidURLComponents's |URL|()
069
070##########################
071#リダイレクト先の取得
072#リクエスト
073set appRequest to refMe's NSMutableURLRequest's requestWithURL:(ocidURL)
074#初期設定
075set ocidConf to (refMe's NSURLSessionConfiguration's defaultSessionConfiguration)
076#キュー
077set appQueue to (refMe's NSOperationQueue's mainQueue)
078#セッション
079set appSession to refMe's NSURLSession's sessionWithConfiguration:(ocidConf) delegate:("self") delegateQueue:(appQueue)
080#タスク
081#set appTask to appSession's dataTaskWithRequest:(appRequest)
082set appTask to appSession's dataTaskWithURL:(ocidURL) completionHandler:(missing value)
083#タスク 開始
084appTask's resume()
085#最大5秒のループ
086repeat 5 times
087   #タスクのステータス取得
088   set ocidStatue to appTask's state()
089   log ocidStatue as text
090   #実行中なら
091   if ocidStatue = (refMe's NSURLSessionTaskStateRunning as integer) then
092      #レスポンスの内容を取得して
093      set ocidResponse to appTask's response()
094      #まだ取得できない状態なら
095      if ocidResponse = (missing value) then
096         #1秒待つ
097         delay 1
098      else
099         #レスポンスが取得できたら
100         log ocidResponse's statusCode()
101         #クラスを確認(なければここでエラーになる)
102         log (ocidResponse's isKindOfClass:(refMe's NSHTTPURLResponse's |class|))
103         #リダイレクトされたURLを取得して
104         set ocidRedirectURL to ocidResponse's |URL|
105         exit repeat
106      end if
107   end if
108end repeat
109#タスクをキャンセル終了する
110appTask's cancel()
111#戻り値
112set strURL to ocidRedirectURL's absoluteString() as text
113#ダウンロードするファイル名
114set ocidFileName to ocidRedirectURL's lastPathComponent()
115set ocidFileName to ocidFileName as text
116#
117set ocidContainerDirPathURL to ocidRedirectURL's URLByDeletingLastPathComponent()
118set strVerSionNO to ocidContainerDirPathURL's lastPathComponent()
119
120##########################
121#
122log "インストール済み: " & ocidVersionString as text
123log "最新バージョン: " & strVerSionNO as text
124
125return "\rインストール済み: " & (ocidVersionString as text) & "\r最新バージョン: " & (strVerSionNO as text) & "\r"
126
127(*
128"
129インストール済み: 4.44.59
130最新バージョン: 4.44.59
131"
132*)
AppleScriptで生成しました

| | コメント (0)

Slack 最新版 ユーザーインストールスクリプト


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

SackUpdate.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004Slackの最新版のインストール
005インストール先は
006/Users/SOME_USER/Applications/Groups
007
008
009インストール後にキャッシュをゴミ箱に入れて
010ダウンロードしたDMGもゴミ箱に入れます
011
012v1 初回作成
013v1.1 キャッシュをゴミ箱に入れる処理を追加
014v1.2 ダウンロードしたDMGもゴミ箱に入れるようにした
015
016com.cocolog-nifty.quicktimer.icefloe *)
017----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
018use AppleScript version "2.8"
019use framework "Foundation"
020use framework "AppKit"
021use scripting additions
022
023property refMe : a reference to current application
024property strBundleID : "com.tinyspeck.slackmacgap"
025
026##########################
027#URL
028set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
029ocidURLComponents's setScheme:("https")
030ocidURLComponents's setHost:("slack.com")
031ocidURLComponents's setPath:("/ssb/download-osx-silicon")
032set ocidURL to ocidURLComponents's |URL|()
033
034##########################
035#リダイレクト先の取得
036
037#リクエスト
038set appRequest to refMe's NSMutableURLRequest's requestWithURL:(ocidURL)
039#初期設定
040set ocidConf to (refMe's NSURLSessionConfiguration's defaultSessionConfiguration)
041#キュー
042set appQueue to (refMe's NSOperationQueue's mainQueue)
043#セッション
044set appSession to refMe's NSURLSession's sessionWithConfiguration:(ocidConf) delegate:("self") delegateQueue:(appQueue)
045#タスク
046#set appTask to appSession's dataTaskWithRequest:(appRequest)
047set appTask to appSession's dataTaskWithURL:(ocidURL) completionHandler:(missing value)
048#タスク 開始
049appTask's resume()
050#最大5秒のループ
051repeat 5 times
052   #タスクのステータス取得
053   set ocidStatue to appTask's state()
054   log ocidStatue as text
055   #実行中なら
056   if ocidStatue = (refMe's NSURLSessionTaskStateRunning as integer) then
057      #レスポンスの内容を取得して
058      set ocidResponse to appTask's response()
059      #まだ取得できない状態なら
060      if ocidResponse = (missing value) then
061         #1秒待つ
062         delay 1
063      else
064         #レスポンスが取得できたら
065         log ocidResponse's statusCode()
066         #クラスを確認(なければここでエラーになる)
067         log (ocidResponse's isKindOfClass:(refMe's NSHTTPURLResponse's |class|))
068         #リダイレクトされたURLを取得して
069         set ocidRedirectURL to ocidResponse's |URL|
070         exit repeat
071      end if
072   end if
073end repeat
074#タスクをキャンセル終了する
075appTask's cancel()
076#戻り値
077log ocidRedirectURL's absoluteString() as text
078#ダウンロードするファイル名
079set ocidFileName to ocidRedirectURL's lastPathComponent()
080
081##########################
082#NSDATA でダウンロード
083set ocidOption to (refMe's NSDataReadingMappedIfSafe)
084set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidRedirectURL) options:(ocidOption) |error|:(reference)
085if (item 2 of listResponse) = (missing value) then
086   log "正常処理"
087   set ocidSaveData to (item 1 of listResponse)
088else if (item 2 of listResponse) ≠ (missing value) then
089   log (item 2 of listResponse)'s code() as text
090   log (item 2 of listResponse)'s localizedDescription() as text
091   return "NSDATAエラーしました"
092end if
093
094##########################
095## ダウンロードするファイル
096##########################
097###テンポラリ
098set appFileManager to refMe's NSFileManager's defaultManager()
099set ocidTemporaryDirPathURL to appFileManager's temporaryDirectory
100###同一パスにならないようにUUIDを足す
101set ocidUUID to refMe's NSUUID's alloc()'s init()
102set coidUUID to ocidUUID's UUIDString()
103set ocidLocalUUIDPathURL to ocidTemporaryDirPathURL's URLByAppendingPathComponent:(coidUUID)
104set ocidMountPointPathURL to ocidLocalUUIDPathURL's URLByAppendingPathComponent:("Slack")
105set strMountPointPath to ocidMountPointPathURL's |path|() as text
106set ocidOrgFilePathURL to ocidMountPointPathURL's URLByAppendingPathComponent:("Slack.app")
107
108###DMG保存ディレクトリ
109set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
110ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
111appFileManager's createDirectoryAtURL:(ocidLocalUUIDPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
112###ファイル名を足してDMGの保存パス
113set ocidSaveFilePathURL to ocidLocalUUIDPathURL's URLByAppendingPathComponent:(ocidFileName)
114set strSaveFilePath to ocidSaveFilePathURL's |path|() as text
115
116##NSDATAで保存
117set ocidOption to (refMe's NSDataWritingAtomic)
118set listDone to ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
119if (item 1 of listDone) is true then
120   log "writeToURL 正常処理"
121else if (item 2 of listDone) ≠ (missing value) then
122   set strErrorNO to (item 2 of listDone)'s code() as text
123   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
124   refMe's NSLog("■" & strErrorNO & strErrorMes)
125   return "writeToURL エラーしました" & strErrorNO & strErrorMes
126end if
127##########################
128##古いバージョンをゴミ箱へ
129##########################
130set ocidAppPathURL to (missing value)
131set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
132if ocidAppBundle = (missing value) then
133   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
134   set ocidAppApthURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
135else
136   #バンドルで見つかる場合
137   set ocidAppApthURL to ocidAppBundle's bundleURL()
138end if
139
140if ocidAppPathURL = (missing value) then
141   try
142      tell application "Finder"
143         set aliasAppApth to (application file id strBundleID) as alias
144      end tell
145      set strAppApth to (POSIX path of aliasAppApth) as text
146      set ocidAppApthStr to refMe's NSString's stringWithString:(strAppApth)
147      set ocidAppApth to ocidAppApthStr's stringByStandardizingPath()
148      set ocidAppApthURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAppApth) isDirectory:(false)
149   end try
150end if
151#ゴミ箱へ入れる
152set appFileManager to refMe's NSFileManager's defaultManager()
153set listDone to (appFileManager's trashItemAtURL:(ocidAppApthURL) resultingItemURL:(ocidAppPathURL) |error|:(reference))
154if (item 2 of listDone) ≠ (missing value) then
155   set strErrorNO to (item 2 of listDone)'s code() as text
156   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
157   refMe's NSLog("■" & strErrorNO & strErrorMes)
158   log "エラーしました" & strErrorNO & strErrorMes
159end if
160
161##########################
162## 本処理
163##########################
164##appNSWorkspaceでドライブを表示しないマウント方法がわからない
165set theComandText to ("/usr/bin/hdiutil attach  \"" & strSaveFilePath & "\" -noverify -nobrowse -noautoopen -mountpoint \"" & strMountPointPath & "\"") as text
166
167log doZshShellScript(theComandText)
168
169##########################
170## インストール先
171##########################
172set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
173set ocidApplicationDirPathURL to ocidURLsArray's firstObject()
174set ocidDistDirPathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:("Groups") isDirectory:(true)
175#
176ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
177set listDone to appFileManager's createDirectoryAtURL:(ocidDistDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
178if (item 1 of listDone) is false then
179   set strErrorNO to (item 2 of listDone)'s code() as text
180   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
181   refMe's NSLog("■" & strErrorNO & strErrorMes)
182   log "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes
183   return false
184end if
185set ocidDistFilePathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:("Groups/Slack.app") isDirectory:(false)
186
187
188##############################
189## コピー
190set appFileManager to refMe's NSFileManager's defaultManager()
191set listDone to (appFileManager's copyItemAtURL:(ocidOrgFilePathURL) toURL:(ocidDistFilePathURL) |error|:(reference))
192
193##########################
194## キャッシュをゴミ箱へ
195##########################
196log doMoveToTrash("~/Library/Application Scripts/com.tinyspeck.slackmacgap")
197log doMoveToTrash("~/Library/Application Scripts/com.tinyspeck.slackmacgap.helper")
198
199log doMoveToTrash("~/Library/Application Support/Slack/Cache")
200log doMoveToTrash("~/Library/Application Support/Slack/Code Cache")
201log doMoveToTrash("~/Library/Application Support/Slack/Crashpad")
202log doMoveToTrash("~/Library/Application Support/Slack/DawnCache")
203log doMoveToTrash("~/Library/Application Support/Slack/GPUCache")
204log doMoveToTrash("~/Library/Application Support/Slack/IndexedDB")
205log doMoveToTrash("~/Library/Application Support/Slack/logs")
206log doMoveToTrash("~/Library/Application Support/Slack/Service Worker/CacheStorage")
207log doMoveToTrash("~/Library/Application Support/Slack/Service Worker/ScriptCache")
208
209log doMoveToTrash("~/Library/HTTPStorages/com.tinyspeck.slackmacgap")
210log doMoveToTrash("~/Library/HTTPStorages/com.tinyspeck.slackmacgap.helper")
211
212
213log doMoveToTrash("~/Library/Logs/Slack")
214log doMoveToTrash("~/Library/Logs/com.tinyspeck.slackmacgap")
215log doMoveToTrash("~/Library/Logs/com.tinyspeck.slackmacgap.helper")
216
217log doMoveToTrash("~/Library/Caches/Slack")
218log doMoveToTrash("~/Library/Caches/com.tinyspeck.slackmacgap")
219log doMoveToTrash("~/Library/Caches/com.tinyspeck.slackmacgap.helper")
220
221log doMoveToTrash("~/Library/Saved Application State/com.tinyspeck.slackmacgap.savedState")
222log doMoveToTrash("~/Library/Saved Application State/com.tinyspeck.slackmacgap.helper.savedState")
223
224log doMoveToTrash("~/Library/WebKit/com.tinyspeck.slackmacgap")
225log doMoveToTrash("~/Library/WebKit/com.tinyspeck.slackmacgap.helper")
226
227###################################
228########キャッシュNSTemporaryDirectory
229###################################
230### T
231set ocidTempDir to (refMe's NSTemporaryDirectory())
232set ocidTemporaryTPathURL to refMe's NSURL's fileURLWithPath:(ocidTempDir)
233log doMoveToTrash(ocidTemporaryTPathURL's URLByAppendingPathComponent:"com.tinyspeck.slackmacgap")
234log doMoveToTrash(ocidTemporaryTPathURL's URLByAppendingPathComponent:"com.tinyspeck.slackmacgap.helper")
235
236
237### 
238set ocidTempURL to ocidTemporaryTPathURL's URLByDeletingLastPathComponent()
239### C
240set ocidTemporaryCPathURL to ocidTempURL's URLByAppendingPathComponent:"C"
241log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.tinyspeck.slackmacgap")
242log doMoveToTrash(ocidTemporaryCPathURL's URLByAppendingPathComponent:"com.tinyspeck.slackmacgap.helper")
243
244
245
246
247##########################
248## アンマウント
249##########################
250set ocidDiskPathStr to refMe's NSString's stringWithString:(strMountPointPath)
251set ocidDiskPath to ocidDiskPathStr's stringByExpandingTildeInPath()
252set ocidDiskPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDiskPath) isDirectory:false)
253set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
254set listResponse to (appNSWorkspace's unmountAndEjectDeviceAtURL:(ocidDiskPathURL) |error|:(reference))
255try
256   if (item 1 of listResponse) is falset then
257      set theComandText to ("/usr/bin/hdiutil detach \"" & strMountPointPath & "\" -force") as text
258      log doZshShellScript(theComandText)
259   end if
260end try
261
262#インストール先を開く
263
264
265set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
266set boolDone to appSharedWorkspace's openURL:(ocidDistDirPathURL)
267
268#ダウンロードしたDMGもゴミ箱へ
269log doMoveToTrash(strSaveFilePath)
270
271
272##########################
273# NZSH 実行
274to doZshShellScript(argCommandText)
275   set strCommandText to argCommandText as text
276   log "コマンド開始\r" & strCommandText & "\r"
277   set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text
278   ##########
279   #コマンド実行
280   try
281      set strResnponse to (do shell script strExec) as text
282      log "コマンド終了"
283   on error
284      return false
285   end try
286   return strResnponse
287end doZshShellScript
288
289
290###################################
291########処理 ゴミ箱に入れる
292###################################
293
294to doMoveToTrash(argFilePath)
295   ###ファイルマネジャー初期化
296   set appFileManager to refMe's NSFileManager's defaultManager()
297   #########################################
298   ###渡された値のClassを調べてとりあえずNSURLにする
299   set refClass to class of argFilePath
300   if refClass is list then
301      return "エラー:リストは処理しません"
302   else if refClass is text then
303      log "テキストパスです"
304      set ocidArgFilePathStr to (refMe's NSString's stringWithString:argFilePath)
305      set ocidArgFilePath to ocidArgFilePathStr's stringByStandardizingPath
306      set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
307   else if refClass is alias then
308      log "エイリアスパスです"
309      set strArgFilePath to (POSIX path of argFilePath) as text
310      set ocidArgFilePathStr to (refMe's NSString's stringWithString:strArgFilePath)
311      set ocidArgFilePath to ocidArgFilePathStr's stringByStandardizingPath
312      set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
313   else
314      set refClass to (className() of argFilePath) as text
315      if refClass contains "NSPathStore2" then
316         log "NSPathStore2です"
317         set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:argFilePath)
318      else if refClass contains "NSCFString" then
319         log "NSCFStringです"
320         set ocidArgFilePath to argFilePath's stringByStandardizingPath
321         set ocidArgFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:ocidArgFilePath)
322      else if refClass contains "NSURL" then
323         set ocidArgFilePathURL to argFilePath
324         log "NSURLです"
325      end if
326   end if
327   #########################################
328   ###
329   -->false
330   set ocidFalse to (refMe's NSNumber's numberWithBool:false)'s boolValue
331   -->true
332   set ocidTrue to (refMe's NSNumber's numberWithBool:true)'s boolValue
333   #########################################
334   ###NSURLがエイリアス実在するか?
335   set ocidArgFilePath to ocidArgFilePathURL's |path|()
336   set boolFileAlias to appFileManager's fileExistsAtPath:(ocidArgFilePath)
337   ###パス先が実在しないなら処理はここまで
338   if boolFileAlias = false then
339      log ocidArgFilePath as text
340      log "処理中止 パス先が実在しない"
341      return false
342   end if
343   #########################################
344   ###NSURLがディレクトリなのか?ファイルなのか?
345   set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference)
346   #      log (item 1 of listBoolDir)
347   #      log (item 2 of listBoolDir)
348   #      log (item 3 of listBoolDir)
349   if (item 2 of listBoolDir) = ocidTrue then
350      #########################################
351      log "ディレクトリです"
352      log ocidArgFilePathURL's |path| as text
353      ##内包リスト
354      set listResult to appFileManager's contentsOfDirectoryAtURL:ocidArgFilePathURL includingPropertiesForKeys:{refMe's NSURLPathKey} options:0 |error|:(reference)
355      ###結果
356      set ocidContentsPathURLArray to item 1 of listResult
357      ###リストの数だけ繰り返し
358      repeat with itemContentsPathURL in ocidContentsPathURLArray
359         ###ゴミ箱に入れる
360         set listResult to (appFileManager's trashItemAtURL:itemContentsPathURL resultingItemURL:(missing value) |error|:(reference))
361      end repeat
362   else
363      #########################################
364      log "ファイルです"
365      set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsAliasFileKey) |error|:(reference)
366      if (item 2 of listBoolDir) = ocidTrue then
367         log "エイリアスは処理しません"
368         return false
369      end if
370      set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsSymbolicLinkKey) |error|:(reference)
371      if (item 2 of listBoolDir) = ocidTrue then
372         log "シンボリックリンクは処理しません"
373         return false
374      end if
375      set listBoolDir to ocidArgFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsSystemImmutableKey) |error|:(reference)
376      if (item 2 of listBoolDir) = ocidTrue then
377         log "システムファイルは処理しません"
378         return false
379      end if
380      ###ファイルをゴミ箱に入れる
381      set listResult to (appFileManager's trashItemAtURL:ocidArgFilePathURL resultingItemURL:(missing value) |error|:(reference))
382   end if
383   return true
384end doMoveToTrash
385
386###################################
387########アプリケーションを終了させる
388###################################
389to doQuitApp2UTI(argUTI)
390   set strUTI to argUTI as text
391   ### まずは普通に終了を試みる
392   tell application id strUTI to quit
393   delay 2
394   set ocidResultsArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:strUTI
395   set numCntArray to ocidResultsArray count
396   if numCntArray ≠ 0 then
397      set ocidRunApp to ocidResultsArray's objectAtIndex:0
398      
399      ###通常終了
400      set boolDone to ocidRunApp's terminate()
401      ####強制終了
402      set boolDone to ocidRunApp's forceTerminate()
403      
404      #### killallを使う場合
405      set ocidExecAppURL to ocidRunApp's executableURL()
406      set ocidFileName to ocidExecAppURL's lastPathComponent()
407      set strFileName to ocidFileName as text
408      
409      set strCommandText to ("/usr/bin/killall -z " & strFileName & "") as text
410      set ocidCommandText to refMe's NSString's stringWithString:strCommandText
411      set ocidTermTask to refMe's NSTask's alloc()'s init()
412      ocidTermTask's setLaunchPath:"/bin/zsh"
413      ocidTermTask's setArguments:({"-c", ocidCommandText})
414      set listDoneReturn to ocidTermTask's launchAndReturnError:(reference)
415      
416      
417      ####killを使う場合
418      set ocidPID to ocidRunApp's processIdentifier()
419      set strPID to ocidPID as text
420      log strPID
421      set strCommandText to ("/bin/kill -9 " & strPID & "") as text
422      set ocidCommandText to refMe's NSString's stringWithString:strCommandText
423      set ocidTermTask to refMe's NSTask's alloc()'s init()
424      ocidTermTask's setLaunchPath:"/bin/zsh"
425      ocidTermTask's setArguments:({"-c", ocidCommandText})
426      set listDoneReturn to ocidTermTask's launchAndReturnError:(reference)
427      
428      
429   end if
430end doQuitApp2UTI
431
AppleScriptで生成しました

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

001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004Slackの最新版のインストール
005インストール先は
006/Users/SOME_USER/Applications/Groups
007com.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
015property strBundleID : "com.tinyspeck.slackmacgap"
016
017##########################
018#URL
019set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
020ocidURLComponents's setScheme:("https")
021ocidURLComponents's setHost:("slack.com")
022ocidURLComponents's setPath:("/ssb/download-osx-silicon")
023set ocidURL to ocidURLComponents's |URL|()
024
025##########################
026#リダイレクト先の取得
027
028#リクエスト
029set appRequest to refMe's NSMutableURLRequest's requestWithURL:(ocidURL)
030#初期設定
031set ocidConf to (refMe's NSURLSessionConfiguration's defaultSessionConfiguration)
032#キュー
033set appQueue to (refMe's NSOperationQueue's mainQueue)
034#セッション
035set appSession to refMe's NSURLSession's sessionWithConfiguration:(ocidConf) delegate:("self") delegateQueue:(appQueue)
036#タスク
037#set appTask to appSession's dataTaskWithRequest:(appRequest)
038set appTask to appSession's dataTaskWithURL:(ocidURL) completionHandler:(missing value)
039#タスク 開始
040appTask's resume()
041#最大5秒のループ
042repeat 5 times
043   #タスクのステータス取得
044   set ocidStatue to appTask's state()
045   log ocidStatue as text
046   #実行中なら
047   if ocidStatue = (refMe's NSURLSessionTaskStateRunning as integer) then
048      #レスポンスの内容を取得して
049      set ocidResponse to appTask's response()
050      #まだ取得できない状態なら
051      if ocidResponse = (missing value) then
052         #1秒待つ
053         delay 1
054      else
055         #レスポンスが取得できたら
056         log ocidResponse's statusCode()
057         #クラスを確認(なければここでエラーになる)
058         log (ocidResponse's isKindOfClass:(refMe's NSHTTPURLResponse's |class|))
059         #リダイレクトされたURLを取得して
060         set ocidRedirectURL to ocidResponse's |URL|
061         exit repeat
062      end if
063   end if
064end repeat
065#タスクをキャンセル終了する
066appTask's cancel()
067#戻り値
068log ocidRedirectURL's absoluteString() as text
069#ダウンロードするファイル名
070set ocidFileName to ocidRedirectURL's lastPathComponent()
071
072##########################
073#NSDATA でダウンロード
074set ocidOption to (refMe's NSDataReadingMappedIfSafe)
075set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidRedirectURL) options:(ocidOption) |error|:(reference)
076if (item 2 of listResponse) = (missing value) then
077   log "正常処理"
078   set ocidSaveData to (item 1 of listResponse)
079else if (item 2 of listResponse) ≠ (missing value) then
080   log (item 2 of listResponse)'s code() as text
081   log (item 2 of listResponse)'s localizedDescription() as text
082   return "NSDATAエラーしました"
083end if
084
085##########################
086## ダウンロードするファイル
087##########################
088###テンポラリ
089set appFileManager to refMe's NSFileManager's defaultManager()
090set ocidTemporaryDirPathURL to appFileManager's temporaryDirectory
091###同一パスにならないようにUUIDを足す
092set ocidUUID to refMe's NSUUID's alloc()'s init()
093set coidUUID to ocidUUID's UUIDString()
094set ocidLocalUUIDPathURL to ocidTemporaryDirPathURL's URLByAppendingPathComponent:(coidUUID)
095set ocidMountPointPathURL to ocidLocalUUIDPathURL's URLByAppendingPathComponent:("Slack")
096set strMountPointPath to ocidMountPointPathURL's |path|() as text
097set ocidOrgFilePathURL to ocidMountPointPathURL's URLByAppendingPathComponent:("Slack.app")
098
099###DMG保存ディレクトリ
100set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
101ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
102appFileManager's createDirectoryAtURL:(ocidLocalUUIDPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
103###ファイル名を足してDMGの保存パス
104set ocidSaveFilePathURL to ocidLocalUUIDPathURL's URLByAppendingPathComponent:(ocidFileName)
105set strSaveFilePath to ocidSaveFilePathURL's |path|() as text
106
107##NSDATAで保存
108set ocidOption to (refMe's NSDataWritingAtomic)
109set listDone to ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
110if (item 1 of listDone) is true then
111   log "writeToURL 正常処理"
112else if (item 2 of listDone) ≠ (missing value) then
113   set strErrorNO to (item 2 of listDone)'s code() as text
114   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
115   refMe's NSLog("■" & strErrorNO & strErrorMes)
116   return "writeToURL エラーしました" & strErrorNO & strErrorMes
117end if
118##########################
119##古いバージョンをゴミ箱へ
120##########################
121set ocidAppPathURL to (missing value)
122set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
123if ocidAppBundle = (missing value) then
124   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
125   set ocidAppApthURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
126else
127   #バンドルで見つかる場合
128   set ocidAppApthURL to ocidAppBundle's bundleURL()
129end if
130
131if ocidAppPathURL = (missing value) then
132   try
133      tell application "Finder"
134         set aliasAppApth to (application file id strBundleID) as alias
135      end tell
136      set strAppApth to (POSIX path of aliasAppApth) as text
137      set ocidAppApthStr to refMe's NSString's stringWithString:(strAppApth)
138      set ocidAppApth to ocidAppApthStr's stringByStandardizingPath()
139      set ocidAppApthURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidAppApth) isDirectory:(false)
140   end try
141end if
142#ゴミ箱へ入れる
143set appFileManager to refMe's NSFileManager's defaultManager()
144set listDone to (appFileManager's trashItemAtURL:(ocidAppApthURL) resultingItemURL:(ocidAppPathURL) |error|:(reference))
145if (item 2 of listDone) ≠ (missing value) then
146   set strErrorNO to (item 2 of listDone)'s code() as text
147   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
148   refMe's NSLog("■" & strErrorNO & strErrorMes)
149   log "エラーしました" & strErrorNO & strErrorMes
150end if
151
152##########################
153## 本処理
154##########################
155##appNSWorkspaceでドライブを表示しないマウント方法がわからない
156set theComandText to ("/usr/bin/hdiutil attach  \"" & strSaveFilePath & "\" -noverify -nobrowse -noautoopen -mountpoint \"" & strMountPointPath & "\"") as text
157
158log doZshShellScript(theComandText)
159
160##########################
161## インストール先
162##########################
163set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
164set ocidApplicationDirPathURL to ocidURLsArray's firstObject()
165set ocidDistDirPathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:("Groups") isDirectory:(true)
166#
167ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
168set listDone to appFileManager's createDirectoryAtURL:(ocidDistDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
169if (item 1 of listDone) is false then
170   set strErrorNO to (item 2 of listDone)'s code() as text
171   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
172   refMe's NSLog("■" & strErrorNO & strErrorMes)
173   log "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes
174   return false
175end if
176set ocidDistFilePathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:("Groups/Slack.app") isDirectory:(false)
177
178
179##############################
180## コピー
181set appFileManager to refMe's NSFileManager's defaultManager()
182set listDone to (appFileManager's copyItemAtURL:(ocidOrgFilePathURL) toURL:(ocidDistFilePathURL) |error|:(reference))
183
184##########################
185## アンマウント
186##########################
187set ocidDiskPathStr to refMe's NSString's stringWithString:(strMountPointPath)
188set ocidDiskPath to ocidDiskPathStr's stringByExpandingTildeInPath()
189set ocidDiskPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDiskPath) isDirectory:false)
190set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
191set listResponse to (appNSWorkspace's unmountAndEjectDeviceAtURL:(ocidDiskPathURL) |error|:(reference))
192try
193   if (item 1 of listResponse) is falset then
194      set theComandText to ("/usr/bin/hdiutil detach \"" & strMountPointPath & "\" -force") as text
195      log doZshShellScript(theComandText)
196   end if
197end try
198
199#インストール先を開く
200
201set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
202set boolDone to appSharedWorkspace's openURL:(ocidDistDirPathURL)
203
204
205##########################
206# NZSH 実行
207to doZshShellScript(argCommandText)
208   set strCommandText to argCommandText as text
209   log "コマンド開始\r" & strCommandText & "\r"
210   set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text
211   ##########
212   #コマンド実行
213   try
214      set strResnponse to (do shell script strExec) as text
215      log "コマンド終了"
216   on error
217      return false
218   end try
219   return strResnponse
220end doZshShellScript

| | コメント (0)

[bash]Slackアップデート 少し修正


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#ユーザードメインにインストール

########################################
##実行パス
SCRIPT_PATH="${BASH_SOURCE[0]}"
/bin/echo "実行中のスクリプト"
/bin/echo "\"$SCRIPT_PATH\""

########################################
##ローカルにインストールされたものをゴミ箱に
CHK_APP_PATH="/Applications/Slack.app"
TRASH_DIR=$(/usr/bin/mktemp -d "$HOME/.Trash/SLACK.XXXXXXXX")
/bin/chmod 777 "$TRASH_DIR"
/bin/mv "$CHK_APP_PATH" "$TRASH_DIR"

if [ -e "$CHK_APP_PATH" ]; then
  /bin/echo "【エラー】$CHK_APP_PATHが存在します以下のコマンドをターミナルで実行してください"
  /bin/echo "/usr/bin/sudo /bin/mv \"/Applications/Slack.app\" \"$HOME/.Trash\""
  exit 1
fi

########################################
##OS
PLIST_PATH="/System/Library/CoreServices/SystemVersion.plist"
STR_OS_VER=$(/usr/bin/defaults read "$PLIST_PATH" ProductVersion)
/bin/echo "OS VERSION :" "$STR_OS_VER"
STR_MAJOR_VERSION="${STR_OS_VER%%.*}"
/bin/echo "STR_MAJOR_VERSION :" "$STR_MAJOR_VERSION"
STR_MINOR_VERSION="${STR_OS_VER#*.}"
/bin/echo "STR_MINOR_VERSION :" "$STR_MINOR_VERSION"

########################################
##ユーザー
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行したユーザーは:$USER_WHOAMI"
CURRENT_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
/bin/echo "実行ユーザー:" "$CURRENT_USER"

########################################
###ダウンロード起動時に削除する項目
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"

########################################
##デバイス
#起動ディスクの名前を取得する
/usr/bin/touch "$USER_TEMP_DIR/diskutil.plist"
/usr/sbin/diskutil info -plist / >"$USER_TEMP_DIR/diskutil.plist"
STARTUPDISK_NAME=$(/usr/bin/defaults read "$USER_TEMP_DIR/diskutil.plist" VolumeName)
/bin/echo "ボリューム名:" "$STARTUPDISK_NAME"

STR_DEVICE_UUID=$(/usr/sbin/ioreg -c IOPlatformExpertDevice | grep IOPlatformUUID | awk -F'"' '{print $4}')
/bin/echo "デバイスUUID: " "$STR_DEVICE_UUID"

############################################################
##基本メンテナンス
##ライブラリの不可視属性を解除
/usr/bin/chflags nohidden "/Users/$CURRENT_USER/Library"
/usr/bin/SetFile -a v "/Users/$CURRENT_USER/Library"
## Managed Itemsフォルダを作る
/bin/mkdir -p "/Users/$CURRENT_USER/Library/Managed Items"
/bin/chmod 755 "/Users/$CURRENT_USER/Library/Managed Items"
/usr/sbin/chown "$CURRENT_USER" "/Users/$CURRENT_USER/Library/Managed Items"
/usr/bin/touch "/Users/$CURRENT_USER/Library/Managed Items/.localized"

########################################
## HOME
########################################
## Developer
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Developer"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 700 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
## bin
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/bin"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 700 "$STR_CHECK_DIR_PATH"
##アクセス権チェック
/bin/chmod 700 "/Users/$CURRENT_USER/Library"
/bin/chmod 700 "/Users/$CURRENT_USER/Movies"
/bin/chmod 700 /"Users/$CURRENT_USER/Music"
/bin/chmod 700 "/Users/$CURRENT_USER/Pictures"
/bin/chmod 700 "/Users/$CURRENT_USER/Downloads"
/bin/chmod 700 "/Users/$CURRENT_USER/Documents"
/bin/chmod 700 "/Users/$CURRENT_USER/Desktop"
##全ローカルユーザーに対して実施したい処理があれば追加する
/bin/echo "ユーザーディレクトリチェックDONE"
########################################
## Public
########################################
/bin/chmod 755 "/Users/$CURRENT_USER/Public"
##
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Public/Drop Box"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 733 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
/usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
##########
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Public/Documents"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 700 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
/usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
##
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Public/Downloads"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 700 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
/usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
##
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Public/Favorites"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 700 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
/usr/bin/chgrp -Rf admin "$STR_CHECK_DIR_PATH"
##########
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Public/Groups"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 770 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
/usr/bin/chgrp -Rf staff "$STR_CHECK_DIR_PATH"
##
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Public/Shared"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 750 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
/usr/bin/chgrp -Rf staff "$STR_CHECK_DIR_PATH"
##########
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Public/Guest"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 777 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
/usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"
##
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Public/Shared Items"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 775 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
/usr/bin/chgrp -Rf nobody "$STR_CHECK_DIR_PATH"

########################################
## Applications
########################################
## Applications
STR_CHECK_DIR_PATH="/Users/$CURRENT_USER/Applications"
/bin/mkdir -p "$STR_CHECK_DIR_PATH"
/bin/chmod 700 "$STR_CHECK_DIR_PATH"
/usr/bin/touch "$STR_CHECK_DIR_PATH/.localized"
##サブフォルダを作る
LIST_SUB_DIR_NAME=("Demos" "Desktop" "Developer" "Documents" "Downloads" "Favorites" "Groups" "Library" "Movies" "Music" "Pictures" "Public" "Shared" "Sites" "System" "Users" "Utilities")
##リストの数だけ処理
for ITEM_DIR_NAME in "${LIST_SUB_DIR_NAME[@]}"; do
  /bin/mkdir -p "$STR_CHECK_DIR_PATH/${ITEM_DIR_NAME}"
  /bin/chmod 700 "$STR_CHECK_DIR_PATH/${ITEM_DIR_NAME}"
  /usr/bin/touch "$STR_CHECK_DIR_PATH/${ITEM_DIR_NAME}/.localized"
done
########################################
##シンボリックリンクを作る
if [[ ! -e "/Users/$CURRENT_USER/Applications/Applications" ]]; then
  /bin/ln -s "/Applications" "/Users/$CURRENT_USER/Applications/Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/Finder Applications" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Finder.app/Contents/Applications" "/Users/$CURRENT_USER/Applications/Utilities/Finder Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/Finder Libraries" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Finder.app/Contents/Resources/MyLibraries" "/Users/$CURRENT_USER/Applications/Utilities/Finder Libraries"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/System Applications" ]]; then
  /bin/ln -s "/System/Library/CoreServices/Applications" "/Users/$CURRENT_USER/Applications/Utilities/System Applications"
fi
if [[ ! -e "/Users/$CURRENT_USER/Applications/Utilities/System Utilities" ]]; then
  /bin/ln -s "/Applications/Utilities" "/Users/$CURRENT_USER/Applications/Utilities/System Utilities"
fi

########################################
###ダウンロード>>起動時に削除する項目
###CPUタイプでの分岐
ARCHITEC=$(/usr/bin/arch)
/bin/echo "Running on $ARCHITEC"
if [ "$ARCHITEC" == "arm64" ]; then
  ###ARM用のダウンロードURL
  STR_URL="https://slack.com/ssb/download-osx-silicon"
  ###ファイル名を取得
  DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
  /bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
  ###ダウンロード
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
    if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
      /bin/echo "ファイルのダウンロードに失敗しました"
      exit 1
    fi
  fi
else
  ###INTEL用のダウンロードURL
  STR_URL="https://slack.com/ssb/download-osx"
  ###ファイル名を取得
  DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
  /bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
  ###ダウンロード
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
    if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
      /bin/echo "ファイルのダウンロードに失敗しました"
      exit 1
    fi
  fi
fi
##全ユーザー実行可能にしておく
/bin/chmod 755 "$USER_TEMP_DIR/$DL_FILE_NAME"
/bin/echo "ダウンロードOK"

########################################
###アプリケーションの終了
###コンソールユーザーにのみ処理する
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "CONSOLE_USER:$CONSOLE_USER"
if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  #####OSAスクリプトはエラーすることも多い(初回インストール時はエラーになる)
  if ! /usr/bin/osascript -e "tell application id \"com.tinyspeck.slackmacgap\" to quit"; then
    ##念の為 KILLもする
    /usr/bin/killall "Slack" 2>/dev/null
    /usr/bin/killall "Slack Helper" 2>/dev/null
    /usr/bin/killall "Slack Helper (GPU)" 2>/dev/null
    /usr/bin/killall "Slack Helper (Renderer)" 2>/dev/null
  fi
fi
/bin/sleep 2
########################################
#####古いファイルをゴミ箱に USER
function DO_MOVE_TO_TRASH() {
  if [ -e "$1" ]; then
    TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$CURRENT_USER/.Trash/SLACK.XXXXXXXX")
    /bin/chmod 777 "$TRASH_DIR"
    /bin/mv "$1" "$TRASH_DIR"
  fi
}
#####古いファイルをゴミ箱に USER
DO_MOVE_TO_TRASH "/Applications/Slack.app"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Applications/Slack.app"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Applications/Groups/Slack.app"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/Cache"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/Code Cache"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/DawnCache"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/GPUCache"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/logs"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/IndexedDB"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/File System"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/Service Worker/CacheStorage"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/Service Worker/ScriptCache"

DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Caches/Slack"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Caches/com.tinyspeck.slackmacgap"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Caches/com.tinyspeck.slackmacgap.helper"

DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/HTTPStorages/com.tinyspeck.slackmacgap"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/HTTPStorages/com.tinyspeck.slackmacgap.binarycookies"

/bin/echo "ユーザーキャッシュ削除DONE"
############################################################
###/var/folde T
MKTEMP_DIR=$(/usr/bin/mktemp -d)
TEMP_DIR_T="$(/usr/bin/dirname "$MKTEMP_DIR")"
function DO_MOVE_TO_TRASH_T() {
  if [ -e "$1" ]; then
    TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$CURRENT_USER/.Trash/SLACK.T.XXXXXXXX")
    /bin/chmod 777 "$TRASH_DIR"
    /bin/mv "$1" "$TRASH_DIR"
  fi
}
#####古いファイルをゴミ箱に
DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/com.tinyspeck.slackmacgap"
DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/com.tinyspeck.slackmacgap.binarycookies"
/bin/echo "ユーザーキャッシュT DONE"
############################################################
###/var/folder C
TEMP_DIR="$(/usr/bin/dirname "$TEMP_DIR_T")"
TEMP_DIR_C="${TEMP_DIR}/C"
function DO_MOVE_TO_TRASH_C() {
  if [ -e "$1" ]; then
    TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$CURRENT_USER/.Trash/SLACK.C.XXXXXXXX")
    /bin/chmod 777 "$TRASH_DIR"
    /bin/mv "$1" "$TRASH_DIR"
  fi
}
#####古いファイルをゴミ箱に
DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.tinyspeck.slackmacgap"
DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.tinyspeck.slackmacgap.binarycookies"
/bin/echo "ユーザーキャッシュ C DONE"

############################################################
######### DITTOコピーインストール
/bin/echo "インストール開始:DITTO:" "$CURRENT_USER"
###ディスクをマウント
/usr/bin/hdiutil attach "$USER_TEMP_DIR/$DL_FILE_NAME" -noverify -nobrowse -noautoopen
sleep 2
####コピーして
/usr/bin/ditto "/Volumes/Slack/Slack.app" "/Users/$CURRENT_USER/Applications/Groups/Slack.app"
sleep 2
###ディスクをアンマウント
/usr/bin/hdiutil detach /Volumes/Slack -force

################################################
###設定項目
STR_BUNDLEID="com.tinyspeck.slackmacgap"
STR_APP_PATH="$HOME/Applications/Groups/Slack.app"
###アプリケーション名を取得
STR_APP_NAME=$(/usr/bin/defaults read "$STR_APP_PATH/Contents/Info.plist" CFBundleDisplayName)
if [ -z "$STR_APP_NAME" ]; then
  STR_APP_NAME=$(/usr/bin/defaults read "$STR_APP_PATH/Contents/Info.plist" CFBundleName)
fi
/bin/echo "アプリケーション名:$STR_APP_NAME"
################################################
### DOCKに登録済みかゴミ箱に入れる前に調べておく
##Dockの登録数を調べる
JSON_PERSISENT_APPS=$(/usr/bin/defaults read com.apple.dock persistent-apps)
NUN_CNT_ITEM=$(/bin/echo "$JSON_PERSISENT_APPS" | grep -o "tile-data" | wc -l)
/bin/echo "Dock登録数:$NUN_CNT_ITEM"
##Dockの登録数だけ繰り返し
NUM_CNT=0 #カウンタ初期化
NUM_POSITION="NULL" #ポジション番号にNULL文字を入れる
###対象のバンドルIDがDockに登録されているか順番に調べる
while [ $NUM_CNT -lt "$NUN_CNT_ITEM" ]; do
  ##順番にバンドルIDを取得して
  STR_CHK_BUNDLEID=$(/usr/libexec/PlistBuddy -c "Print:persistent-apps:$NUM_CNT:tile-data:bundle-identifier" "$HOME/Library/Preferences/com.apple.dock.plist")
  ##対象のバンドルIDだったら
  if [ "$STR_CHK_BUNDLEID" = "$STR_BUNDLEID" ]; then
    /bin/echo "DockのポジションNO: $NUM_CNT バンドルID:$STR_CHK_BUNDLEID"
    ##位置情報ポジションを記憶しておく
    NUM_POSITION=$NUM_CNT
  fi
  NUM_CNT=$((NUM_CNT + 1))
done

##結果 対象のバンドルIDが無ければ
if [ "$NUM_POSITION" = "NULL" ]; then
  /bin/echo "Dockに未登録です"
  PLIST_DICT="<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$STR_APP_PATH</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
  /usr/bin/defaults write com.apple.dock persistent-apps -array-add "$PLIST_DICT"
else
  ##すでに登録済みの場合は一旦削除
  /bin/echo "Dockの$NUM_POSITION に登録済み 削除してから同じ場所に登録しなおします"
  ##削除して
  /usr/libexec/PlistBuddy -c "Delete:persistent-apps:$NUM_POSITION" "$HOME/Library/Preferences/com.apple.dock.plist"
  ##保存
  /usr/libexec/PlistBuddy -c "Save" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###同じ内容を作成する
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:GUID integer $RANDOM$RANDOM" "$HOME/Library/Preferences/com.apple.dock.plist"
  ## 想定値 file-tile directory-tile
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-type string file-tile" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑この親Dictに子要素としてtile-dataをDictで追加
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑子要素のtile-dataにキーと値を入れていく
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:showas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
  ## 想定値 2:フォルダ 41:アプリケーション 169 Launchpad とMission Control
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-type integer 41" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:displayas integer 0" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:parent-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-mod-date integer $(date '+%s')" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-label string $STR_APP_NAME" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:is-beta bool false" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###↑この子要素のtile-dataに孫要素でfile-dataをDictで追加
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data dict" "$HOME/Library/Preferences/com.apple.dock.plist"
  ###値を入れていく
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data:_CFURLStringType integer 15" "$HOME/Library/Preferences/com.apple.dock.plist"
  /usr/libexec/PlistBuddy -c "add:persistent-apps:$NUM_POSITION:tile-data:file-data:_CFURLString string file://$STR_APP_PATH" "$HOME/Library/Preferences/com.apple.dock.plist"
  ##保存
  /usr/libexec/PlistBuddy -c "Save" "$HOME/Library/Preferences/com.apple.dock.plist"
fi
###
/bin/echo "処理終了 DOCKを再起動します"
/usr/bin/killall "Dock"

exit 0


|

[BASH]SLACKユーザーアップデート(カレントユーザーのみ)


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

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
########################################
##OS
PLIST_PATH="/System/Library/CoreServices/SystemVersion.plist"
STR_OS_VER=$(/usr/bin/defaults read "$PLIST_PATH" ProductVersion)
/bin/echo "OS VERSION :" "$STR_OS_VER"
STR_MAJOR_VERSION="${STR_OS_VER%%.*}"
/bin/echo "STR_MAJOR_VERSION :" "$STR_MAJOR_VERSION"
STR_MINOR_VERSION="${STR_OS_VER#*.}"
/bin/echo "STR_MINOR_VERSION :" "$STR_MINOR_VERSION"

########################################
##ユーザー
USER_WHOAMI=$(/usr/bin/whoami)
/bin/echo "実行したユーザーは:$USER_WHOAMI"
CURRENT_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
/bin/echo "実行ユーザー:" "$CURRENT_USER"

########################################
##デバイス
USER_TEMP_DIR=$(/usr/bin/mktemp -d)
/bin/echo "起動時に削除されるディレクトリ:" "$USER_TEMP_DIR"
#起動ディスクの名前を取得する
/usr/bin/touch "$USER_TEMP_DIR/diskutil.plist"
/usr/sbin/diskutil info -plist / >"$USER_TEMP_DIR/diskutil.plist"
STARTUPDISK_NAME=$(/usr/bin/defaults read "$USER_TEMP_DIR/diskutil.plist" VolumeName)
/bin/echo "ボリューム名:" "$STARTUPDISK_NAME"

########################################
###ダウンロード起動時に削除する項目

###CPUタイプでの分岐
ARCHITEC=$(/usr/bin/arch)
/bin/echo "Running on $ARCHITEC"
if [ "$ARCHITEC" == "arm64" ]; then
  ###ARM用のダウンロードURL
  STR_URL="https://slack.com/ssb/download-osx-silicon"
  ###ファイル名を取得
  DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
  /bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
  ###ダウンロード
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
    if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
      /bin/echo "ファイルのダウンロードに失敗しました"
      exit 1
    fi
  fi
else
  ###INTEL用のダウンロードURL
  STR_URL="https://slack.com/ssb/download-osx"
  ###ファイル名を取得
  DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
  /bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
  ###ダウンロード
  if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --connect-timeout 20; then
    /bin/echo "ファイルのダウンロードに失敗しました HTTP1.1で再トライします"
    if ! /usr/bin/curl -L -o "$USER_TEMP_DIR/$DL_FILE_NAME" "$STR_URL" --http1.1 --connect-timeout 20; then
      /bin/echo "ファイルのダウンロードに失敗しました"
      exit 1
    fi
  fi
fi
##全ユーザー実行可能にしておく
/bin/chmod 755 "$USER_TEMP_DIR/$DL_FILE_NAME"
/bin/echo "ダウンロードOK"

########################################
###アプリケーションの終了
###コンソールユーザーにのみ処理する
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "CONSOLE_USER:$CONSOLE_USER"
if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  #####OSAスクリプトはエラーすることも多い(初回インストール時はエラーになる)
  if ! /usr/bin/osascript -e "tell application id \"com.tinyspeck.slackmacgap\" to quit"; then
    ##念の為 KILLもする
    /usr/bin/killall "Slack" 2>/dev/null
    /usr/bin/killall "Slack Helper" 2>/dev/null
    /usr/bin/killall "Slack Helper (GPU)" 2>/dev/null
    /usr/bin/killall "Slack Helper (Renderer)" 2>/dev/null
  fi
fi
/bin/sleep 2

############################################################
##基本メンテナンス

##ライブラリの不可視属性を解除
/usr/bin/chflags nohidden "/Users/$CURRENT_USER/Library"
/usr/bin/SetFile -a v "/Users/$CURRENT_USER/Library"
##ユーザーアプリケーションフォルダを作る
/bin/mkdir -p "/Users/$CURRENT_USER/Applications"
/bin/chmod 700 "/Users/$CURRENT_USER/Applications"
/usr/sbin/chown "$CURRENT_USER" "/Users/$CURRENT_USER/Applications"
/usr/bin/touch "/Users/$CURRENT_USER/Applications/.localized"
##ユーザーユーティリティフォルダを作る
/bin/mkdir -p "/Users/$CURRENT_USER/Applications/Utilities"
/bin/chmod 755 "/Users/$CURRENT_USER/Applications/Utilities"
/usr/sbin/chown "$CURRENT_USER" "/Users/$CURRENT_USER/Applications/Utilities"
/usr/bin/touch "/Users/$CURRENT_USER/Applications/Utilities/.localized"
## Managed Itemsフォルダを作る
/bin/mkdir -p "/Users/$CURRENT_USER/Library/Managed Items"
/bin/chmod 755 "/Users/$CURRENT_USER/Library/Managed Items"
/usr/sbin/chown "$CURRENT_USER" "/Users/$CURRENT_USER/Library/Managed Items"
/usr/bin/touch "/Users/$CURRENT_USER/Library/Managed Items/.localized"
##アクセス権チェック
/bin/chmod 700 "/Users/$CURRENT_USER/Library"
/bin/chmod 700 "/Users/$CURRENT_USER/Movies"
/bin/chmod 700 /"Users/$CURRENT_USER/Music"
/bin/chmod 700 "/Users/$CURRENT_USER/Pictures"
/bin/chmod 700 "/Users/$CURRENT_USER/Downloads"
/bin/chmod 700 "/Users/$CURRENT_USER/Documents"
/bin/chmod 700 "/Users/$CURRENT_USER/Desktop"
##全ローカルユーザーに対して実施したい処理があれば追加する
/bin/echo "ユーザーディレクトリチェックDONE"

############################################################

#####古いファイルをゴミ箱に USER
function DO_MOVE_TO_TRASH() {
  if [ -e "$1" ]; then
    TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$CURRENT_USER/.Trash/SLACK.XXXXXXXX")
    /bin/chmod 777 "$TRASH_DIR"
    /bin/mv "$1" "$TRASH_DIR"
  fi
}
#####古いファイルをゴミ箱に USER
DO_MOVE_TO_TRASH "/Applications/Slack.app"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Applications/Slack.app"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/Cache"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/Code Cache"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/DawnCache"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/GPUCache"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/logs"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/IndexedDB"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/File System"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/Service Worker/CacheStorage"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Application Support/Slack/Service Worker/ScriptCache"

DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Caches/Slack"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Caches/com.tinyspeck.slackmacgap"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/Caches/com.tinyspeck.slackmacgap.helper"

DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/HTTPStorages/com.tinyspeck.slackmacgap"
DO_MOVE_TO_TRASH "/Users/$CURRENT_USER/Library/HTTPStorages/com.tinyspeck.slackmacgap.binarycookies"

/bin/echo "ユーザーキャッシュ削除DONE"
############################################################
###/var/folde T
MKTEMP_DIR=$(/usr/bin/mktemp -d)
TEMP_DIR_T="$(/usr/bin/dirname "$MKTEMP_DIR")"
function DO_MOVE_TO_TRASH_T() {
  if [ -e "$1" ]; then
    TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$CURRENT_USER/.Trash/SLACK.T.XXXXXXXX")
    /bin/chmod 777 "$TRASH_DIR"
    /bin/mv "$1" "$TRASH_DIR"
  fi
}
#####古いファイルをゴミ箱に
DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/com.tinyspeck.slackmacgap"
DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/com.tinyspeck.slackmacgap.binarycookies"
/bin/echo "ユーザーキャッシュT DONE"
############################################################
###/var/folder C
TEMP_DIR="$(/usr/bin/dirname "$TEMP_DIR_T")"
TEMP_DIR_C="${TEMP_DIR}/C"
function DO_MOVE_TO_TRASH_C() {
  if [ -e "$1" ]; then
    TRASH_DIR=$(/usr/bin/mktemp -d "/Users/$CURRENT_USER/.Trash/SLACK.C.XXXXXXXX")
    /bin/chmod 777 "$TRASH_DIR"
    /bin/mv "$1" "$TRASH_DIR"
  fi
}
#####古いファイルをゴミ箱に
DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.tinyspeck.slackmacgap"
DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.tinyspeck.slackmacgap.binarycookies"
/bin/echo "ユーザーキャッシュ C DONE"

############################################################
######### DITTOコピーインストール
/bin/echo "インストール開始:DITTO:" "$CURRENT_USER"
###ディスクをマウント
/usr/bin/hdiutil attach "$USER_TEMP_DIR/$DL_FILE_NAME" -noverify -nobrowse -noautoopen
sleep 2
####コピーして
/usr/bin/ditto "/Volumes/Slack/Slack.app" "/Users/$CURRENT_USER/Applications/Slack.app"
sleep 2
###ディスクをアンマウント
/usr/bin/hdiutil detach /Volumes/Slack -force
###Dockに追加して
/usr/bin/defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$HOME/Applications/Slack.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
###反映させて
/usr/bin/killall cfprefsd
###Dockを再起動
/usr/bin/killall Dock

exit 0


|

[URLForApplicationToOpenURL]デフォルトのブラウザ


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

###設定項目ドキュメントのURL
###(スキームだけでも取得できる)
set strScheme to "slack://"

###ワークスペース初期化
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
###NSURL
set ocidLocalHostURL to refMe's NSURL's URLWithString:(strScheme)
###URLタイプのデフォルトアプリケーション
set ocidAppPathURL to appShardWorkspace's URLForApplicationToOpenURL:(ocidLocalHostURL)
###アプリケーションの名前
set listResponse to (ocidAppPathURL's getResourceValue:(reference) forKey:(refMe's NSURLNameKey) |error|:(missing value))
set strAppName to (item 2 of listResponse) as text
log "デフォルトブラウザの名前は:" & strAppName & "です"
####パス
set aliasAppPath to ocidAppPathURL's absoluteURL() as alias
log "デフォルトブラウザのパスは:" & aliasAppPath & "です"
####バンドルID取得
set ocidAppBunndle to (refMe's NSBundle's bundleWithURL:(ocidAppPathURL))
set ocidBunndleID to ocidAppBunndle's bundleIdentifier
set strBundleID to ocidBunndleID as text
log "デフォルトブラウザのBunndleIDは:" & strBundleID & "です"




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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
error number -128
com.cocolog-nifty.quicktimer.icefloe
*)
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

###設定項目ドキュメントのURL
set strScheme to "http://localhost"

###ワークスペース初期化
set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
###NSURL
set ocidLocalHostURL to refMe's NSURL's URLWithString:(strScheme)
###URLタイプのデフォルトアプリケーション
set ocidAppPathURL to appShardWorkspace's URLForApplicationToOpenURL:(ocidLocalHostURL)
###アプリケーションの名前
set listResponse to (ocidAppPathURL's getResourceValue:(reference) forKey:(refMe's NSURLNameKey) |error|:(missing value))
set strAppName to (item 2 of listResponse) as text
log "デフォルトブラウザの名前は:" & strAppName & "です"
####パス
set aliasAppPath to ocidAppPathURL's absoluteURL() as alias
log "デフォルトブラウザのパスは:" & aliasAppPath & "です"
####バンドルID取得
set ocidAppBunndle to (refMe's NSBundle's bundleWithURL:(ocidAppPathURL))
set ocidBunndleID to ocidAppBunndle's bundleIdentifier
set strBundleID to ocidBunndleID as text
log "デフォルトブラウザのBunndleIDは:" & strBundleID & "です"



|

[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 で実行してください"
  exit 1
else
  ###実行しているユーザー名
  SUDO_USER=$(/bin/echo "$HOME" | /usr/bin/awk -F'/' '{print $NF}')
  /bin/echo "実行ユーザー:" "$SUDO_USER"
fi
########################################
###全ユーザーで使う起動時に削除する項目
/bin/mkdir -p "/private/tmp/TemporaryItems/Trash"
LOCAL_TMP_DIR=$(/usr/bin/mktemp -d "/private/tmp/TemporaryItems/XXXXXXXX")
/bin/chmod -Rf 777 "/private/tmp/TemporaryItems"
/bin/echo "LOCAL_TMP_DIR:CURL:" "$LOCAL_TMP_DIR"
###CPUタイプでの分岐
ARCHITEC=$(/usr/bin/arch)
/bin/echo "Running on $ARCHITEC"
if [ "$ARCHITEC" == "arm64" ]; then
  ###ARM用のダウンロードURL
  STR_URL="https://slack.com/ssb/download-osx-silicon"
  ###ファイル名を取得
  DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
  /bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
  ###ダウンロード
  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
  ###INTEL用のダウンロードURL
  STR_URL="https://slack.com/ssb/download-osx"
  ###ファイル名を取得
  DL_FILE_NAME=$(/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' "$STR_URL" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev)
  /bin/echo "DL_FILE_NAME:$DL_FILE_NAME"
  ###ダウンロード
  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
##全ユーザー実行可能にしておく
/bin/chmod 755 "$LOCAL_TMP_DIR/$DL_FILE_NAME"
/bin/echo "ダウンロードOK"

########################################
###アプリケーションの終了
###コンソールユーザーにのみ処理する
CONSOLE_USER=$(/bin/echo "show State:/Users/ConsoleUser" | /usr/sbin/scutil | /usr/bin/awk '/Name :/ { print $3 }')
/bin/echo "CONSOLE_USER:$CONSOLE_USER"
if [ -z "$CONSOLE_USER" ]; then
  /bin/echo "コンソールユーザーが無い=電源入れてログインウィンドウ状態"
else
  #####OSAスクリプトはエラーすることも多い(初回インストール時はエラーになる)
  if ! /usr/bin/sudo -u "$CONSOLE_USER" /usr/bin/osascript -e "tell application id \"com.tinyspeck.slackmacgap\" to quit"; then
    ##念の為 KILLもする
    /usr/bin/killall "Slack" 2>/dev/null
    /usr/bin/killall "Slack Helper" 2>/dev/null
    /usr/bin/killall "Slack Helper (GPU)" 2>/dev/null
    /usr/bin/killall "Slack Helper (Renderer)" 2>/dev/null
  fi
fi
/bin/sleep 2
############################################################
###ローカルのユーザーアカウントを取得
TEXT_RESULT=$(/usr/bin/dscl localhost -list /Local/Default/Users PrimaryGroupID | /usr/bin/awk '$2 == 20 { print $1 }')
###リストにする
read -d '\\n' -r -a LIST_USER <<<"$TEXT_RESULT"
###リスト内の項目数
NUM_CNT=${#LIST_USER[@]}
/bin/echo "ユーザー数:" "$NUM_CNT"

############################################################
##リストの内容を順番に処理
for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/echo "LIST_USER:MKDIR:" "${ITEM_LIST}"
  ##ライブラリの不可視属性を解除
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/chflags nohidden "/Users/${ITEM_LIST}/Library"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/SetFile -a v "/Users/${ITEM_LIST}/Library"
  ##ユーザーアプリケーションフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Applications"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Applications"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" "/Users/${ITEM_LIST}/Applications"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Applications/.localized"
  ##ユーザーユーティリティフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Applications/Utilities"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 755 "/Users/${ITEM_LIST}/Applications/Utilities"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" "/Users/${ITEM_LIST}/Applications/Utilities"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Applications/Utilities/.localized"
  ## Managed Itemsフォルダを作る
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/mkdir -p "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 755 "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/sbin/chown "${ITEM_LIST}" "/Users/${ITEM_LIST}/Library/Managed Items"
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/touch "/Users/${ITEM_LIST}/Library/Managed Items/.localized"
  ##アクセス権チェック
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Library"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Movies"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 /"Users/${ITEM_LIST}/Music"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Pictures"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Downloads"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Documents"
  /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 700 "/Users/${ITEM_LIST}/Desktop"
  ##全ローカルユーザーに対して実施したい処理があれば追加する
  /bin/echo "ユーザーディレクトリチェックDONE"
done
############################################################
for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/echo "LIST_USER:CLEAR:" "${ITEM_LIST}"
  #####古いファイルをゴミ箱に USER
  function DO_MOVE_TO_TRASH() {
    if [ -e "$1" ]; then
      TRASH_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d "/Users/${ITEM_LIST}/.Trash/XXXXXXXX")
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 777 "$TRASH_DIR"
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/mv "$1" "$TRASH_DIR"
    fi
}
  #####古いファイルをゴミ箱に USER
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Applications/Slack.app"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/Cache"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/Code Cache"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/DawnCache"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/GPUCache"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/logs"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/IndexedDB"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/File System"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/Service Worker/CacheStorage"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Application Support/Slack/Service Worker/ScriptCache"

  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Caches/Slack"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Caches/com.tinyspeck.slackmacgap"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/Caches/com.tinyspeck.slackmacgap.helper"

  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/HTTPStorages/com.tinyspeck.slackmacgap"
  DO_MOVE_TO_TRASH "/Users/${ITEM_LIST}/Library/HTTPStorages/com.tinyspeck.slackmacgap.binarycookies"

  /bin/echo "ユーザーキャッシュ削除DONE"
  ############################################################
  ###/var/folde T
  MKTEMP_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d)
  TEMP_DIR_T="$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/dirname "$MKTEMP_DIR")"
  function DO_MOVE_TO_TRASH_T() {
    if [ -e "$1" ]; then
      TRASH_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d "/Users/${ITEM_LIST}/.Trash/XXXXXXXX")
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 777 "$TRASH_DIR"
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/mv "$1" "$TRASH_DIR"
    fi
}
  #####古いファイルをゴミ箱に
  DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/com.tinyspeck.slackmacgap"
  DO_MOVE_TO_TRASH_T "$TEMP_DIR_T/com.tinyspeck.slackmacgap.binarycookies"
  /bin/echo "ユーザーキャッシュT DONE"
  ############################################################
  ###/var/folder C
  TEMP_DIR="$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/dirname "$TEMP_DIR_T")"
  TEMP_DIR_C="${TEMP_DIR}/C"
  function DO_MOVE_TO_TRASH_C() {
    if [ -e "$1" ]; then
      TRASH_DIR=$(/usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/mktemp -d "/Users/${ITEM_LIST}/.Trash/XXXXXXXX")
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/chmod 777 "$TRASH_DIR"
      /usr/bin/sudo -u "${ITEM_LIST}" /bin/mv "$1" "$TRASH_DIR"
    fi
}
  #####古いファイルをゴミ箱に
  DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.tinyspeck.slackmacgap"
  DO_MOVE_TO_TRASH_C "$TEMP_DIR_C/com.tinyspeck.slackmacgap.binarycookies"
  /bin/echo "ユーザーキャッシュ C DONE"
done

############################################################
#########
for ITEM_LIST in "${LIST_USER[@]}"; do
  /bin/echo "LIST_USER:DITTO:" "${ITEM_LIST}"
  ###ディスクをマウント
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/hdiutil attach "$LOCAL_TMP_DIR/$DL_FILE_NAME" -noverify -nobrowse -noautoopen
  sleep 2
  ####コピーして
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/ditto "/Volumes/Slack/Slack.app" "/Users/${ITEM_LIST}/Applications/Slack.app"
  sleep 2
  ###ディスクをアンマウント
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/hdiutil detach /Volumes/Slack -force
  ###Dockに追加して
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$HOME/Applications/Slack.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
  ###反映させて
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/killall cfprefsd
  ###Dockを再起動
  /usr/bin/sudo -u "${ITEM_LIST}" /usr/bin/killall Dock
done

############################################
###Applicationsにインストールされている場合
if [ -e "/Applications/Slack.app" ]; then
  /usr/bin/sudo /bin/chmod -Rf 777 "/Applications/Slack.app"
  TRASH_DIR=$(/usr/bin/sudo -u "$SUDO_USER" /usr/bin/mktemp -d "/Users/$SUDO_USER/.Trash/XXXXXXXX")
  /usr/bin/sudo -u "$SUDO_USER" /bin/chmod 777 "$TRASH_DIR"
  /usr/bin/sudo -u "$SUDO_USER" /bin/mv "/Applications/Slack.app" "$TRASH_DIR"
  /bin/echo "アプリケーション DONE"
fi

###TCC設定を行わない場合は削除して
/usr/bin/tccutil reset All com.tinyspeck.slackmacgap

exit 0

|

[admin]インストール済みアプリケーションのバージョンを求める


-->application file
####起動させないなら
tell application "Finder"
    set aliasAppPath to (application file id "com.tinyspeck.slackmacgap") as alias
end tell

tell application "Finder"
    set strAppPath to POSIX path of (application file id "com.tinyspeck.slackmacgap" as alias) as text
end tell

set strPlistPath to strAppPath & "Contents/Info.plist"
set strCommandText to "/usr/bin/defaults read \"" & strPlistPath & "\" CFBundleShortVersionString"
set strAppVer to do shell script strCommandText

log strAppVer
-->    (*4.29.149*)


use framework "Foundation"
use scripting additions


property refMe : a reference to current application

set strUTI to "com.google.Chrome" as text


tell application "Finder"
    set fileAppPath to application file id strUTI
    set aliasAppPath to fileAppPath as alias
    set strAppPath to POSIX path of aliasAppPath as text
end tell

set ocidAppBundle to refMe's NSBundle's bundleWithPath:strAppPath
set ocidAppName to ocidAppBundle's objectForInfoDictionaryKey:"CFBundleDisplayName"
log ocidAppName as text
-->(*Google Chrome*)


set ocidAppVer to ocidAppBundle's objectForInfoDictionaryKey:"CFBundleShortVersionString"
log ocidAppVer as text
-->(*110.0.5481.177*)

|

[AppleScript]com.apple.TCC.configuration-profile-policyの作成補助

com.apple.TCC.configuration-profile-policyの
↓この部分を作成します

                        <dict>

                            <key>Allowed</key>

                            <true/>

                            <key>Identifier</key>

                            <string>com.tinyspeck.slackmacgap</string>

                            <key>IdentifierType</key>

                            <string>bundleID</string>

                            <key>Comment</key>

                            <string>Services com.tinyspeck.slackmacgap</string>

                            <key>CodeRequirement</key>

                            <string>identifier "com.tinyspeck.slackmacgap" and anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.OU] = BQR82RBBHL</string>

                        </dict>


ダウンロード - coderequirement.scpt.zip


#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# 
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7


use framework "Foundation"
use AppleScript version "2.4"
use scripting additions
property objMe : a reference to current application
property objNSString : a reference to objMe's NSString


set aliasFile to (choose file with prompt "Appを選んでください" default location (path to applications folder from user domain) of type {"com.apple.application-bundle"} with invisibles without showing package contents and multiple selections allowed) as alias

tell application "Finder"

set objInfo to info for aliasFile
set strAppPath to POSIX path of aliasFile

set strUTI to bundle identifier of objInfo

end tell
set objCapText to objNSString's stringWithString:strUTI
set strCapText to (objCapText's lowercaseString()) as string

set strcodesign to (do shell script "codesign -dr - \"" & strAppPath & "\"") as text
set strcodesign to doReplace(strcodesign, "designated => ", "")
set strcodesign to doReplace(strcodesign, "(", "")
set strcodesign to doReplace(strcodesign, ")", "")


##set strTCC to "<dict>\n<key>Allowed</key><true/>\n<key>Identifier</key>\n<string>" & strCapText & "</string>\n<key>IdentifierType</key>\n<string>bundleID</string>\n<key>Comment</key>\n<string>Services " & strCapText & "</string>\n<key>CodeRequirement</key>\n<string>" & strcodesign & "</string>\n<key>StaticCode</key>\n<false/>\n</dict>\n"


set strTCC to "<dict>\n<key>Allowed</key><true/>\n<key>Identifier</key>\n<string>" & strCapText & "</string>\n<key>IdentifierType</key>\n<string>bundleID</string>\n<key>Comment</key>\n<string>Services " & strCapText & "</string>\n<key>CodeRequirement</key>\n<string>" & strcodesign & "</string>\n</dict>\n"

set the clipboard to strTCC as text

to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace

|

[TCC]ユーザーTCC.dbの値の操作(リセット)bash版

[TCC]ユーザーTCC.dbの値の操作(リセット)
https://quicktimer.cocolog-nifty.com/icefloe/2022/03/post-927f65.html
こちらの記事のbash版


#!/bin/bash



###ここだけ設定項目

strAppPath="$HOME/Applications/Slack.app"


########

strUTI=""

#strUTI=`/usr/bin/defaults read  "${strAppPath}/Contents/Info.plist"  CFBundleIdentifier`

strCommandText="/usr/bin/defaults read  \"${strAppPath}/Contents/Info.plist\"  CFBundleIdentifier"

echo $strCommandText

strUTI=`eval "$strCommandText"`

echo $strUTI

########

/usr/bin/osascript <<END

tell application id  "$strUTI" to quit

END



########対象アプリが起動中の場合の終了処理

strCommandText="echo ${strAppPath##*/}"

strBaseName=`eval $strCommandText`

strCommandText="echo ${strBaseName%.*}"

strBaseName=`eval $strCommandText`

strCommandText="/usr/bin/killall \"${strBaseName}\""

eval $strCommandText


########本処理

##ユーザードメインのTCCdbのパス

strTCCdbPath="$HOME/Library/Application Support/com.apple.TCC/TCC.db"

##サービス一覧を収納

listService=("kTCCServiceSystemPolicySysAdminFiles" "kTCCServiceAccessibility" "kTCCServiceSystemPolicyAllFiles" "kTCCServiceScreenCapture" "kTCCServicePostEvent" "kTCCServiceAppleEvents" "kTCCServiceAccessibility" "kTCCServiceScreenCapture" "kTCCServicePostEvent" "kTCCServiceAccessibility" "kTCCServiceCamera" "kTCCServiceMicrophone" "kTCCServiceScreenCapture"  "kTCCServiceSystemPolicyAllFiles" "kTCCServiceAddressBook" "kTCCServiceContactsLimited" "kTCCServiceContactsFull" "kTCCServiceCalendar" "kTCCServiceReminders" "kTCCServiceTwitter" "kTCCServiceFacebook" "kTCCServiceSinaWeibo" "kTCCServiceTencentWeibo" "kTCCServiceShareKit" "kTCCServiceLiverpool" "kTCCServiceUbiquity" "kTCCServicePhotos" "kTCCServicePhotosAdd" "kTCCServiceCamera" "kTCCServiceMicrophone" "kTCCServiceWillow" "kTCCServiceMediaLibrary" "kTCCServiceSiri" "kTCCServiceMotion" "kTCCServiceSpeechRecognition" "kTCCServiceUserTracking" "kTCCServiceBluetoothAlways" "kTCCServiceWebKitIntelligentTrackingPrevention" "kTCCServicePrototype3Rights" "kTCCServicePrototype4Rights" "kTCCServiceGameCenterFriends" "kTCCServiceBluetoothPeripheral" "kTCCServiceBluetoothWhileInUse" "kTCCServiceKeyboardNetwork" "kTCCServiceMSO" "kTCCServiceCalls" "kTCCServiceFaceID" "kTCCServiceExposureNotificationRegion" "kTCCServiceFallDetection" "kTCCServiceNearbyInteraction" "kTCCServiceFocusStatus" "kTCCServiceUserAvailability" "kTCCServiceLinkedIn" "kTCCServiceListenEvent" "kTCCServiceSystemPolicyDeveloperFiles" "kTCCServiceDeveloperTool" "kTCCServiceFileProviderPresence" "kTCCServiceFileProviderDomain" "kTCCServiceSystemPolicyRemovableVolumes" "kTCCServiceSystemPolicyNetworkVolumes" "kTCCServiceSystemPolicyDesktopFolder" "kTCCServiceSystemPolicyDownloadsFolder" "kTCCServiceSystemPolicyDocumentsFolder")

#######

for (( i = 0; i < ${#listService[@]}; ++i )); do

logCommand=`/usr/bin/tccutil reset ${listService[$i]/kTCCService/} ${strUTI}`

echo $logCommand

done



exit

ダウンロード - tccutilreset.sh.zip

|

[com.tinyspeck.slackmacgap]UTIからアプリケーションのインストール先を求める


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

UTIからアプリケーションのインストール先を求める .scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004
005v1 初回作成
006v1.1 いちおうダメ元でFinderにも問い合わせように変更
007
008com.cocolog-nifty.quicktimer.icefloe *)
009----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
010use AppleScript version "2.8"
011use framework "Foundation"
012use framework "AppKit"
013use framework "UniformTypeIdentifiers"
014use scripting additions
015
016
017property refMe : a reference to current application
018
019###対象のアプリケーションのUTI
020set strUTI to ("com.tinyspeck.slackmacgap") as text
021
022#NSBundle
023#UTIからアプリケーションのインストール先を求める
024set ocidAppBundle to refMe's NSBundle's bundleWithIdentifier:(strUTI)
025#NSバンドルが取得できない場合は
026if ocidAppBundle = (missing value) then
027   #NSWorkspaceで調べる
028   set appNSWorkspace to refMe's NSWorkspace's sharedWorkspace()
029   set ocidAppPathURL to appNSWorkspace's URLForApplicationWithBundleIdentifier:(strUTI)
030else
031   #バンドル取得できなたらそのままNSBundle
032   set ocidAppBundleStr to ocidAppBundle's bundlePath()
033   set ocidAppBundlePath to ocidAppBundleStr's stringByStandardizingPath()
034   set ocidAppPathURL to refMe's NSURL's fileURLWithPath:(ocidAppBundlePath)
035end if
036if ocidAppPathURL = (missing value) then
037   tell application "Finder"
038      try
039         set aliasAppPath to (application file id argBundleID) as alias
040         set strAppPath to (POSIX path of aliasAppPath) as text
041         set ocidAppPathStr to refMe's NSString's stringWithString:(strAppPath)
042         set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
043         set ocidAppPathURL to refMe's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false)
044      on error strErrMes number numErrNo
045         return "アプリケーションが見つかりませんでした"
046      end try
047   end tell
048else
049   log ocidAppPathURL as alias
050   return ocidAppPathURL as alias
051end if
AppleScriptで生成しました

| | コメント (0)

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom