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