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