[セキュリティ]各種情報 バージョン取得 v2 (TCC_Compatibility廃止対応)
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | #com.cocolog-nifty.quicktimer.icefloe |
004 | # 各種情報を収集HTML表示 |
005 | # 計画性なく作ったV1 |
006 | # SequoiaでTCC_Compatibility Bundleが廃止になったのに対応 |
007 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
008 | use AppleScript version "2.8" |
009 | use framework "Foundation" |
010 | use framework "AppKit" |
011 | use scripting additions |
012 | |
013 | property refMe : a reference to current application |
014 | |
015 | |
016 | ########################################## |
017 | #【1】コンピューター名 |
018 | set appFileManager to refMe's NSFileManager's defaultManager() |
019 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask)) |
020 | set ocidLibraryDirPathURL to ocidURLsArray's firstObject() |
021 | set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/SystemConfiguration/preferences.plist") isDirectory:(false) |
022 | # |
023 | set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error| :(reference) |
024 | if (item 2 of listResponse) = (missing value) then |
025 | log "正常処理" |
026 | set ocidPlistDict to (item 1 of listResponse) |
027 | else if (item 2 of listResponse) ≠ (missing value) then |
028 | log (item 2 of listResponse)'s code() as text |
029 | log (item 2 of listResponse)'s localizedDescription() as text |
030 | log "エラーしました" |
031 | return false |
032 | end if |
033 | set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/SystemConfiguration/com.apple.smb.server.plist") isDirectory:(false) |
034 | # |
035 | set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error| :(reference) |
036 | if (item 2 of listResponse) = (missing value) then |
037 | log "正常処理" |
038 | set ocidPlistDictSMB to (item 1 of listResponse) |
039 | else if (item 2 of listResponse) ≠ (missing value) then |
040 | log (item 2 of listResponse)'s code() as text |
041 | log (item 2 of listResponse)'s localizedDescription() as text |
042 | log "エラーしました" |
043 | return false |
044 | end if |
045 | (* この方法だとBonjourとSMB名が取れないので使わない |
046 | set recordSystemInfo to (system info) as record |
047 | ###MacOS用 |
048 | set strComputerName to (computer name of recordSystemInfo) as text |
049 | ###/bin/hostname と同等 |
050 | set strHostName to (host name of recordSystemInfo) as text |
051 | *) |
052 | ###Bonjourローカルネットワーク用 |
053 | set ocidLocalHostName to (ocidPlistDict's valueForKeyPath:("System.Network.HostNames.LocalHostName")) |
054 | ###MacOS用 |
055 | set ocidComputerName to (ocidPlistDict's valueForKeyPath:("System.System.ComputerName")) |
056 | ###/bin/hostname と同等 |
057 | set ocidHostName to (ocidPlistDict's valueForKeyPath:("System.System.HostName")) |
058 | ###SMB用 |
059 | set ocidNetBIOSName to (ocidPlistDictSMB's valueForKeyPath:("NetBIOSName")) |
060 | |
061 | log ocidLocalHostName as text |
062 | log ocidComputerName as text |
063 | log ocidHostName as text |
064 | log ocidNetBIOSName as text |
065 | |
066 | |
067 | ########################################## |
068 | #【2】OS情報 |
069 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSCoreServiceDirectory) inDomains:(refMe's NSSystemDomainMask)) |
070 | set ocidCoreServiceDirPathURL to ocidURLsArray's firstObject() |
071 | set ocidPlistFilePathURL to ocidCoreServiceDirPathURL's URLByAppendingPathComponent:("SystemVersion.plist") isDirectory:(false) |
072 | # |
073 | set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error| :(reference) |
074 | if (item 2 of listResponse) = (missing value) then |
075 | log "正常処理" |
076 | set ocidPlistDict to (item 1 of listResponse) |
077 | else if (item 2 of listResponse) ≠ (missing value) then |
078 | log (item 2 of listResponse)'s code() as text |
079 | log (item 2 of listResponse)'s localizedDescription() as text |
080 | log "エラーしました" |
081 | return false |
082 | end if |
083 | (* この方法だとビルド番号が取れないので使わない |
084 | set recordSystemInfo to (system info) as record |
085 | ###OSバージョン |
086 | set strProductBuildVersion to (system version of recordSystemInfo) as text |
087 | *) |
088 | ###ビルド番号 |
089 | set ocidProductBuildVersion to (ocidPlistDict's valueForKeyPath:("ProductBuildVersion")) |
090 | ###OSバージョン |
091 | set ocidProductVersion to (ocidPlistDict's valueForKeyPath:("ProductVersion")) |
092 | |
093 | log ocidProductBuildVersion as text |
094 | log ocidProductBuildVersion as text |
095 | |
096 | ########################################## |
097 | #【3】シリアル番号 system_profiler JSON |
098 | set ocidSerialNo to doSPHardwareDataTypeJson("SPHardwareDataType.serial_number")'s firstObject() |
099 | set ocidModelName to doSPHardwareDataTypeJson("SPHardwareDataType.machine_model") |
100 | set ocidPlatform_UUID to doSPHardwareDataTypeJson("SPHardwareDataType.platform_UUID") |
101 | set ocidBootRomVer to doSPHardwareDataTypeJson("SPHardwareDataType.boot_rom_version") |
102 | |
103 | log ocidSerialNo as text |
104 | log ocidModelName as text |
105 | log ocidPlatform_UUID as text |
106 | log ocidBootRomVer as text |
107 | |
108 | ########################################## |
109 | #【4】モデル名 ConfigCode |
110 | set ocidConfigCode to doGetConfigCode(ocidSerialNo) |
111 | log ocidConfigCode as text |
112 | |
113 | ########################################## |
114 | #【5】メモリー量 |
115 | set ocidProcessInfo to refMe's NSProcessInfo's processInfo() |
116 | set realMemoryByte to ocidProcessInfo's physicalMemory() as real |
117 | set realGB to "1073741824" as real |
118 | set numPhysicalMemory to (realMemoryByte / realGB) as integer |
119 | (* これはこの方法でも良かった |
120 | set recordSystemInfo to (system info) as record |
121 | set numMem to (physical memory of recordSystemInfo) as real |
122 | set numPhysicalMemory to (numMem / 1000) as integer |
123 | *) |
124 | |
125 | ########################################## |
126 | #【6】ディスク キャパ と 残 diskutil |
127 | set listVolumeInfo to doGetVolumeInfo() |
128 | set ocidVolumeName to (item 1 of listVolumeInfo) |
129 | set ocidFileVault to (item 2 of listVolumeInfo) |
130 | set ocidEncryption to (item 3 of listVolumeInfo) |
131 | set numTotalSize to (item 4 of listVolumeInfo) |
132 | set numContainerFree to (item 5 of listVolumeInfo) |
133 | set ocidDiskUUID to (item 6 of listVolumeInfo) |
134 | log ocidVolumeName as text |
135 | log ocidFileVault as text |
136 | log ocidEncryption as text |
137 | log numTotalSize as text |
138 | log numContainerFree as text |
139 | log ocidDiskUUID as text |
140 | (*ディスクサイズとディスク残はこの方法でも良い |
141 | |
142 | tell application "System Events" |
143 | set strVolumeName to (name of startup disk) as text |
144 | tell startup disk |
145 | set numDiskCapacity to capacity as real |
146 | set numFreeSpace to free space as real |
147 | end tell |
148 | end tell |
149 | set intGB to "1073741824" as integer |
150 | set intGB to "1000000000" as integer |
151 | set numTotalSize to (numTotalSize / intGB) as integer |
152 | set numContainerFree to (numContainerFree / intGB) as integer |
153 | *) |
154 | |
155 | ########################################## |
156 | #【7】システム保護 |
157 | set strCommandText to ("/bin/bash -c '/usr/bin/csrutil status 2>&1'") as text |
158 | set strResponse to (do shell script strCommandText) as text |
159 | if strResponse contains "enabled" then |
160 | log "System Integrity Protection ON" |
161 | set ocidSIP to ("ON") as text |
162 | else |
163 | log "System Integrity ProtectionがOFFです" |
164 | set ocidSIP to ("OFF") as text |
165 | end if |
166 | |
167 | |
168 | ########################################## |
169 | #【8】XProtect |
170 | set strCommandText to ("/bin/bash -c '/usr/sbin/spctl --status 2>&1'") as text |
171 | set strResponse to (do shell script strCommandText) as text |
172 | if strResponse contains "enabled" then |
173 | log "XProtect ON" |
174 | set ocidXProtect to ("ON") as text |
175 | else |
176 | log "XProtectがOFFです" |
177 | set ocidXProtect to ("OFF") as text |
178 | end if |
179 | |
180 | |
181 | ########################################## |
182 | #【9】TCCバージョン |
183 | #set strChkFilePath to ("/Library/Apple/Library/Bundles/TCC_Compatibility.bundle") as text |
184 | #バージョン取得 |
185 | #set ocidTCCver to doGetVersion(strChkFilePath) |
186 | #log ocidTCCver as text |
187 | set ocidTCCver to ("Sequoiaで廃止") |
188 | |
189 | ########################################## |
190 | #【10】AppleKext バージョン |
191 | set strChkFilePath to ("/Library/Apple/System/Library/Extensions/AppleKextExcludeList.kext") as text |
192 | #バージョン取得 |
193 | set ocidKEXTver to doGetVersion(strChkFilePath) |
194 | log ocidKEXTver as text |
195 | |
196 | ########################################## |
197 | #【11】XProtect バージョン |
198 | set strChkFilePath to ("/Library/Apple/System/Library/CoreServices/XProtect.bundle/Contents/Info.plist") as text |
199 | #バージョン取得 |
200 | set ocidXBundlever to doGetPlistValue(strChkFilePath, "CFBundleShortVersionString") |
201 | log ocidXBundlever as text |
202 | |
203 | |
204 | set strChkFilePath to ("/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/Info.plist") as text |
205 | #バージョン取得 |
206 | set ocidXAppver to doGetPlistValue(strChkFilePath, "CFBundleShortVersionString") |
207 | log ocidXAppver as text |
208 | |
209 | set ocidMRTver to ((ocidXBundlever as text) & " " & (ocidXAppver as text)) as text |
210 | |
211 | ########################################## |
212 | #【12】ディスクの暗号化 fdesetup |
213 | set strCommandText to ("/bin/bash -c '/usr/bin/fdesetup status 2>&1'") as text |
214 | set strResponse to (do shell script strCommandText) as text |
215 | if strResponse contains "Off" then |
216 | log "FileVault未設定" |
217 | set ocidFileVault to ("OFF") as text |
218 | else |
219 | log "FileVault実行中" |
220 | set ocidFileVault to ("ON") as text |
221 | end if |
222 | |
223 | ########################################## |
224 | #【13】ユーザー情報 |
225 | (* 一般的にはこの方法がいいでしょう |
226 | ##system infoを使う |
227 | set recordSystemInfo to (system info) as record |
228 | set strUserName to (short user name of recordSystemInfo) as text |
229 | set strUserNameLong to (long user name of recordSystemInfo) as text |
230 | set strUID to (user ID of recordSystemInfo) as text |
231 | #ここだけエイリアスが戻り値 |
232 | set aliasHomeDirPath to (home directory of recordSystemInfo) as alias |
233 | set strHomeDirPath to (POSIX path of aliasHomeDirPath) as text |
234 | *) |
235 | #ユーザー名ショート |
236 | set ocidUserName to refMe's NSUserName() |
237 | #ユーザー名ロング |
238 | set ocidUserNameLong to refMe's NSFullUserName() |
239 | #Unixパス ホームディレクトリ |
240 | set ocidHomeDirPath to refMe's NSHomeDirectory() |
241 | #NSURL ホームディレクトリ |
242 | set ocidHomeDirPathURL to appFileManager's homeDirectoryForUser:(ocidUserName) |
243 | set ocidHomeDirPath to ocidHomeDirPathURL's |path|() |
244 | #コンソールのIDを取得する方法 |
245 | set strDevDirPath to ("/dev/console") as text |
246 | set ocidDevDirPathStr to refMe's NSString's stringWithString:(strDevDirPath) |
247 | set ocidDevDirPath to ocidDevDirPathStr's stringByStandardizingPath() |
248 | #アトリビュートを取得して |
249 | set listResponse to appFileManager's attributesOfItemAtPath:(ocidDevDirPath) |error| :(reference) |
250 | if (item 2 of listResponse) = (missing value) then |
251 | log "正常処理" |
252 | set ocidAttarDict to (item 1 of listResponse) |
253 | else if (item 2 of listResponse) ≠ (missing value) then |
254 | log (item 2 of listResponse)'s code() as text |
255 | log (item 2 of listResponse)'s localizedDescription() as text |
256 | return "エラーしました" |
257 | end if |
258 | #UIDを取得する |
259 | set ocidUID to (ocidAttarDict's valueForKey:(refMe's NSFileOwnerAccountID)) |
260 | |
261 | ########################################## |
262 | #【14】電源情報 pmset |
263 | |
264 | if (ocidModelName as text) contains "book" then |
265 | set listResponse to doGetPmset() |
266 | set ocidBatterySerialNumber to (item 1 of listResponse) |
267 | set ocidBatteryHealth to (item 2 of listResponse) |
268 | set ocidOptimized to (item 3 of listResponse) |
269 | log ocidBatterySerialNumber as text |
270 | log ocidBatteryHealth as text |
271 | log ocidOptimized as text |
272 | |
273 | end if |
274 | ########################################## |
275 | #【OUTPUT】HTMLにして表示 |
276 | |
277 | set strHTML to ("<!DOCTYPE html><html lang=\"ja\"><head><title>システム情報</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><meta name=\"viewport\" content=\"width=720\"><style>body {margin: 10px;background-color: #FFFFFF;font-family: system-ui;}article {max-width: 720px;}.content {display: flex;flex-wrap: wrap;gap: 12px;}.module {width: 216px;height: 72px;border-radius: .5em;background-color: lightgrey;flex-direction: column;align-items: center;text-align: center;border: 1px solid #ccc;}.module p,.module h4,.module h5 {margin: 5px 0;}a {text-decoration: none;}small{font-size: 0.5rem;}</style><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"></head><body><header id=\"header\" class=\"body_header\"><div><h3>システム情報</h3></div></header><article id=\"article\" class=\"body_article\"><div class=\"content\"><div class=\"module\"><h4>コンピューター名<a href=\"x-apple.systempreferences:com.apple.SystemProfiler.AboutExtension?aboutSection\">⚒️</a></h4><h5>ComputerName</h5><p>" & ocidComputerName & "</p></div><div class=\"module\"><h4>Bonjour名<a href=\"x-apple.systempreferences:com.apple.Sharing-Settings.extension?Services_PersonalFileSharing\">⚒️</a></h4><h5>LocalHostName</h5><p>" & ocidLocalHostName & "</p></div><div class=\"module\"><h4>ホスト名<a href=\"x-apple.systempreferences:com.apple.SystemProfiler.AboutExtension?aboutSection\">⚒️</a></h4><h5>HostName</h5><p>" & ocidHostName & "</p></div><div class=\"module\"><h4>SMB名<a href=\"x-apple.systempreferences:com.apple.Sharing-Settings.extension?Services_WindowsSharing\">⚒️</a></h4><h5>NetBIOSName</h5><p>" & ocidNetBIOSName & "</p></div><div class=\"module\"><h4>Osバージョン<a href=\"x-apple.systempreferences:com.apple.SystemProfiler.AboutExtension?softwareSection\">⚒️</a></h4><h5>ProductVersion</h5><p>" & ocidProductVersion & "</p></div><div class=\"module\"><h4>ビルド番号<a href=\"x-apple.systempreferences:com.apple.SystemProfiler.AboutExtension?softwareSection\">⚒️</a></h4><h5>ProductBuildVersion</h5><p>" & ocidProductBuildVersion & "</p></div><div class=\"module\"><h4>モデル番号<a href=\"x-apple.systempreferences:com.apple.SystemProfiler.AboutExtension?aboutSection\">⚒️</a></h4><h5>machine_model</h5><p>" & ocidModelName & "</p></div><div class=\"module\"><h4>モデル名<a href=\"x-apple.systempreferences:com.apple.SystemProfiler.AboutExtension?aboutSection\">⚒️</a></h4><h5>ConfigCode</h5><p><small>" & ocidConfigCode & "</small></p></div><div class=\"module\"><h4>シリアルNO<a href=\"x-apple.systempreferences:com.apple.SystemProfiler.AboutExtension?aboutSection\">⚒️</a></h4><h5>serial_number</h5><p>" & ocidSerialNo & "</p></div><div class=\"module\"><h4>デバイスUUID<a href=\"file:///System/Applications/Utilities/System Information.app\">⚙️</a></h4><h5>platform_UUID</h5><p><small>" & ocidPlatform_UUID & "</small></p></div><div class=\"module\"><h4>BootRomバージョン<a href=\"file:///System/Applications/Utilities/System Information.app\">⚙️</a></h4><h5>boot_rom_version</h5><p>" & ocidBootRomVer & "</p></div><div class=\"module\"><h4>メモリー搭載量<a href=\"x-apple.systempreferences:com.apple.SystemProfiler.AboutExtension?aboutSection\">⚒️</a></h4><h5>physicalMemory</h5><p>" & numPhysicalMemory & "GB" & "</p></div><div class=\"module\"><h4>ディスク容量<a href=\"x-apple.systempreferences:com.apple.settings.Storage?storagePref\">🗄️</a></h4><h5>TotalSize</h5><p>" & numTotalSize & "GB" & "</p></div><div class=\"module\"><h4>ディスク残<a href=\"x-apple.systempreferences:com.apple.settings.Storage?storagePref\">🗄️</a></h4><h5>APFSContainerFree</h5><p>" & numContainerFree & "GB" & "</p></div><div class=\"module\"><h4>ディスクUUID<a href=\"file:///System/Applications/Utilities/System Information.app\">⚙️</a></h4><h5>DiskUUID</h5><p><small>" & ocidDiskUUID & "</small></p></div><div class=\"module\"><h4>FileVault実行<a href=\"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?FileVault\">🗄️</a></h4><h5>FileVault</h5><p>" & ocidFileVault & "</p></div><div class=\"module\"><h4>暗号化<a href=\"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?FileVault\">🗄️</a></h4><h5>Encryption</h5><p>" & ocidEncryption & "</p></div><div class=\"module\"><h4>起動ディスク名<a href=\"x-apple.systempreferences:com.apple.Startup-Disk-Settings.extension?StartupSearchGroup\">🗄️</a></h4><h5>VolumeName</h5><p>" & ocidVolumeName & "</p></div><div class=\"module\"><h4>システム保護SIP<a href=\"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Security\">🗄️</a></h4><h5>csrutil</h5><p>" & ocidSIP & "</p></div><div class=\"module\"><h4>XProtect</h4><h5>spctl</h5><p>" & ocidXProtect & "</p></div><div class=\"module\"><h4>TCCバージョン</h4><h5>TCC_Compatibility</h5><p>" & ocidTCCver & "</p></div><div class=\"module\"><h4>AppleKext</h4><h5>ExcludeList</h5><p>" & ocidKEXTver & "</p></div><div class=\"module\"><h4>XProtect</h4><h5>XProtect</h5><p>" & ocidMRTver & "</p></div><div class=\"module\"><h4>FileVault<a href=\"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?FileVault\">🗄️</a></h4><h5>fdesetup</h5><p>" & ocidFileVault & "</p></div><div class=\"module\"><h4>ユーザー名<a href=\"x-apple.systempreferences:com.apple.Users-Groups-Settings.extension\">👤</a></h4><h5>NSUserName</h5><p>" & ocidUserName & "</p></div><div class=\"module\"><h4>ユーザーID<a href=\"x-apple.systempreferences:com.apple.Users-Groups-Settings.extension\">👤</a></h4><h5>AccountID</h5><p>" & ocidUID & "</p></div><div class=\"module\"><h4> </h4><h5> </h5><p> </p></div><div class=\"module\"><h4>バッテリーシリアル<a href=\"file:///System/Applications/Utilities/System Information.app\">⚙️</a></h4><h5>Hardware Serial Number</h5><p>" & ocidBatterySerialNumber & "</p></div><div class=\"module\"><h4>バッテリー最適化<a href=\"x-apple.systempreferences:com.apple.Battery-Settings.extension*BatteryPreferences?batteryhealth\">🔋</a></h4><h5>Optimized Battery</h5><p>" & ocidOptimized & "</p></div><div class=\"module\"><h4>バッテリー状態<a href=\"x-apple.systempreferences:com.apple.Battery-Settings.extension*BatteryPreferences?currentSource\">🔋</a></h4><h5>BatteryHealth</h5><p>" & ocidBatteryHealth & "</p></div></div></article><footer id=\"footer\" class=\"body_footer\"><div><p><a href=\"https://quicktimer.cocolog-nifty.com/icefloe/2024/06/post-9cf776.html\" target=\"_blank\">AppleScriptで生成しました</a></p></div></footer></body></html>") as text |
278 | |
279 | set ocidSaveFilePathURL to doSaveText(strHTML) |
280 | ##HTMLを開く |
281 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
282 | set boolDone to appSharedWorkspace's openURL:(ocidSaveFilePathURL) |
283 | |
284 | ########################################## |
285 | #HTMLとして保存 |
286 | to doSaveText(argText) |
287 | ###ディレクトリ |
288 | set appFileManager to refMe's NSFileManager's defaultManager() |
289 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
290 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
291 | set ocidUUIDString to ocidUUID's UUIDString |
292 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true |
293 | # |
294 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
295 | # 777-->511 755-->493 700-->448 766-->502 |
296 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
297 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
298 | ###パス |
299 | set strFileName to "device_info.html" as text |
300 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false |
301 | # |
302 | set ocidSaveString to refMe's NSString's stringWithString:(argText) |
303 | set listDone to ocidSaveString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
304 | if (item 1 of listDone) is true then |
305 | log "正常処理" |
306 | return ocidSaveFilePathURL |
307 | else if (item 2 of listDone) ≠ (missing value) then |
308 | log (item 2 of listDone)'s code() as text |
309 | log (item 2 of listDone)'s localizedDescription() as text |
310 | log "エラーしました" |
311 | return false |
312 | end if |
313 | |
314 | |
315 | end doSaveText |
316 | return |
317 | |
318 | ########################################## |
319 | #【14】電源情報 pmset |
320 | |
321 | to doGetPmset() |
322 | set strCommandText to ("/bin/zsh -c '/usr/bin/pmset -g batt -xml'") as text |
323 | log strCommandText |
324 | try |
325 | set strResponse to (do shell script strCommandText) as text |
326 | on error |
327 | log "コマンドでエラーしました" |
328 | return false |
329 | end try |
330 | #戻り値をストリングに |
331 | set ocidPlistStrings to refMe's NSString's stringWithString:(strResponse) |
332 | #NSDATAにして |
333 | set ocidPlisStringstData to ocidPlistStrings's dataUsingEncoding:(refMe's NSUTF8StringEncoding) |
334 | #PLIST初期化して |
335 | set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0) |
336 | set listResponse to refMe's NSPropertyListSerialization's propertyListWithData:ocidPlisStringstData options:(0) format:(ocidFormat) |error| :(reference) |
337 | if (item 2 of listResponse) = (missing value) then |
338 | log "正常処理" |
339 | set ocidPlistDict to (item 1 of listResponse) |
340 | else if (item 2 of listResponse) ≠ (missing value) then |
341 | log (item 2 of listResponse)'s code() as text |
342 | log (item 2 of listResponse)'s localizedDescription() as text |
343 | return "エラーしました" |
344 | end if |
345 | set ocidBatterySerialNumber to ocidPlistDict's valueForKey:("Hardware Serial Number") |
346 | set ocidBatteryHealth to ocidPlistDict's valueForKey:("BatteryHealth") |
347 | set ocidOptimized to ocidPlistDict's valueForKey:("Optimized Battery Charging Engaged") |
348 | |
349 | return {ocidBatterySerialNumber, ocidBatteryHealth, ocidOptimized} |
350 | |
351 | end doGetPmset |
352 | |
353 | ########################################## |
354 | # 【13】 アップデート softwareupdate |
355 | set strCommandText to ("/bin/bash -c '/usr/sbin/softwareupdate --list --include-config-data 2>&1'") as text |
356 | log strCommandText |
357 | set strResponse to (do shell script strCommandText) as text |
358 | if strResponse contains "No new software available" then |
359 | log "最新です" |
360 | else |
361 | log "アップデートがあります" |
362 | end if |
363 | |
364 | ########################################## |
365 | #【6】ディスク キャパ と 残 diskutil |
366 | to doGetVolumeInfo() |
367 | set strCommandText to "/usr/sbin/diskutil info -plist /" as text |
368 | log strCommandText |
369 | try |
370 | set strResponse to (do shell script strCommandText) as text |
371 | on error |
372 | log "コマンドでエラーしました" |
373 | return false |
374 | end try |
375 | #戻り値をストリングに |
376 | set ocidPlistStrings to refMe's NSString's stringWithString:(strResponse) |
377 | #NSDATAにして |
378 | set ocidPlisStringstData to ocidPlistStrings's dataUsingEncoding:(refMe's NSUTF8StringEncoding) |
379 | #PLIST初期化して |
380 | set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0) |
381 | set listResponse to refMe's NSPropertyListSerialization's propertyListWithData:ocidPlisStringstData options:(0) format:(ocidFormat) |error| :(reference) |
382 | if (item 2 of listResponse) = (missing value) then |
383 | log "正常処理" |
384 | set ocidPlistDict to (item 1 of listResponse) |
385 | else if (item 2 of listResponse) ≠ (missing value) then |
386 | log (item 2 of listResponse)'s code() as text |
387 | log (item 2 of listResponse)'s localizedDescription() as text |
388 | return "エラーしました" |
389 | end if |
390 | # |
391 | set ocidVolumeName to (ocidPlistDict's valueForKey:"VolumeName") |
392 | set ocidDiskUUID to (ocidPlistDict's valueForKey:"DiskUUID") |
393 | set ocidVolumeUUID to (ocidPlistDict's valueForKey:"VolumeUUID") |
394 | set ocidFilesystemName to (ocidPlistDict's valueForKey:"FilesystemName") |
395 | set ocidFileVault to (ocidPlistDict's valueForKey:"FileVault") |
396 | set ocidEncryption to (ocidPlistDict's valueForKey:"Encryption") |
397 | #サイズ |
398 | set ocidTotalSize to (ocidPlistDict's valueForKey:"TotalSize") |
399 | set intGB to "1073741824" as integer |
400 | set ocidGB to (refMe's NSNumber's numberWithInteger:intGB) |
401 | set numTotalSize to ((ocidTotalSize's doubleValue as real) / (ocidGB's doubleValue as real)) as integer |
402 | #残 |
403 | set ocidAPFSContainerFree to (ocidPlistDict's valueForKey:"APFSContainerFree") |
404 | set intGB to "1073741824" as integer |
405 | set ocidGB to (refMe's NSNumber's numberWithInteger:intGB) |
406 | set numContainerFree to ((ocidAPFSContainerFree's doubleValue as real) / (ocidGB's doubleValue as real)) as integer |
407 | |
408 | return {ocidVolumeName, ocidFileVault, ocidEncryption, numTotalSize, numContainerFree, ocidDiskUUID} |
409 | end doGetVolumeInfo |
410 | |
411 | ########################################## |
412 | #【4】モデル名 ConfigCode |
413 | to doGetConfigCode(argSerialNo) |
414 | #ConfigCodeになる4文字を取り出して |
415 | set intTextlength to (argSerialNo's |length|) as integer |
416 | set ocidRenge to refMe's NSMakeRange((intTextlength - 4), 4) |
417 | set strConfigCode to (argSerialNo's substringWithRange:(ocidRenge)) as text |
418 | #URL整形 |
419 | set ocidURLComponents to refMe's NSURLComponents's alloc()'s init() |
420 | #スキーム を追加 |
421 | ocidURLComponents's setScheme:("https") |
422 | #ホスト追加 |
423 | ocidURLComponents's setHost:("support-sp.apple.com") |
424 | #パスを追加(setHostじゃないよ) |
425 | ocidURLComponents's setPath:("/sp/product") |
426 | #CC config Codeクエリーを追加 |
427 | set ocidComponentArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
428 | set ocidQueryItem to refMe's NSURLQueryItem's alloc()'s initWithName:("cc") value:(strConfigCode) |
429 | ocidComponentArray's addObject:(ocidQueryItem) |
430 | #langクエリーを追加 |
431 | set ocidLocale to refMe's NSLocale's currentLocale() |
432 | set ocidLocaleID to ocidLocale's localeIdentifier() |
433 | set ocidQueryItem to (refMe's NSURLQueryItem's alloc()'s initWithName:("lang") value:(ocidLocaleID)) |
434 | (ocidComponentArray's addObject:(ocidQueryItem)) |
435 | #検索クエリーとして追加 |
436 | (ocidURLComponents's setQueryItems:(ocidComponentArray)) |
437 | #コンポーネントをURLに展開 |
438 | set ocidURL to ocidURLComponents's |URL|() |
439 | #XML読み込み |
440 | set ocidOption to (refMe's NSXMLDocumentTidyXML) |
441 | set listResponse to refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error| :(reference) |
442 | if (item 2 of listResponse) = (missing value) then |
443 | log "正常処理" |
444 | set ocidReadXMLDoc to (item 1 of listResponse) |
445 | else if (item 2 of listResponse) ≠ (missing value) then |
446 | log (item 2 of listResponse)'s code() as text |
447 | log (item 2 of listResponse)'s localizedDescription() as text |
448 | log "エラーしました" |
449 | return false |
450 | end if |
451 | #ROOTエレメント |
452 | set ocidRootElement to ocidReadXMLDoc's rootElement() |
453 | #configCodeからモデル名を取得 |
454 | set ocidConfigCode to (ocidRootElement's elementsForName:("configCode"))'s firstObject() |
455 | set ocidConfigCode to ocidConfigCode's stringValue() |
456 | return ocidConfigCode |
457 | end doGetConfigCode |
458 | |
459 | ########################################## |
460 | #【3】system_profiler json |
461 | to doSPHardwareDataTypeJson(argKeyPath) |
462 | set strCommandText to ("/bin/zsh -c '/usr/sbin/system_profiler SPHardwareDataType -json'") as text |
463 | log strCommandText |
464 | set strResponse to (do shell script strCommandText) as text |
465 | set ocidJsonStrings to refMe's NSString's stringWithString:(strResponse) |
466 | set ocidJsonData to ocidJsonStrings's dataUsingEncoding:(refMe's NSUTF8StringEncoding) |
467 | set ocidOption to (refMe's NSJSONReadingMutableContainers) |
468 | set listResponse to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:(ocidOption) |error| :(reference)) |
469 | if (item 2 of listResponse) = (missing value) then |
470 | log "正常処理" |
471 | set ocidJsonDict to (item 1 of listResponse) |
472 | else if (item 2 of listResponse) ≠ (missing value) then |
473 | log (item 2 of listResponse)'s code() as text |
474 | log (item 2 of listResponse)'s localizedDescription() as text |
475 | return "エラーしました" |
476 | end if |
477 | set ocidValue to (ocidJsonDict's valueForKeyPath:(argKeyPath)) |
478 | return ocidValue |
479 | end doSPHardwareDataTypeJson |
480 | |
481 | |
482 | ########################################## |
483 | #テキストパスからバージョンを取得 |
484 | to doGetVersion(argFilePathStrings) |
485 | #パス |
486 | set strFilePath to (argFilePathStrings) as text |
487 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
488 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
489 | set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false) |
490 | # |
491 | set ocidAppBundle to refMe's NSBundle's bundleWithURL:(ocidFilePathURL) |
492 | set ocidInfoDict to ocidAppBundle's infoDictionary() |
493 | set ocidCFBundleVersion to (ocidInfoDict's valueForKey:("CFBundleVersion")) |
494 | return ocidCFBundleVersion |
495 | end doGetVersion |
496 | |
497 | |
498 | ########################################## |
499 | #plistから指定のキーの値を取得する |
500 | to doGetPlistValue(argFilePathStrings, argKey) |
501 | #パス |
502 | set strFilePath to (argFilePathStrings) as text |
503 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
504 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
505 | set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false) |
506 | #レコードを読み込み |
507 | set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidFilePathURL) |error| :(reference) |
508 | if (item 2 of listResponse) = (missing value) then |
509 | log "正常処理" |
510 | set ocidPlistDict to (item 1 of listResponse) |
511 | else if (item 2 of listResponse) ≠ (missing value) then |
512 | log (item 2 of listResponse)'s code() as text |
513 | log (item 2 of listResponse)'s localizedDescription() as text |
514 | log "エラーしました" |
515 | return false |
516 | end if |
517 | set ocidValue to ocidPlistDict's valueForKey:(argKey) |
518 | if ocidValue = (missing value) then |
519 | return false |
520 | else |
521 | return ocidValue |
522 | end if |
523 | end doGetPlistValue |
524 | |
525 | |
526 | |
AppleScriptで生成しました |
| 固定リンク