VMware Workstation 最新版ダウンローダー (ダウンロードするのはWINDOW用のファイルです)
WINDOWS用のソフトをダウンロードするためのスクリプトです
MacOS版のVMware Fusionのダウンロードスクリプトはこちら
VMware Fusion 最新版ダウンローダー (URL追加 ARM版 とインテル版で選べるようにした)
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | (* |
004 | com.cocolog-nifty.quicktimer.icefloe |
005 | VMware Workstation最新版をダウンロード |
006 | VMware WorkstationはWindows用のアプリケーションです |
007 | MacOSでは、そのままでは起動出来ません |
008 | *) |
009 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
010 | use AppleScript version "2.8" |
011 | use framework "Foundation" |
012 | use framework "AppKit" |
013 | use scripting additions |
014 | property refMe : a reference to current application |
015 | |
016 | ### 【1】XMLのURL |
017 | #サイトURL |
018 | set strSiteURL to ("https://softwareupdate.vmware.com/cds/vmw-desktop/") as text |
019 | set ocidSiteURL to refMe's NSURL's alloc()'s initWithString:(strSiteURL) |
020 | #XMLのURL |
021 | #設定項目 |
022 | #インテル用 |
023 | set strURL to ("https://softwareupdate.vmware.com/cds/vmw-desktop/ws-windows.xml") as text |
024 | |
025 | |
026 | #NSURLにして |
027 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(strURL) |
028 | ### 【2】XML読み込み |
029 | set ocidOption to (refMe's NSXMLDocumentTidyXML) |
030 | set listResponse to refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error| :(reference) |
031 | if (item 2 of listResponse) = (missing value) then |
032 | set ocidReadXMLDoc to (item 1 of listResponse) |
033 | else if (item 2 of listResponse) ≠ (missing value) then |
034 | set strErrorNO to (item 2 of listResponse)'s code() as text |
035 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
036 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
037 | log "エラーしました" & strErrorNO & strErrorMes |
038 | set ocidReadXMLDoc to (item 1 of listResponse) |
039 | end if |
040 | #格納用のARRAY |
041 | set ocidXMLURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
042 | ###【3】XMLから必要なデータを取得 |
043 | #【3-1】:ROOT |
044 | set ocidRootElement to ocidReadXMLDoc's rootElement() |
045 | #【3-2】:metadata |
046 | ##metadataを要素として取得してから処理する |
047 | set ocidElementArray to ocidRootElement's elementsForName:("metadata") |
048 | repeat with itemElement in ocidElementArray |
049 | set ocidUrlPath to (itemElement's elementsForName:("url"))'s firstObject() |
050 | set ocidSitePath to ocidUrlPath's stringValue() |
051 | set ocidItemURL to (ocidSiteURL's URLByAppendingPathComponent:(ocidSitePath) isDirectory:(false)) |
052 | set ocidItemURLstring to ocidItemURL's absoluteString() as text |
053 | (ocidXMLURLArrayM's addObject:(ocidItemURLstring)) |
054 | end repeat |
055 | ##### |
056 | #取り出したURLのARRAYを |
057 | #coreとpackagesで分割する |
058 | set appPredicateForCore to refMe's NSPredicate's predicateWithFormat_("SELF CONTAINS %@", "core") |
059 | set appPredicateForPackages to refMe's NSPredicate's predicateWithFormat_("SELF CONTAINS %@", "packages") |
060 | # |
061 | set ocidSubarrayCore to ocidXMLURLArrayM's filteredArrayUsingPredicate:(appPredicateForCore) |
062 | set ocidSubarrayPackages to ocidXMLURLArrayM's filteredArrayUsingPredicate:(appPredicateForPackages) |
063 | ##Arrayをソート |
064 | set ocidSortedSubarrayCore to ocidSubarrayCore's sortedArrayUsingSelector:("localizedStandardCompare:") |
065 | set ocidSortedSubarrayPackages to ocidSubarrayPackages's sortedArrayUsingSelector:("localizedStandardCompare:") |
066 | #バージョン数のもっとも大きい数字が最新だから |
067 | set ocidCoreFileString to ocidSortedSubarrayCore's lastObject() |
068 | log ocidCoreFileString's |path| as text |
069 | # |
070 | set ocidPackagesFileString to ocidSortedSubarrayPackages's lastObject() |
071 | log ocidPackagesFileString's |path| as text |
072 | #最新版のXMLのURL |
073 | set ocidCoreFileURL to refMe's NSURL's alloc()'s initWithString:(ocidCoreFileString) |
074 | set ocidPackagesFileURL to refMe's NSURL's alloc()'s initWithString:(ocidPackagesFileString) |
075 | |
076 | ################################ |
077 | #XMLのファイル名 Packages |
078 | set ocidFileName to ocidPackagesFileURL's lastPathComponent() |
079 | #NSDATAに読み込む |
080 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
081 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPackagesFileURL) options:(ocidOption) |error| :(reference) |
082 | if (item 2 of listResponse) = (missing value) then |
083 | set ocidGzFileData to (item 1 of listResponse) |
084 | else if (item 2 of listResponse) ≠ (missing value) then |
085 | set strErrorNO to (item 2 of listResponse)'s code() as text |
086 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
087 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
088 | return "エラーしました" & strErrorNO & strErrorMes |
089 | end if |
090 | ##保存 |
091 | #テンポラリに保存 |
092 | set appFileManager to refMe's NSFileManager's defaultManager() |
093 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
094 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
095 | set ocidUUIDString to ocidUUID's UUIDString |
096 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true) |
097 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
098 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
099 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
100 | if (item 1 of listDone) is true then |
101 | #パスを整形しておく |
102 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false) |
103 | set ocidExtractXMLFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("metadata.xml") isDirectory:(false) |
104 | ##NSDataで保存 |
105 | set ocidOption to (refMe's NSDataWritingAtomic) |
106 | set listDone to ocidGzFileData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference) |
107 | if (item 1 of listDone) is true then |
108 | log "正常処理" |
109 | else if (item 2 of listDone) ≠ (missing value) then |
110 | set strErrorNO to (item 2 of listDone)'s code() as text |
111 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
112 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
113 | return "エラーしました" & strErrorNO & strErrorMes |
114 | end if |
115 | set strSaveFilePath to ocidSaveFilePathURL's |path|() as text |
116 | else if (item 2 of listDone) ≠ (missing value) then |
117 | set strErrorNO to (item 2 of listDone)'s code() as text |
118 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
119 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
120 | return "エラーしました" & strErrorNO & strErrorMes |
121 | end if |
122 | #保存したファイルを解凍して |
123 | set strCommandText to ("/bin/zsh -c '/usr/bin/gzip -d \"" & strSaveFilePath & "\"'") as text |
124 | log strCommandText |
125 | try |
126 | do shell script strCommandText |
127 | on error |
128 | return "gzipでエラーになりました" |
129 | end try |
130 | |
131 | ###### |
132 | #解凍したXMLを読み込む |
133 | set ocidOption to (refMe's NSXMLDocumentTidyXML) |
134 | set listResponse to refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidExtractXMLFilePathURL) options:(ocidOption) |error| :(reference) |
135 | if (item 2 of listResponse) = (missing value) then |
136 | set ocidReadXMLDoc to (item 1 of listResponse) |
137 | else if (item 2 of listResponse) ≠ (missing value) then |
138 | set strErrorNO to (item 2 of listResponse)'s code() as text |
139 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
140 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
141 | log "エラーしました" & strErrorNO & strErrorMes |
142 | set ocidReadXMLDoc to (item 1 of listResponse) |
143 | end if |
144 | #ビルド番号 |
145 | set ocidRootElement to ocidReadXMLDoc's rootElement() |
146 | # set listResponse to (ocidRootElement's nodesForXPath:("//productList/product/buildNumber") |error| :(reference)) |
147 | set listResponse to (ocidRootElement's nodesForXPath:("//visibleTo/product/buildNumber") |error| :(reference)) |
148 | set ocidBuildNumber to (item 1 of listResponse)'s firstObject() |
149 | set ocidBuldName to ocidBuildNumber's stringValue() |
150 | #バージョン |
151 | set listResponse to (ocidRootElement's nodesForXPath:("//visibleTo/product/version") |error| :(reference)) |
152 | set ocidVersionNumber to (item 1 of listResponse)'s firstObject() |
153 | set ocidVersionName to ocidVersionNumber's stringValue() as text |
154 | #ファイル名 |
155 | set listResponse to (ocidRootElement's nodesForXPath:("//componentList/component/relativePath") |error| :(reference)) |
156 | set ocidRelativePath to (item 1 of listResponse)'s firstObject() |
157 | set ocidTarFileName to ocidRelativePath's stringValue() as text |
158 | #パスを繋げてURLにして |
159 | set strSetPath to ("/cds/vmw-desktop/ws/" & ocidVersionName & "/" & ocidBuldName & "/windows/packages/" & ocidTarFileName) as text |
160 | set ocidURLComponents to refMe's NSURLComponents's alloc()'s init() |
161 | ocidURLComponents's setScheme:("https") |
162 | ocidURLComponents's setHost:("softwareupdate.vmware.com") |
163 | ocidURLComponents's setPath:(strSetPath) |
164 | set ocidTarURL to ocidURLComponents's |URL|() |
165 | |
166 | |
167 | #NSDATAに読み込む ダウンロード |
168 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
169 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidTarURL) options:(ocidOption) |error| :(reference) |
170 | if (item 2 of listResponse) = (missing value) then |
171 | set ocidSetImageData to (item 1 of listResponse) |
172 | else if (item 2 of listResponse) ≠ (missing value) then |
173 | set strErrorNO to (item 2 of listResponse)'s code() as text |
174 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
175 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
176 | return "エラーしました" & strErrorNO & strErrorMes |
177 | end if |
178 | #ダウンロードフォルダに指定のファイル名で |
179 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask)) |
180 | set ocidDownloadsDirPathURL to ocidURLsArray's firstObject() |
181 | set ocidSaveFilePathURL to ocidDownloadsDirPathURL's URLByAppendingPathComponent:(ocidTarFileName) isDirectory:false |
182 | #保存 |
183 | set ocidOption to (refMe's NSDataWritingAtomic) |
184 | set listDone to ocidSetImageData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference) |
185 | if (item 1 of listDone) is true then |
186 | log "正常終了" |
187 | else if (item 1 of listDone) is false then |
188 | log (item 2 of listDone)'s localizedDescription() as text |
189 | return "保存に失敗しました" |
190 | end if |
191 | |
192 | |
193 | |
194 | ################################ |
195 | #XMLのファイル名 Core |
196 | set ocidFileName to ocidCoreFileURL's lastPathComponent() |
197 | #NSDATAに読み込む |
198 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
199 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidCoreFileURL) options:(ocidOption) |error| :(reference) |
200 | if (item 2 of listResponse) = (missing value) then |
201 | set ocidGzFileData to (item 1 of listResponse) |
202 | else if (item 2 of listResponse) ≠ (missing value) then |
203 | set strErrorNO to (item 2 of listResponse)'s code() as text |
204 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
205 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
206 | return "エラーしました" & strErrorNO & strErrorMes |
207 | end if |
208 | ##保存 |
209 | #テンポラリに保存 |
210 | set appFileManager to refMe's NSFileManager's defaultManager() |
211 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
212 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
213 | set ocidUUIDString to ocidUUID's UUIDString |
214 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true) |
215 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
216 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
217 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
218 | if (item 1 of listDone) is true then |
219 | #パスを整形しておく |
220 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false) |
221 | set ocidExtractXMLFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("metadata.xml") isDirectory:(false) |
222 | ##NSDataで保存 |
223 | set ocidOption to (refMe's NSDataWritingAtomic) |
224 | set listDone to ocidGzFileData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference) |
225 | if (item 1 of listDone) is true then |
226 | log "正常処理" |
227 | else if (item 2 of listDone) ≠ (missing value) then |
228 | set strErrorNO to (item 2 of listDone)'s code() as text |
229 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
230 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
231 | return "エラーしました" & strErrorNO & strErrorMes |
232 | end if |
233 | set strSaveFilePath to ocidSaveFilePathURL's |path|() as text |
234 | else if (item 2 of listDone) ≠ (missing value) then |
235 | set strErrorNO to (item 2 of listDone)'s code() as text |
236 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
237 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
238 | return "エラーしました" & strErrorNO & strErrorMes |
239 | end if |
240 | #保存したファイルを解凍して |
241 | set strCommandText to ("/bin/zsh -c '/usr/bin/gzip -d \"" & strSaveFilePath & "\"'") as text |
242 | log strCommandText |
243 | try |
244 | do shell script strCommandText |
245 | on error |
246 | return "gzipでエラーになりました" |
247 | end try |
248 | |
249 | ###### |
250 | #解凍したXMLを読み込む |
251 | set ocidOption to (refMe's NSXMLDocumentTidyXML) |
252 | set listResponse to refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidExtractXMLFilePathURL) options:(ocidOption) |error| :(reference) |
253 | if (item 2 of listResponse) = (missing value) then |
254 | set ocidReadXMLDoc to (item 1 of listResponse) |
255 | else if (item 2 of listResponse) ≠ (missing value) then |
256 | set strErrorNO to (item 2 of listResponse)'s code() as text |
257 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
258 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
259 | log "エラーしました" & strErrorNO & strErrorMes |
260 | set ocidReadXMLDoc to (item 1 of listResponse) |
261 | end if |
262 | #ビルド番号 |
263 | set ocidRootElement to ocidReadXMLDoc's rootElement() |
264 | set listResponse to (ocidRootElement's nodesForXPath:("//productList/product/buildNumber") |error| :(reference)) |
265 | set ocidBuildNumber to (item 1 of listResponse)'s firstObject() |
266 | set ocidBuldName to ocidBuildNumber's stringValue() |
267 | #バージョン |
268 | set listResponse to (ocidRootElement's nodesForXPath:("//productList/product/version") |error| :(reference)) |
269 | set ocidVersionNumber to (item 1 of listResponse)'s firstObject() |
270 | set ocidVersionName to ocidVersionNumber's stringValue() as text |
271 | #ファイル名 |
272 | set listResponse to (ocidRootElement's nodesForXPath:("//componentList/component/relativePath") |error| :(reference)) |
273 | set ocidRelativePath to (item 1 of listResponse)'s firstObject() |
274 | set ocidTarFileName to ocidRelativePath's stringValue() as text |
275 | #パスを繋げてURLにして |
276 | set strSetPath to ("/cds/vmw-desktop/ws/" & ocidVersionName & "/" & ocidBuldName & "/windows/core/" & ocidTarFileName) as text |
277 | set ocidURLComponents to refMe's NSURLComponents's alloc()'s init() |
278 | ocidURLComponents's setScheme:("https") |
279 | ocidURLComponents's setHost:("softwareupdate.vmware.com") |
280 | ocidURLComponents's setPath:(strSetPath) |
281 | set ocidTarURL to ocidURLComponents's |URL|() |
282 | log ocidTarURL's absoluteString() as text |
283 | |
284 | |
285 | #NSDATAに読み込む ダウンロード |
286 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
287 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidTarURL) options:(ocidOption) |error| :(reference) |
288 | if (item 2 of listResponse) = (missing value) then |
289 | set ocidSetImageData to (item 1 of listResponse) |
290 | else if (item 2 of listResponse) ≠ (missing value) then |
291 | set strErrorNO to (item 2 of listResponse)'s code() as text |
292 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
293 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
294 | return "エラーしました" & strErrorNO & strErrorMes |
295 | end if |
296 | #ダウンロードフォルダに指定のファイル名で |
297 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask)) |
298 | set ocidDownloadsDirPathURL to ocidURLsArray's firstObject() |
299 | set ocidSaveFilePathURL to ocidDownloadsDirPathURL's URLByAppendingPathComponent:(ocidTarFileName) isDirectory:false |
300 | #保存 |
301 | set ocidOption to (refMe's NSDataWritingAtomic) |
302 | set listDone to ocidSetImageData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference) |
303 | if (item 1 of listDone) is true then |
304 | log "正常終了" |
305 | else if (item 1 of listDone) is false then |
306 | log (item 2 of listDone)'s localizedDescription() as text |
307 | return "保存に失敗しました" |
308 | end if |
309 | #保存先を開く |
310 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
311 | set boolDone to appSharedWorkspace's openURL:(ocidDownloadsDirPathURL) |
312 | |
313 | |
314 | return "終了" |
AppleScriptで生成しました |
| 固定リンク