20260518

[Applescript]Chromium Browser ダウンロード

[Applescript]Chromium Browser ダウンロードスクリプト

NOTE記事一覧ですnote.com
 

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

Chromiumダウンロード.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
004(*
005
006Woolyss ChromiumでビルドされたARM用のChromiumブラウザを
007ダウンロード
008解凍
009拡張属性削除
010ユーザーアプリケーションフォルダへ移動までします
011
012v1 初回作成
013v2 Branch Base Position番号を自動取得するように変更
014
015Branch Base Position番号の取得方法はこちらを参考にした
016https://github.com/mloporchio/chromium-downloader-script
017
018
019com.cocolog-nifty.quicktimer.icefloe *)
020----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
021use AppleScript version "2.8"
022use framework "Foundation"
023use framework "AppKit"
024use framework "UniformTypeIdentifiers"
025use scripting additions
026
027property refMe : a reference to current application
028
029#ポジションを取得
030set strURL to ("https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/LAST_CHANGE") as text
031set ocidURLString to refMe's NSString's stringWithString:(strURL)
032set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
033
034set listReadStrings to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
035set strPos to (first item of listReadStrings) as text
036
037#ダウンロードURLにして
038set strURL to ("https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac_Arm/") as text
039set ocidURLString to refMe's NSString's stringWithString:(strURL)
040set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
041
042set ocidURL to ocidURL's URLByAppendingPathComponent:(strPos) isDirectory:(true)
043set ocidURL to ocidURL's URLByAppendingPathComponent:("chrome-mac.zip") isDirectory:(false)
044
045
046#NSDATA ダウンロード
047set ocidOption to (refMe's NSDataReadingMappedIfSafe)
048set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference)
049if (item 2 of listResponse) = (missing value) then
050   log "initWithContentsOfURL 正常処理"
051   set ocidReadData to (item 1 of listResponse)
052else if (item 2 of listResponse) ≠ (missing value) then
053   set strErrorNO to (item 2 of listResponse)'s code() as text
054   set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
055   refMe's NSLog("■:" & strErrorNO & strErrorMes)
056   return "initWithContentsOfURL エラーしました" & strErrorNO & strErrorMes
057end if
058
059#ディレクトリ テンポラリー(起動時に自動削除される)
060set appFileManager to refMe's NSFileManager's defaultManager()
061set ocidTempDirURL to appFileManager's temporaryDirectory()
062set ocidUUID to refMe's NSUUID's alloc()'s init()
063set ocidUUIDString to ocidUUID's UUIDString
064set ocidUUIDDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
065#テンポラリーZIPをダウンロードして保存するフォルダ
066set appFileManager to refMe's NSFileManager's defaultManager()
067set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init()
068ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
069set listDone to appFileManager's createDirectoryAtURL:(ocidUUIDDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
070if (item 1 of listDone) is false then
071   set strErrorNO to (item 2 of listDone)'s code() as text
072   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
073   refMe's NSLog("■:" & strErrorNO & strErrorMes)
074   log "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes
075   return false
076end if
077
078###パス
079set strFileName to "chrome-mac.zip" as text
080set ocidSaveFilePathURL to ocidUUIDDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
081
082#NSDATA
083set ocidOption to (refMe's NSDataWritingAtomic)
084set listDone to ocidReadData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)
085if (item 1 of listDone) is true then
086   log "writeToURL 正常処理"
087else if (item 2 of listDone) ≠ (missing value) then
088   set strErrorNO to (item 2 of listDone)'s code() as text
089   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
090   refMe's NSLog("■:" & strErrorNO & strErrorMes)
091   log ocidSaveFilePathURL's |path|() as text
092   return "writeToURL エラーしました" & strErrorNO & strErrorMes
093end if
094
095#アプリケーションフォルダ内Sitesに展開
096set appFileManager to refMe's NSFileManager's defaultManager()
097set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationDirectory) inDomains:(refMe's NSUserDomainMask))
098set ocidApplicationDirPathURL to ocidURLsArray's firstObject()
099set ocidSaveDirPathURL to ocidApplicationDirPathURL's URLByAppendingPathComponent:("Sites") isDirectory:(true)
100set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
101if (item 1 of listDone) is false then
102   set strErrorNO to (item 2 of listDone)'s code() as text
103   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
104   refMe's NSLog("■:" & strErrorNO & strErrorMes)
105   log "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes
106   return false
107end if
108
109#コマンド用のパス
110set ocidSaveFilePath to ocidSaveFilePathURL's |path|()
111set ocidUUIDDirPath to ocidUUIDDirPathURL's |path|()
112
113#解凍
114set strCmd to ("/usr/bin/ditto -xk \"" & ocidSaveFilePath & "\" \"" & ocidUUIDDirPath & "\"")
115do shell script strCmd
116#拡張属性を削除
117set strCmd to ("/usr/bin/xattr -c \"" & ocidUUIDDirPath & "\"")
118do shell script strCmd
119
120#解凍されて 拡張属性を削除されたアプリケーション
121set ocidExtractAppPathURL to ocidUUIDDirPathURL's URLByAppendingPathComponent:("chrome-mac/Chromium.app") isDirectory:(true)
122
123#インストール先
124set ocidSaveAppPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Chromium.app") isDirectory:(true)
125
126#古いバージョンはゴミ箱へ
127set appFileManager to refMe's NSFileManager's defaultManager()
128set listDone to (appFileManager's trashItemAtURL:(ocidSaveAppPathURL) resultingItemURL:(ocidSaveAppPathURL) |error|:(reference))
129
130#解凍ファイルをアプリケーションフォルダへ
131set appFileManager to refMe's NSFileManager's defaultManager()
132set listDone to (appFileManager's moveItemAtURL:(ocidExtractAppPathURL) toURL:(ocidSaveAppPathURL) |error|:(reference))
133
134
135#ダウンロードZIPファイルはゴミ箱へ
136set appFileManager to refMe's NSFileManager's defaultManager()
137set listDone to (appFileManager's trashItemAtURL:(ocidUUIDDirPathURL) resultingItemURL:(ocidUUIDDirPathURL) |error|:(reference))
138if (item 2 of listDone) ≠ (missing value) then
139   set strErrorNO to (item 2 of listDone)'s code() as text
140   set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
141   refMe's NSLog("■:" & strErrorNO & strErrorMes)
142   return "エラーしました" & strErrorNO & strErrorMes
143end if
144
145
146#ダウンロード先を開く
147set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
148set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
149set appFinderArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:("com.apple.finder")
150set appFinder to appFinderArray's firstObject()
151set boolDone to appFinder's activateWithOptions:(refMe's NSApplicationActivateIgnoringOtherApps)
152
153
154return boolDone
AppleScriptで生成しました