[Acrobat]ARMDCアップデート
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | (* |
004 | 【1】最新版のARMDCのバージョン |
005 | 【2】インストール済みのARMDCのバージョン |
006 | 【3】最新のマニフェストのダウンロード解凍 |
007 | 【4】マニフェストからPKGのURLを取得 |
008 | 【5】pkgのダウンロード |
009 | 【6】pkgのインストール(要管理者権限) |
010 | |
011 | *) |
012 | # com.cocolog-nifty.quicktimer.icefloe |
013 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
014 | use AppleScript version "2.8" |
015 | use framework "Foundation" |
016 | use framework "AppKit" |
017 | use framework "UniformTypeIdentifiers" |
018 | use scripting additions |
019 | |
020 | property refMe : a reference to current application |
021 | |
022 | |
023 | set strCurrentVerURL to ("https://armmf.adobe.com/arm-manifests/mac/ARMDC/current_version.txt") as text |
024 | |
025 | set strHelperManifestsURL to ("https://armmf.adobe.com/arm-manifests/mac/ARMDC/ARMDCHelperManifest.arm") as text |
026 | ###PKG |
027 | #拡張子はarmだけど中身はPKG |
028 | #2015 1 . 0 . 14 |
029 | set strContent1URL to ("https://armmf.adobe.com/arm-manifests/mac/ARMDC/RMPackage/univ/ARMDCContents.arm") as text |
030 | #2017 1 . 1 . 1 |
031 | set strContent2URL to ("https://armmf.adobe.com/arm-manifests/mac/ARMDC/RMPackage/univ/ARMDCContents2.arm") as text |
032 | #2018 1 . 1 . 7 |
033 | set strContent3URL to ("https://armmf.adobe.com/arm-manifests/mac/ARMDC/RMPackage/univ/ARMDCContents3.arm") as text |
034 | #最新 1 . 2 . 6 |
035 | set strContent4URL to ("https://armmf.adobe.com/arm-manifests/mac/ARMDC/RMPackage/univ/ARMDCContents4.arm") as text |
036 | |
037 | #Installer |
038 | set strAgentInstallerURL to ("https://armmf.adobe.com/arm-updates/mac/ARMDC/ARM_update/ARMDCAgentInstaller.pkg") as text |
039 | |
040 | |
041 | ######################### |
042 | #【1】最新版のARMDCのバージョン |
043 | #current_version.txtの取得 |
044 | set ocidCurrentVerURLStr to refMe's NSString's stringWithString:(strCurrentVerURL) |
045 | set ocidCurrentVerURL to refMe's NSURL's alloc()'s initWithString:(ocidCurrentVerURLStr) |
046 | # |
047 | set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidCurrentVerURL) encoding:(refMe's NSASCIIStringEncoding) |error| :(reference) |
048 | set ocidCurrentVer to (item 1 of listResponse) |
049 | #初回アクセス時に値を取れないことがあるので保険で3回 |
050 | if ocidCurrentVer = (missing value) then |
051 | repeat 3 times |
052 | set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidCurrentVerURL) encoding:(refMe's NSASCIIStringEncoding) |error| :(reference) |
053 | delay 0.5 |
054 | end repeat |
055 | set ocidCurrentVer to (item 1 of listResponse) |
056 | end if |
057 | if ocidCurrentVer = (missing value) then |
058 | return "バージョン取得に失敗しました" |
059 | end if |
060 | log "current_version.txt: " & ocidCurrentVer as text |
061 | |
062 | |
063 | ######################### |
064 | #【2】インストール済みのARMDCのバージョン |
065 | #バージョンチェック用 |
066 | set strRegPlistFilePath to ("/Library/Application Support/Adobe/ARMDC/Registered Products/com.adobe.ARMDCHelper.plist") |
067 | set ocidRegPlistFilePathStr to refMe's NSString's stringWithString:(strRegPlistFilePath) |
068 | set ocidRegPlistFilePath to ocidRegPlistFilePathStr's stringByStandardizingPath() |
069 | set ocidRegPlistFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidRegPlistFilePath) isDirectory:(false) |
070 | #Registered Productsのplistを読み取り |
071 | set listResponse to refMe's NSDictionary's dictionaryWithContentsOfURL:(ocidRegPlistFilePathURL) |error| :(reference) |
072 | if (item 2 of listResponse) = (missing value) then |
073 | log "dictionaryWithContentsOfURL 正常処理" |
074 | set ocidPlistDict to (item 1 of listResponse) |
075 | else if (item 2 of listResponse) ≠ (missing value) then |
076 | set strErrorNO to (item 2 of listDone)'s code() as text |
077 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
078 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
079 | return "エラーしました" & strErrorNO & strErrorMes |
080 | end if |
081 | |
082 | set ocidVerUrlDict to ocidPlistDict's objectForKey:("VersionFileURL") |
083 | set ocidBaseURL to ocidVerUrlDict's valueForKey:("httpsURLBase") |
084 | set ocidPathURL to ocidVerUrlDict's valueForKey:("URL") |
085 | #URLに |
086 | set ocidBaseVerURL to refMe's NSURL's alloc()'s initWithString:(ocidBaseURL) |
087 | set ocidVerURL to ocidBaseVerURL's URLByAppendingPathComponent:(ocidPathURL) |
088 | set strVerURL to ocidVerURL's absoluteString() as text |
089 | #インストール済みのパス |
090 | set ocidHelperPathArray to ocidPlistDict's objectForKey:("Version") |
091 | set ocidHelperPathStr to ocidHelperPathArray's firstObject() |
092 | set ocidHelperPath to ocidHelperPathStr's stringByStandardizingPath() |
093 | set ocidHelperPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidHelperPath) isDirectory:(false) |
094 | #インストール済みののplistを読み取り |
095 | set listResponse to refMe's NSDictionary's dictionaryWithContentsOfURL:(ocidHelperPathURL) |error| :(reference) |
096 | if (item 2 of listResponse) = (missing value) then |
097 | log "dictionaryWithContentsOfURL 正常処理" |
098 | set ocidPlistDict to (item 1 of listResponse) |
099 | else if (item 2 of listResponse) ≠ (missing value) then |
100 | set strErrorNO to (item 2 of listDone)'s code() as text |
101 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
102 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
103 | return "エラーしました" & strErrorNO & strErrorMes |
104 | end if |
105 | |
106 | set ocidInstallVerStr to ocidPlistDict's valueForKey:("CFBundleVersion") |
107 | set ocidInstallVerStr to (ocidInstallVerStr's stringByReplacingOccurrencesOfString:(" ") withString:("")) |
108 | log "CFBundleVersion: " & ocidInstallVerStr as text |
109 | #バージョン比較 |
110 | set boolSame to (ocidCurrentVer's isEqualToString:(ocidInstallVerStr)) as boolean |
111 | if boolSame is true then |
112 | return "バージョン同じ=最新なので処理する必要がない" |
113 | end if |
114 | |
115 | |
116 | ######################### |
117 | #【3】最新のマニフェストのダウンロード解凍 |
118 | #Manifestダウンロード |
119 | set ocidHelperManifestsURLStr to refMe's NSString's stringWithString:(strHelperManifestsURL) |
120 | set ocidHelperManifestsURL to refMe's NSURL's alloc()'s initWithString:(ocidHelperManifestsURLStr) |
121 | #テンポラリ |
122 | set appFileManager to refMe's NSFileManager's defaultManager() |
123 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
124 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
125 | set ocidUUIDString to ocidUUID's UUIDString |
126 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true) |
127 | set appFileManager to refMe's NSFileManager's defaultManager() |
128 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
129 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
130 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference) |
131 | if (item 1 of listDone) is true then |
132 | log "createDirectoryAtURL 正常処理" |
133 | else if (item 2 of listDone) ≠ (missing value) then |
134 | set strErrorNO to (item 2 of listDone)'s code() as text |
135 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
136 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
137 | return "エラーしました" & strErrorNO & strErrorMes |
138 | end if |
139 | ###パス |
140 | set strSaveFileName to "ARMDCHelperManifest.pkg" as text |
141 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
142 | ##NSDATAに読み込む |
143 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
144 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidHelperManifestsURL) options:(ocidOption) |error| :(reference) |
145 | if (item 2 of listResponse) = (missing value) then |
146 | log "initWithContentsOfURL 正常処理" |
147 | set ocidReadData to (item 1 of listResponse) |
148 | else if (item 2 of listResponse) ≠ (missing value) then |
149 | set strErrorNO to (item 2 of listResponse)'s code() as text |
150 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
151 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
152 | return "エラーしました" & strErrorNO & strErrorMes |
153 | end if |
154 | ##NSDataで保存 |
155 | set ocidOption to (refMe's NSDataWritingAtomic) |
156 | set listDone to ocidReadData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference) |
157 | if (item 1 of listDone) is true then |
158 | log "ocidSaveFilePathURL 正常処理" |
159 | else if (item 2 of listDone) ≠ (missing value) then |
160 | set strErrorNO to (item 2 of listDone)'s code() as text |
161 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
162 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
163 | return "エラーしました" & strErrorNO & strErrorMes |
164 | end if |
165 | ##解凍ファイル |
166 | set strSaveFilePath to ocidSaveFilePathURL's |path|() as text |
167 | ##解凍先 |
168 | set ocidExpandDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Expand") isDirectory:(true) |
169 | set strExpandDirPath to ocidExpandDirPathURL's |path|() as text |
170 | #コマンド実行 |
171 | set strComandText to "/usr/sbin/pkgutil --expand-full \"" & strSaveFilePath & "\" \"" & strExpandDirPath & "\"" as text |
172 | log "\r" & strComandText & "\r" |
173 | set strExec to ("/bin/zsh -c '" & strComandText & "'") |
174 | try |
175 | do shell script strExec |
176 | on error |
177 | return "do shell scriptでエラーしました" |
178 | end try |
179 | |
180 | ############################## |
181 | #XML読み込み |
182 | set ocidManifestFilePathURL to ocidExpandDirPathURL's URLByAppendingPathComponent:("ASSET/ARMDCHelperManifest.xml") isDirectory:(false) |
183 | #NSDATAに読み込み |
184 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
185 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidManifestFilePathURL) options:(ocidOption) |error| :(reference) |
186 | if (item 2 of listResponse) = (missing value) then |
187 | log "initWithContentsOfURL 正常処理" |
188 | set ocidReadData to (item 1 of listResponse) |
189 | else if (item 2 of listResponse) ≠ (missing value) then |
190 | log (item 2 of listResponse)'s code() as text |
191 | log (item 2 of listResponse)'s localizedDescription() as text |
192 | return "initWithContentsOfURL エラーしました" |
193 | end if |
194 | ############################## |
195 | #XMLに読み込む |
196 | set ocidOption to (refMe's NSXMLNodePreserveAll) + (refMe's NSXMLDocumentTidyXML) |
197 | set listResponse to refMe's NSXMLDocument's alloc()'s initWithData:(ocidReadData) options:(ocidOption) |error| :(reference) |
198 | if (item 2 of listResponse) = (missing value) then |
199 | log "initWithData 正常処理" |
200 | set ocidXMLDoc to (item 1 of listResponse) |
201 | else if (item 2 of listResponse) ≠ (missing value) then |
202 | log (item 2 of listResponse)'s code() as text |
203 | log (item 2 of listResponse)'s localizedDescription() as text |
204 | log "initWithData エラー 警告がありました" |
205 | set ocidXMLDoc to (item 1 of listResponse) |
206 | end if |
207 | ############################## |
208 | #XML解析 |
209 | #ROOT |
210 | set ocidRootElement to ocidXMLDoc's rootElement() |
211 | set ocidActionItemsArray to ocidRootElement's elementsForName:("DownloadActionItems") |
212 | set ocidActionItems to ocidActionItemsArray's firstObject() |
213 | set ocidDItemArray to (ocidActionItems's elementsForName:("dItem")) |
214 | set ocidDItem to ocidDItemArray's firstObject() |
215 | set ocidHttpURLBase to (ocidDItem's attributeForName:("httpURLBase"))'s stringValue() |
216 | set ocidURLPath to (ocidDItem's attributeForName:("URL"))'s stringValue() |
217 | set ocidURLFileName to (ocidDItem's attributeForName:("fileName"))'s stringValue() |
218 | # |
219 | set ocidBaseAgentInstallerURL to refMe's NSURL's alloc()'s initWithString:(ocidHttpURLBase) |
220 | set ocidBaseDirAgentInstallerURL to ocidBaseAgentInstallerURL's URLByAppendingPathComponent:(ocidURLPath) |
221 | set ocidAgentInstallerURL to ocidBaseDirAgentInstallerURL's URLByAppendingPathComponent:(ocidURLFileName) |
222 | set strAgentInstallerURL to ocidAgentInstallerURL's absoluteString() as text |
223 | |
224 | ############################## |
225 | #【5】pkgのダウンロード |
226 | set ocidSavePkgFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidURLFileName) isDirectory:(false) |
227 | #NSDATAに読み込み |
228 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
229 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidAgentInstallerURL) options:(ocidOption) |error| :(reference) |
230 | if (item 2 of listResponse) = (missing value) then |
231 | log "initWithContentsOfURL 正常処理" |
232 | set ocidReadData to (item 1 of listResponse) |
233 | else if (item 2 of listResponse) ≠ (missing value) then |
234 | log (item 2 of listResponse)'s code() as text |
235 | log (item 2 of listResponse)'s localizedDescription() as text |
236 | return "initWithContentsOfURL エラーしました" |
237 | end if |
238 | ##NSDataで保存 |
239 | set ocidOption to (refMe's NSDataWritingAtomic) |
240 | set listDone to ocidReadData's writeToURL:(ocidSavePkgFilePathURL) options:(ocidOption) |error| :(reference) |
241 | if (item 1 of listDone) is true then |
242 | log "ocidSaveFilePathURL 正常処理" |
243 | else if (item 2 of listDone) ≠ (missing value) then |
244 | set strErrorNO to (item 2 of listDone)'s code() as text |
245 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
246 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
247 | return "エラーしました" & strErrorNO & strErrorMes |
248 | end if |
249 | |
250 | set strPkgFilePath to ocidSavePkgFilePathURL's |path|() as text |
251 | #コマンド実行 |
252 | set strCommandText to ("/usr/bin/sudo /usr/sbin/installer -pkg \"" & strPkgFilePath & "\" -target / -dumplog -allowUntrusted -lang ja") as text |
253 | log "\r" & strCommandText & "\r" |
254 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") |
255 | try |
256 | do shell script strExec |
257 | on error |
258 | return "do shell scriptでエラーしました" |
259 | end try |
260 | |
261 | |
262 | return 0 |
AppleScriptで生成しました |
| 固定リンク