Admin Support

[セキュリティ]各種情報 バージョン取得 v2 (TCC_Compatibility廃止対応)


AppleScript サンプルコード

【スクリプトエディタで開く】 |

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
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use scripting additions
012
013property refMe : a reference to current application
014
015
016##########################################
017#【1】コンピューター名
018set appFileManager to refMe's NSFileManager's defaultManager()
019set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSLocalDomainMask))
020set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
021set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/SystemConfiguration/preferences.plist") isDirectory:(false)
022#
023set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error| :(reference)
024if (item 2 of listResponse) = (missing value) then
025  log "正常処理"
026  set ocidPlistDict to (item 1 of listResponse)
027else 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
032end if
033set ocidPlistFilePathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences/SystemConfiguration/com.apple.smb.server.plist") isDirectory:(false)
034#
035set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error| :(reference)
036if (item 2 of listResponse) = (missing value) then
037  log "正常処理"
038  set ocidPlistDictSMB to (item 1 of listResponse)
039else 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
044end if
045(* この方法だとBonjourとSMB名が取れないので使わない
046set recordSystemInfo to (system info) as record
047###MacOS用
048set strComputerName to (computer name of recordSystemInfo) as text
049###/bin/hostname と同等
050set strHostName to (host name of recordSystemInfo) as text
051*)
052###Bonjourローカルネットワーク用
053set ocidLocalHostName to (ocidPlistDict's valueForKeyPath:("System.Network.HostNames.LocalHostName"))
054###MacOS用
055set ocidComputerName to (ocidPlistDict's valueForKeyPath:("System.System.ComputerName"))
056###/bin/hostname と同等
057set ocidHostName to (ocidPlistDict's valueForKeyPath:("System.System.HostName"))
058###SMB用
059set ocidNetBIOSName to (ocidPlistDictSMB's valueForKeyPath:("NetBIOSName"))
060
061log ocidLocalHostName as text
062log ocidComputerName as text
063log ocidHostName as text
064log ocidNetBIOSName as text
065
066
067##########################################
068#【2】OS情報
069set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSCoreServiceDirectory) inDomains:(refMe's NSSystemDomainMask))
070set ocidCoreServiceDirPathURL to ocidURLsArray's firstObject()
071set ocidPlistFilePathURL to ocidCoreServiceDirPathURL's URLByAppendingPathComponent:("SystemVersion.plist") isDirectory:(false)
072#
073set listResponse to refMe's NSDictionary's alloc()'s initWithContentsOfURL:(ocidPlistFilePathURL) |error| :(reference)
074if (item 2 of listResponse) = (missing value) then
075  log "正常処理"
076  set ocidPlistDict to (item 1 of listResponse)
077else 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
082end if
083(* この方法だとビルド番号が取れないので使わない
084set recordSystemInfo to (system info) as record
085###OSバージョン
086set strProductBuildVersion to (system version of recordSystemInfo) as text
087*)
088###ビルド番号
089set ocidProductBuildVersion to (ocidPlistDict's valueForKeyPath:("ProductBuildVersion"))
090###OSバージョン
091set ocidProductVersion to (ocidPlistDict's valueForKeyPath:("ProductVersion"))
092
093log ocidProductBuildVersion as text
094log ocidProductBuildVersion as text
095
096##########################################
097#【3】シリアル番号 system_profiler JSON
098set ocidSerialNo to doSPHardwareDataTypeJson("SPHardwareDataType.serial_number")'s firstObject()
099set ocidModelName to doSPHardwareDataTypeJson("SPHardwareDataType.machine_model")
100set ocidPlatform_UUID to doSPHardwareDataTypeJson("SPHardwareDataType.platform_UUID")
101set ocidBootRomVer to doSPHardwareDataTypeJson("SPHardwareDataType.boot_rom_version")
102
103log ocidSerialNo as text
104log ocidModelName as text
105log ocidPlatform_UUID as text
106log ocidBootRomVer as text
107
108##########################################
109#【4】モデル名 ConfigCode
110set ocidConfigCode to doGetConfigCode(ocidSerialNo)
111log ocidConfigCode as text
112
113##########################################
114#【5】メモリー量
115set ocidProcessInfo to refMe's NSProcessInfo's processInfo()
116set realMemoryByte to ocidProcessInfo's physicalMemory() as real
117set realGB to "1073741824" as real
118set numPhysicalMemory to (realMemoryByte / realGB) as integer
119(* これはこの方法でも良かった
120set recordSystemInfo to (system info) as record
121set numMem to (physical memory of recordSystemInfo) as real
122set numPhysicalMemory to (numMem / 1000) as integer
123*)
124
125##########################################
126#【6】ディスク キャパ と 残 diskutil
127set listVolumeInfo to doGetVolumeInfo()
128set ocidVolumeName to (item 1 of listVolumeInfo)
129set ocidFileVault to (item 2 of listVolumeInfo)
130set ocidEncryption to (item 3 of listVolumeInfo)
131set numTotalSize to (item 4 of listVolumeInfo)
132set numContainerFree to (item 5 of listVolumeInfo)
133set ocidDiskUUID to (item 6 of listVolumeInfo)
134log ocidVolumeName as text
135log ocidFileVault as text
136log ocidEncryption as text
137log numTotalSize as text
138log numContainerFree as text
139log ocidDiskUUID as text
140(*ディスクサイズとディスク残はこの方法でも良い
141
142tell 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
148end tell
149set intGB to "1073741824" as integer
150set intGB to "1000000000" as integer
151set numTotalSize to (numTotalSize / intGB) as integer
152set numContainerFree to (numContainerFree / intGB) as integer
153*)
154
155##########################################
156#【7】システム保護
157set strCommandText to ("/bin/bash -c '/usr/bin/csrutil status 2>&1'") as text
158set strResponse to (do shell script strCommandText) as text
159if strResponse contains "enabled" then
160  log "System Integrity Protection ON"
161  set ocidSIP to ("ON") as text
162else
163  log "System Integrity ProtectionがOFFです"
164  set ocidSIP to ("OFF") as text
165end if
166
167
168##########################################
169#【8】XProtect
170set strCommandText to ("/bin/bash -c '/usr/sbin/spctl --status 2>&1'") as text
171set strResponse to (do shell script strCommandText) as text
172if strResponse contains "enabled" then
173  log "XProtect ON"
174  set ocidXProtect to ("ON") as text
175else
176  log "XProtectがOFFです"
177  set ocidXProtect to ("OFF") as text
178end 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
187set ocidTCCver to ("Sequoiaで廃止")
188
189##########################################
190#【10】AppleKext バージョン
191set strChkFilePath to ("/Library/Apple/System/Library/Extensions/AppleKextExcludeList.kext") as text
192#バージョン取得
193set ocidKEXTver to doGetVersion(strChkFilePath)
194log ocidKEXTver as text
195
196##########################################
197#【11】XProtect バージョン
198set strChkFilePath to ("/Library/Apple/System/Library/CoreServices/XProtect.bundle/Contents/Info.plist") as text
199#バージョン取得
200set ocidXBundlever to doGetPlistValue(strChkFilePath, "CFBundleShortVersionString")
201log ocidXBundlever as text
202
203
204set strChkFilePath to ("/Library/Apple/System/Library/CoreServices/XProtect.app/Contents/Info.plist") as text
205#バージョン取得
206set ocidXAppver to doGetPlistValue(strChkFilePath, "CFBundleShortVersionString")
207log ocidXAppver as text
208
209set ocidMRTver to ((ocidXBundlever as text) & " " & (ocidXAppver as text)) as text
210
211##########################################
212#【12】ディスクの暗号化 fdesetup
213set strCommandText to ("/bin/bash -c '/usr/bin/fdesetup status 2>&1'") as text
214set strResponse to (do shell script strCommandText) as text
215if strResponse contains "Off" then
216  log "FileVault未設定"
217  set ocidFileVault to ("OFF") as text
218else
219  log "FileVault実行中"
220  set ocidFileVault to ("ON") as text
221end if
222
223##########################################
224#【13】ユーザー情報
225(* 一般的にはこの方法がいいでしょう
226##system infoを使う
227set recordSystemInfo to (system info) as record
228set strUserName to (short user name of recordSystemInfo) as text
229set strUserNameLong to (long user name of recordSystemInfo) as text
230set strUID to (user ID of recordSystemInfo) as text
231#ここだけエイリアスが戻り値
232set aliasHomeDirPath to (home directory of recordSystemInfo) as alias
233set strHomeDirPath to (POSIX path of aliasHomeDirPath) as text
234*)
235#ユーザー名ショート
236set ocidUserName to refMe's NSUserName()
237#ユーザー名ロング
238set ocidUserNameLong to refMe's NSFullUserName()
239#Unixパス ホームディレクトリ
240set ocidHomeDirPath to refMe's NSHomeDirectory()
241#NSURL ホームディレクトリ
242set ocidHomeDirPathURL to appFileManager's homeDirectoryForUser:(ocidUserName)
243set ocidHomeDirPath to ocidHomeDirPathURL's |path|()
244#コンソールのIDを取得する方法
245set strDevDirPath to ("/dev/console") as text
246set ocidDevDirPathStr to refMe's NSString's stringWithString:(strDevDirPath)
247set ocidDevDirPath to ocidDevDirPathStr's stringByStandardizingPath()
248#アトリビュートを取得して
249set listResponse to appFileManager's attributesOfItemAtPath:(ocidDevDirPath) |error| :(reference)
250if (item 2 of listResponse) = (missing value) then
251  log "正常処理"
252  set ocidAttarDict to (item 1 of listResponse)
253else 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 "エラーしました"
257end if
258#UIDを取得する
259set ocidUID to (ocidAttarDict's valueForKey:(refMe's NSFileOwnerAccountID))
260
261##########################################
262#【14】電源情報 pmset
263
264if (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  
273end if
274##########################################
275#【OUTPUT】HTMLにして表示
276
277set 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
279set ocidSaveFilePathURL to doSaveText(strHTML)
280##HTMLを開く
281set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
282set boolDone to appSharedWorkspace's openURL:(ocidSaveFilePathURL)
283
284##########################################
285#HTMLとして保存
286to 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  
315end doSaveText
316return
317
318##########################################
319#【14】電源情報 pmset
320
321to 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  
351end doGetPmset
352
353##########################################
354# 【13】 アップデート softwareupdate
355set strCommandText to ("/bin/bash -c '/usr/sbin/softwareupdate  --list --include-config-data 2>&1'") as text
356log strCommandText
357set strResponse to (do shell script strCommandText) as text
358if strResponse contains "No new software available" then
359  log "最新です"
360else
361  log "アップデートがあります"
362end if
363
364##########################################
365#【6】ディスク キャパ と 残 diskutil
366to 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}
409end doGetVolumeInfo
410
411##########################################
412#【4】モデル名 ConfigCode
413to 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
457end doGetConfigCode
458
459##########################################
460#【3】system_profiler json 
461to 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
479end doSPHardwareDataTypeJson
480
481
482##########################################
483#テキストパスからバージョンを取得
484to 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
495end doGetVersion
496
497
498##########################################
499#plistから指定のキーの値を取得する
500to 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
523end doGetPlistValue
524
525
526
AppleScriptで生成しました

|

Appleサポートドキュメント一覧

ページ数が多くなったので
別にした
20240902110534_697x644 https://apple-support-link.blogspot.com/

|

Appleのサポート文書のタイトルとリンクを取得してHTML表示する(さすがに少し修正した)


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005# Appleサポート用にカスタマイズしていますので
006# 一般的なサイトでは利用できません
007#
008#
009----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
010use AppleScript version "2.8"
011use framework "Foundation"
012use framework "AppKit"
013use scripting additions
014property refMe : a reference to current application
015
016############
017#設定項目
018#開始番号 HT+開始番号で 文書番号になる
019set numStartHTNO to (212000) as integer
020#取得するWEBページ数
021set numCntGetURL to (100) as integer
022
023############
024#指定個数分URLを生成する
025set ocidURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
026repeat numCntGetURL times
027  set strHTNo to ("HT" & numStartHTNO) as text
028  set strSetPath to ("/en-us/" & strHTNo) as text
029  
030  set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
031  (ocidURLComponents's setScheme:("https"))
032  (ocidURLComponents's setHost:("support.apple.com"))
033  (ocidURLComponents's setPath:(strSetPath))
034  set ocidSetURL to ocidURLComponents's |URL|()
035  set strSetURL to ocidSetURL's absoluteString() as text
036  ocidURLArray's addObject:(strSetURL)
037  set numStartHTNO to (numStartHTNO + 1) as integer
038end repeat
039
040############
041set appFileManager to refMe's NSFileManager's defaultManager()
042#保存先確保
043set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
044set ocidSaveDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:("Sites/LinkMaker") isDirectory:(true)
045set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
046ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
047set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference)
048if (item 1 of listDone) is false then
049  set strErrorNO to (item 2 of listDone)'s code() as text
050  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
051  refMe's NSLog("■:" & strErrorNO & strErrorMes)
052  return "エラーしました" & strErrorNO & strErrorMes
053end if
054#保存ファイルURL
055set strDateNo to doGetDateNo("yyyyMMdd_hhmm")
056set strSaveFileName to ("linkmaker_" & strDateNo & ".html") as text
057set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false)
058
059
060############
061#HTML生成用に渡すlist
062set listMakeHTML to {} as list
063
064#URLの数だけ繰り返し
065repeat with itemArray in ocidURLArray
066  #対象のURL
067  set strURL to itemArray as text
068  set ocidURLString to (refMe's NSString's stringWithString:(strURL))
069  set ocidURL to (refMe's NSURL's alloc()'s initWithString:(ocidURLString))
070  #【1】HT番号
071  set ocidHTno to ocidURL's lastPathComponent()
072  #【2】USの参照URL
073  set strURLEN to ocidURL's absoluteString() as text
074  #############################
075  #英語サイトのタイトル収集
076  set ocidOption to (refMe's NSXMLDocumentTidyHTML)
077  set listReadXMLDoc to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error| :(reference))
078  set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
079  if ocidReadXMLDoc = (missing value) then
080    set ocidHTno to (ocidHTno) as text
081    set ocidDocNo to ("NULL") as text
082    set strCanonicalURL to ("NULL") as text
083    set ocidTitleEN to ("NULL") as text
084    set strURLJP to ("NULL") as text
085    set ocidTitleJP to ("NULL") as text
086  else
087    set ocidRootElement to ocidReadXMLDoc's rootElement()
088    set ocidHeadElement to (ocidRootElement's elementsForName:("head"))'s firstObject()
089    #
090    set listResponse to (ocidHeadElement's nodesForXPath:("//title") |error| :(reference))
091    if (item 2 of listResponse) = (missing value) then
092      set ocidTitleNode to (item 1 of listResponse)'s firstObject()
093    else if (item 2 of listResponse) ≠ (missing value) then
094      set strErrorNO to (item 2 of listResponse)'s code() as text
095      set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
096      refMe's NSLog("■:" & strErrorNO & strErrorMes)
097      return "エラーしました" & strErrorNO & strErrorMes
098    end if
099    set ocidTitleEN to ocidTitleNode's stringValue()
100    #【2】USのタイトル
101    set ocidTitleEN to (ocidTitleEN's stringByReplacingOccurrencesOfString:(" - Apple Support") withString:(""))
102    #
103    set listResponse to (ocidHeadElement's nodesForXPath:("//link") |error| :(reference))
104    if (item 2 of listResponse) = (missing value) then
105      set ocidLinkNodeArray to (item 1 of listResponse)
106    else if (item 2 of listResponse) ≠ (missing value) then
107      set strErrorNO to (item 2 of listResponse)'s code() as text
108      set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
109      refMe's NSLog("■:" & strErrorNO & strErrorMes)
110      return "エラーしました" & strErrorNO & strErrorMes
111    end if
112    repeat with itemNode in ocidLinkNodeArray
113      set ocidAttrRel to (itemNode's attributeForName:("rel"))'s stringValue() as text
114      if ocidAttrRel is "canonical" then
115        set ocidCanonicalURL to (itemNode's attributeForName:("href"))
116        if ocidCanonicalURL ≠ (missing value) then
117          #【2】USの元URL
118          set strCanonicalURL to ocidCanonicalURL's stringValue() as text
119          set ocidCanonicalURLString to (refMe's NSString's stringWithString:(strCanonicalURL))
120          set ocidCanonicalURLEn to (refMe's NSURL's alloc()'s initWithString:(ocidCanonicalURLString))
121          #【1】DOC番号
122          set ocidDocNo to ocidCanonicalURLEn's lastPathComponent()
123        end if
124      else if ocidAttrRel is "alternate" then
125        set ocidCanonicalLang to (itemNode's attributeForName:("hreflang"))
126        if ocidCanonicalLang ≠ (missing value) then
127          set strCanonicalLang to ocidCanonicalLang's stringValue() as text
128        else
129          set strCanonicalURLJP to "NULL"
130        end if
131        #【3】日本語URL
132        if strCanonicalLang is "ja-jp" then
133          set strCanonicalURLJP to (itemNode's attributeForName:("href"))'s stringValue() as text
134        else
135          set strCanonicalURLJP to "NULL"
136        end if
137      end if
138    end repeat
139    #############################
140    #日本用のURLを生成
141    
142    if strCanonicalURLJP is "NULL" then
143      set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
144      (ocidURLComponents's setScheme:("https"))
145      (ocidURLComponents's setHost:("support.apple.com"))
146      (ocidURLComponents's setPath:("/kb/index"))
147      ##クエリー部
148      set ocidQueryItems to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0))
149      (ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("page") value:("search")))
150      (ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("locale") value:("ja_JP")))
151      (ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("includeArchived") value:("true")))
152      (ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("q") value:(ocidHTno)))
153      (ocidURLComponents's setQueryItems:(ocidQueryItems))
154      set ocidURLJP to ocidURLComponents's |URL|()
155      set strURLJP to ocidURLJP's absoluteString() as text
156    else
157      set ocidURLString to (refMe's NSString's stringWithString:(strCanonicalURLJP))
158      set ocidURLJP to (refMe's NSURL's alloc()'s initWithString:(ocidURLString))
159      set strURLJP to strCanonicalURLJP as text
160    end if
161    #
162    set ocidOption to (refMe's NSXMLDocumentTidyHTML)
163    set listReadXMLDoc to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidURLJP) options:(ocidOption) |error| :(reference))
164    set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
165    set ocidRootElement to ocidReadXMLDoc's rootElement()
166    set ocidHeadElement to (ocidRootElement's elementsForName:("head"))'s firstObject()
167    set listResponse to (ocidHeadElement's nodesForXPath:("//title") |error| :(reference))
168    if (item 2 of listResponse) = (missing value) then
169      set ocidTitleNode to (item 1 of listResponse)'s firstObject()
170    else if (item 2 of listResponse) ≠ (missing value) then
171      set strErrorNO to (item 2 of listResponse)'s code() as text
172      set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
173      refMe's NSLog("■:" & strErrorNO & strErrorMes)
174      return "エラーしました" & strErrorNO & strErrorMes
175    end if
176    #
177    set ocidTitleJP to ocidTitleNode's stringValue()
178    set ocidTitleJP to (ocidTitleJP's stringByReplacingOccurrencesOfString:(" - Apple サポート (日本)") withString:(""))
179  end if
180  #############################
181  #必要なデータは揃いました
182  log ocidHTno as text
183  (*
184  log ocidDocNo as text
185  log strCanonicalURL
186  log ocidTitleEN as text
187  
188  log strURLJP
189  log ocidTitleJP as text
190  *)
191  #レコードに格納して
192  set recordContents to {|HTNO|:(ocidHTno as text), |DOCNO|:(ocidDocNo as text), |ENURL|:(strURL as text), |CANOEN|:(strCanonicalURL as text), |TITLEEN|:(ocidTitleEN as text), |CANOJP|:(strURLJP as text), |TITLEJP|:(ocidTitleJP as text)} as record
193  #順番にリストにしていく
194  copy recordContents to end of listMakeHTML
195end repeat
196
197
198########################################
199#headerに渡すエレメント
200set ocidH3Element to (refMe's NSXMLElement's elementWithName:("h3"))
201(ocidH3Element's setStringValue:("Appleサポートドキュメント一覧"))
202########################################
203#footerに渡すエレメント
204set ocidFotterAElement to (refMe's NSXMLElement's elementWithName:("a"))
205set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
206(ocidFotterAElement's addAttribute:(ocidAddNode))
207set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
208(ocidFotterAElement's addAttribute:(ocidAddNode))
209set strContents to ("AppleScriptで生成しました") as text
210(ocidFotterAElement's setStringValue:(strContents))
211
212
213########################################
214#articleに渡すエレメント
215#テーブル部生成開始
216set ocidTableElement to refMe's NSXMLElement's elementWithName:("table")
217#【caption】
218set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption")
219set strJpDate to doGetDateNo("yyyy MM dd")
220set strSetValue to ("URL取得日: " & strJpDate) as text
221ocidCaptionElement's setStringValue:(strSetValue)
222ocidTableElement's addChild:(ocidCaptionElement)
223#【colgroup】
224set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup")
225#テーブルのタイトル部
226set listColName to {"行番号", "HtNo", "DocNo", "EnTitle", "JpTitle", "Link"} as list
227
228#タイトル部の数だけ繰り返し
229repeat with itemColName in listColName
230  #【col】col生成
231  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
232  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
233  (ocidAddElement's addAttribute:(ocidAddNode))
234  (ocidColgroupElement's addChild:(ocidAddElement))
235end repeat
236#テーブルエレメントに追加
237ocidTableElement's addChild:(ocidColgroupElement)
238#【thead】
239set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead")
240#TR
241set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
242#タイトル部の数だけ繰り返し
243repeat with itemColName in listColName
244  #ここはTDではなくてTHを利用
245  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
246  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
247  (ocidAddElement's addAttribute:(ocidAddNode))
248  #値を入れる
249  (ocidAddElement's setStringValue:(itemColName))
250  #TH→TRにセット
251  (ocidTrElement's addChild:(ocidAddElement))
252end repeat
253#TRをTHEADにセット
254ocidTheadElement's addChild:(ocidTrElement)
255#THEADをテーブルにセット
256ocidTableElement's addChild:(ocidTheadElement)
257########################################
258#【tbody】
259set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
260###【3-4】:item
261
262set numLineNO to 1 as integer
263
264repeat with itemArray in listMakeHTML
265  
266  set strHTNo to (|HTNO| of itemArray) as text
267  set strDOCNO to (|DOCNO| of itemArray) as text
268  set strENURL to (|ENURL| of itemArray) as text
269  set strCANOEN to (|CANOEN| of itemArray) as text
270  set strTITLEEN to (|TITLEEN| of itemArray) as text
271  set strCANOJP to (|CANOJP| of itemArray) as text
272  set strTITLEJP to (|TITLEJP| of itemArray) as text
273  (*
274  log strHTNO as text
275  log strDOCNO as text
276  log strENURL
277  log strTITLEEN as text
278  
279  log strCANOJP
280  log strTITLEJP as text
281  *)
282  #TRの開始
283  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
284  #【行番号】をTHでセット
285  set strZeroSupp to ("00") as text
286  set strZeroSupp to ("00" & numLineNO) as text
287  set strLineNO to (text -3 through -1 of strZeroSupp) as text
288  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
289  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("行番号"))
290  (ocidThElement's addAttribute:(ocidAddNode))
291  (ocidThElement's setStringValue:(strLineNO))
292  (ocidTrElement's addChild:(ocidThElement))
293  #【HtNo】をTDでセット
294  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
295  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("HtNo"))
296  (ocidTdElement's addAttribute:(ocidAddNode))
297  set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
298  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strENURL))
299  (ocidAElement's addAttribute:(ocidAddNode))
300  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
301  (ocidAElement's addAttribute:(ocidAddNode))
302  (ocidAElement's setStringValue:(strHTNo))
303  (ocidTdElement's addChild:(ocidAElement))
304  (ocidTrElement's addChild:(ocidTdElement))
305  
306  #【DOCNO】をTDでセット
307  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
308  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("DocNo"))
309  (ocidTdElement's addAttribute:(ocidAddNode))
310  if strDOCNO is not "NULL" then
311    set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
312    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strCANOEN))
313    (ocidAElement's addAttribute:(ocidAddNode))
314    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
315    (ocidAElement's addAttribute:(ocidAddNode))
316    (ocidAElement's setStringValue:(strDOCNO))
317    (ocidTdElement's addChild:(ocidAElement))
318  else
319    (ocidTdElement's setStringValue:(""))
320  end if
321  (ocidTrElement's addChild:(ocidTdElement))
322  
323  #【strTITLEEN】をTDでセット
324  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
325  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("EnTitle"))
326  (ocidTdElement's addAttribute:(ocidAddNode))
327  if strTITLEEN is not "NULL" then
328    (ocidTdElement's setStringValue:(strTITLEEN))
329  else
330    (ocidTdElement's setStringValue:(""))
331  end if
332  (ocidTrElement's addChild:(ocidTdElement))
333  
334  #【strTITLEJP】をTDでセット
335  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
336  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("JpTitle"))
337  (ocidTdElement's addAttribute:(ocidAddNode))
338  if strTITLEEN is not "NULL" then
339    (ocidTdElement's setStringValue:(strTITLEJP))
340  else
341    (ocidTdElement's setStringValue:(""))
342  end if
343  (ocidTrElement's addChild:(ocidTdElement))
344  
345  #【リンク】をTDでセット
346  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
347  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("Link"))
348  (ocidTdElement's addAttribute:(ocidAddNode))
349  if strCANOJP is not "NULL" then
350    set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
351    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strCANOJP))
352    (ocidAElement's addAttribute:(ocidAddNode))
353    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
354    (ocidAElement's addAttribute:(ocidAddNode))
355    (ocidAElement's setStringValue:("LINK"))
356    (ocidTdElement's addChild:(ocidAElement))
357  else
358    (ocidTdElement's setStringValue:(""))
359  end if
360  (ocidTrElement's addChild:(ocidTdElement))
361  
362  #出来上がったTRをTBODYにセット
363  (ocidTbodyElement's addChild:(ocidTrElement))
364  set numLineNO to numLineNO + 1 as integer
365end repeat
366#TBODYをテーブルにセット
367ocidTableElement's addChild:(ocidTbodyElement)
368#【tfoot】 TRで
369set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot")
370set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
371#項目数を取得して
372set numCntCol to (count of listColName) as integer
373#colspan指定して1行でセット
374set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
375set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
376(ocidThElement's addAttribute:(ocidAddNode))
377set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
378(ocidThElement's addAttribute:(ocidAddNode))
379set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
380(ocidThElement's addAttribute:(ocidAddNode))
381#
382set ocidTfotterAElement to refMe's NSXMLElement's elementWithName:("a")
383set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://support.apple.com"))
384(ocidTfotterAElement's addAttribute:(ocidAddNode))
385set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
386(ocidTfotterAElement's addAttribute:(ocidAddNode))
387set strContents to ("AppleサポートTOP") as text
388(ocidTfotterAElement's setStringValue:(strContents))
389ocidThElement's addChild:(ocidTfotterAElement)
390#THをTRにセットして
391ocidTrElement's addChild:(ocidThElement)
392#TRをTFOOTにセット
393ocidTfootElement's addChild:(ocidTrElement)
394#TFOOTをテーブルにセット
395ocidTableElement's addChild:(ocidTfootElement)
396
397##############################
398#HTMLにする
399##############################
400set ocidHTML to doMakeRootElement({ocidH3Element, ocidTableElement, ocidFotterAElement})
401
402##############################
403#保存
404##############################
405###【5−2】保存
406#読み取りやすい表示
407set ocidXMLdata to ocidHTML's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
408
409set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference)
410
411###ブラウザで開く
412set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
413tell application "Finder"
414  open location aliasFilePath
415end tell
416
417###保存先を開く
418set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
419set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
420
421
422
423##############################
424# 基本的なHTMLの構造
425(*
426doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents})
427HTMLのBODY部
428header
429article
430footerにそれぞれAddchildするデータをリストで渡す
431戻り値はRootエレメントにセットされた
432NSXMLDocumentを戻すので 保存すればOK
433*)
434##############################
435to doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents})
436  #XML初期化
437  set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
438  ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)
439  # DTD付与
440  set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
441  ocidDTD's setName:("html")
442  ocidXMLDoc's setDTD:(ocidDTD)
443  #
444  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
445  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
446  ocidRootElement's addAttribute:(ocidAddNode)
447  #
448  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
449  #
450  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
451  ocidAddElement's setStringValue:("RSS一覧")
452  ocidHeadElement's addChild:(ocidAddElement)
453  # http-equiv
454  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
455  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
456  ocidAddElement's addAttribute:(ocidAddNode)
457  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
458  ocidAddElement's addAttribute:(ocidAddNode)
459  ocidHeadElement's addChild:(ocidAddElement)
460  #
461  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
462  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type")
463  ocidAddElement's addAttribute:(ocidAddNode)
464  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css")
465  ocidAddElement's addAttribute:(ocidAddNode)
466  ocidHeadElement's addChild:(ocidAddElement)
467  #
468  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
469  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type")
470  ocidAddElement's addAttribute:(ocidAddNode)
471  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript")
472  ocidAddElement's addAttribute:(ocidAddNode)
473  ocidHeadElement's addChild:(ocidAddElement)
474  #
475  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
476  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
477  ocidAddElement's addAttribute:(ocidAddNode)
478  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
479  ocidAddElement's addAttribute:(ocidAddNode)
480  ocidHeadElement's addChild:(ocidAddElement)
481  #
482  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
483  ocidAddElement's setStringValue:("body { margin: 10px; background-color: #FFFFFF; } table { border-spacing: 0; caption-side: top; font-family: system-ui; } thead th { border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:first-of-type { border-start-start-radius: .5em } &:last-of-type { border-start-end-radius: .5em; border-inline-end-width: 1px } } tbody td { word-wrap: break-word;max-width: 360px;border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:last-of-type { border-inline-end-width: 1px } } tbody th { border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; } tbody tr:nth-of-type(odd) { background: #F2F2F2; } .kind_string { font-size: 0.75em; } .date_string { font-size: 0.5em; } tfoot th { border: solid 1px #666666; padding: .5ch 1ch; &:first-of-type { border-end-start-radius: .5em } &:last-of-type { border-end-end-radius: .5em; border-inline-end-width: 1px } }")
484  ocidHeadElement's addChild:(ocidAddElement)
485  ocidRootElement's addChild:(ocidHeadElement)
486  #
487  #ボディエレメント
488  set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body")
489  #ヘッダー
490  set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header")
491  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")
492  ocidHeaderElement's addAttribute:(ocidAddNode)
493  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")
494  ocidHeaderElement's addAttribute:(ocidAddNode)
495  ocidHeaderElement's addChild:(argHeaderContents)
496  ocidBodyElement's addChild:(ocidHeaderElement)
497  #アーティクル
498  set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article")
499  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")
500  ocidArticleElement's addAttribute:(ocidAddNode)
501  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")
502  ocidArticleElement's addAttribute:(ocidAddNode)
503  ocidArticleElement's addChild:(argArticleContents)
504  ocidBodyElement's addChild:(ocidArticleElement)
505  #フッター
506  set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer")
507  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")
508  ocidFooterElement's addAttribute:(ocidAddNode)
509  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")
510  ocidFooterElement's addAttribute:(ocidAddNode)
511  ocidFooterElement's addChild:(argFooterContents)
512  ocidBodyElement's addChild:(ocidFooterElement)
513  
514  ocidRootElement's addChild:(ocidBodyElement)
515  ocidXMLDoc's setRootElement:(ocidRootElement)
516  return ocidXMLDoc
517end doMakeRootElement
518
519
520
521##########################################
522####日付情報の取得
523##########################################
524to doGetDateNo(strDateFormat)
525  ####日付情報の取得
526  set ocidDate to refMe's NSDate's |date|()
527  ###日付のフォーマットを定義
528  set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init()
529  ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"en_US")
530  ocidNSDateFormatter's setDateFormat:strDateFormat
531  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
532  set strDateAndTime to ocidDateAndTime as text
533  return strDateAndTime
534end doGetDateNo
AppleScriptで生成しました

|

Appleのサポート文書のタイトルとリンクを取得してHTML表示する

URL取得日: 2024 09 01
行番号HtNoDocNoEnTitleJpTitleLink
001HT214081120893About the security content of iOS 17.4 and iPadOS 17.4iOS 17.4 および iPadOS 17.4 のセキュリティコンテンツについてLINK
002HT214082120880About the security content of iOS 16.7.6 and iPadOS 16.7.6iOS 16.7.6 および iPadOS 16.7.6 のセキュリティコンテンツについてLINK
003HT214083120884About the security content of macOS Monterey 12.7.4macOS Monterey 12.7.4 のセキュリティコンテンツについてLINK
004HT214084120895About the security content of macOS Sonoma 14.4macOS Sonoma 14.4 のセキュリティコンテンツについてLINK
005HT214085120886About the security content of macOS Ventura 13.6.5macOS Ventura 13.6.5 のセキュリティコンテンツについてLINK
006HT214086120882About the security content of tvOS 17.4tvOS 17.4 のセキュリティコンテンツについてLINK
007HT214087120883About the security content of visionOS 1.1visionOS 1.1 のセキュリティコンテンツについてLINK
008HT214088120881About the security content of watchOS 10.4watchOS 10.4 のセキュリティコンテンツについてLINK
009HT214089120894About the security content of Safari 17.4Safari 17.4 のセキュリティコンテンツについてLINK
010HT214090120885About the security content of GarageBand 10.4.11GarageBand 10.4.11 のセキュリティコンテンツについてLINK
011HT214091120313About the security content of iTunes 12.13.1 for WindowsiTunes for Windows 12.13.1 のセキュリティコンテンツについてLINK
012HT214092120887About the security content of Xcode 15.3Xcode 15.3 のセキュリティコンテンツについてLINK
013HT214093120312About the security content of visionOS 1.1.1visionOS 1.1.1 のセキュリティコンテンツについてLINK
014HT214094120888About the security content of Safari 17.4.1Safari 17.4.1 のセキュリティコンテンツについてLINK
015HT214095120891About the security content of macOS Ventura 13.6.6macOS Ventura 13.6.6 のセキュリティコンテンツについてLINK
016HT214096120889About the security content of macOS Sonoma 14.4.1macOS Sonoma 14.4.1 のセキュリティコンテンツについてLINK
017HT214097120890About the security content of iOS 17.4.1 and iPadOS 17.4.1iOS 17.4.1 および iPadOS 17.4.1 のセキュリティコンテンツについてLINK
018HT214098120892About the security content of iOS 16.7.7 and iPadOS 16.7.7iOS 16.7.7 および iPadOS 16.7.7 のセキュリティコンテンツについてLINK
019HT214099120897About the security content of iTunes 12.13.2 for WindowsiTunes for Windows 12.13.2 のセキュリティコンテンツについてLINK
020HT214100120898About the security content of iOS 16.7.8 and iPadOS 16.7.8iOS 16.7.8 および iPadOS 16.7.8 のセキュリティコンテンツについてLINK
021HT214101120905About the security content of iOS 17.5 and iPadOS 17.5iOS 17.5 および iPadOS 17.5 のセキュリティコンテンツについてLINK
022HT214102120901About the security content of tvOS 17.5tvOS 17.5 のセキュリティコンテンツについてLINK
023HT214103120896About the security content of Safari 17.5Safari 17.5 のセキュリティコンテンツについてLINK
024HT214104120902About the security content of watchOS 10.5watchOS 10.5 のセキュリティコンテンツについてLINK
025HT214105120899About the security content of macOS Monterey 12.7.5macOS Monterey 12.7.5 のセキュリティコンテンツについてLINK
026HT214106120903About the security content of macOS Sonoma 14.5macOS Sonoma 14.5 のセキュリティコンテンツについてLINK
027HT214107120900About the security content of macOS Ventura 13.6.7macOS Ventura 13.6.7 のセキュリティコンテンツについてLINK
028HT214108120906About the security content of visionOS 1.2visionOS 1.2 のセキュリティコンテンツについてLINK
029HT214109
030HT214110
031HT214111120907About the security content of AirPods Firmware Update 6A326, AirPods Firmware Update 6F8, and Beats Firmware Update 6F8AirPods ファームウェアアップデート 6A326、AirPods ファームウェアアップデート 6F8、Beats ファームウェアアップデート 6F8 のセキュリティコンテンツについてLINK
032HT214112
033HT214113
034HT214114
035HT214115
036HT214116120908About the security content of iOS 16.7.9 and iPadOS 16.7.9iOS 16.7.9 および iPadOS 16.7.9 のセキュリティコンテンツについてLINK
037HT214117120909About the security content of iOS 17.6 and iPadOS 17.6iOS 17.6 および iPadOS 17.6 のセキュリティコンテンツについてLINK
038HT214118120910About the security content of macOS Monterey 12.7.6macOS Monterey 12.7.6 のセキュリティコンテンツについてLINK
039HT214119120911About the security content of macOS Sonoma 14.6macOS Sonoma 14.6 のセキュリティコンテンツについてLINK
040HT214120120912About the security content of macOS Ventura 13.6.8macOS Ventura 13.6.8 のセキュリティコンテンツについてLINK
041HT214121120913About the security content of Safari 17.6Safari 17.6 のセキュリティコンテンツについてLINK
042HT214122120914About the security content of tvOS 17.6tvOS 17.6 のセキュリティコンテンツについてLINK
043HT214123120915About the security content of visionOS 1.3visionOS 1.3 のセキュリティコンテンツについてLINK
044HT214124120916About the security content of watchOS 10.6watchOS 10.6 のセキュリティコンテンツについてLINK
045HT214125
046HT214126
047HT214127
048HT214128
049HT214129
050HT214130
AppleサポートTOP



ダウンロード - getapplesupporttitle.zip




AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#com.cocolog-nifty.quicktimer.icefloe
005# Appleサポート用にカスタマイズしていますので
006# 一般的なサイトでは利用できません
007# dataフォルダ内にあるURL_LIST.txtのURLを順番に処理します
008#
009----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
010use AppleScript version "2.8"
011use framework "Foundation"
012use framework "AppKit"
013use scripting additions
014property refMe : a reference to current application
015
016############
017#URLリスト
018set aliasPathToMe to (path to me) as alias
019set strPathToMe to (POSIX path of aliasPathToMe) as text
020set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe)
021set ocidPathToMePath to ocidPathToMeStr's stringByStandardizingPath()
022set ocidPathToMeURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMePath) isDirectory:false)
023#
024set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent()
025set ocidURLlistFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("data/URL_LIST.txt") isDirectory:(false)
026#URLリスト読み込み
027set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidURLlistFilePathURL) usedEncoding:(refMe's NSUTF8StringEncoding) |error| :(reference)
028if (item 2 of listResponse) = (missing value) then
029  set ocidURLlistString to (item 1 of listResponse)
030else if (item 2 of listResponse) ≠ (missing value) then
031  set strErrorNO to (item 2 of listResponse)'s code() as text
032  set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
033  refMe's NSLog("■:" & strErrorNO & strErrorMes)
034  return "エラーしました" & strErrorNO & strErrorMes
035end if
036#UNIX改行を強制
037set ocidTextM to ocidURLlistString's stringByReplacingOccurrencesOfString:("\r") withString:("\n")
038set ocidTextTM to ocidTextM's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n")
039##タブ除去
040set ocidURLlistString to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("")
041#文末の改行(要素としては空になるので)除去しておく
042set ocidListlenge to ocidURLlistString's |length|()
043set ocidLastChar to ocidURLlistString's substringFromIndex:(ocidListlenge - 1)
044if (ocidLastChar as text) is "\n" then
045  set ocidLastCharRange to refMe's NSRange's NSMakeRange((ocidListlenge - 1), 1)
046  set ocidURLlistString to ocidURLlistString's stringByReplacingCharactersInRange:(ocidLastCharRange) withString:("")
047end if
048
049############
050set appFileManager to refMe's NSFileManager's defaultManager()
051#保存先確保
052set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser()
053set ocidSaveDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:("Sites/LinkMaker") isDirectory:(true)
054set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
055ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
056set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error| :(reference)
057if (item 1 of listDone) is false then
058  set strErrorNO to (item 2 of listDone)'s code() as text
059  set strErrorMes to (item 2 of listDone)'s localizedDescription() as text
060  refMe's NSLog("■:" & strErrorNO & strErrorMes)
061  return "エラーしました" & strErrorNO & strErrorMes
062end if
063#保存ファイルURL
064set strDateNo to doGetDateNo("yyyyMMdd_hhmm")
065set strSaveFileName to ("linkmaker_" & strDateNo & ".html") as text
066set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false)
067############
068#URLリストをArrayに
069set ocidURLArray to ocidURLlistString's componentsSeparatedByString:("\n")
070############
071#HTML生成用に渡すlist
072set listMakeHTML to {} as list
073
074#URLの数だけ繰り返し
075repeat with itemArray in ocidURLArray
076  #対象のURL
077  set strURL to itemArray as text
078  set ocidURLString to (refMe's NSString's stringWithString:(strURL))
079  set ocidURL to (refMe's NSURL's alloc()'s initWithString:(ocidURLString))
080  #【1】HT番号
081  set ocidHTno to ocidURL's lastPathComponent()
082  #【2】USの参照URL
083  set strURLEN to ocidURL's absoluteString() as text
084  #############################
085  #英語サイトのタイトル収集
086  set ocidOption to (refMe's NSXMLDocumentTidyHTML)
087  set listReadXMLDoc to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error| :(reference))
088  set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
089  if ocidReadXMLDoc = (missing value) then
090    set ocidHTno to (ocidHTno) as text
091    set ocidDocNo to ("NULL") as text
092    set strCanonicalURL to ("NULL") as text
093    set ocidTitleEN to ("NULL") as text
094    set strURLJP to ("NULL") as text
095    set ocidTitleJP to ("NULL") as text
096  else
097    set ocidRootElement to ocidReadXMLDoc's rootElement()
098    set ocidHeadElement to (ocidRootElement's elementsForName:("head"))'s firstObject()
099    #
100    set listResponse to (ocidHeadElement's nodesForXPath:("//title") |error| :(reference))
101    if (item 2 of listResponse) = (missing value) then
102      set ocidTitleNode to (item 1 of listResponse)'s firstObject()
103    else if (item 2 of listResponse) ≠ (missing value) then
104      set strErrorNO to (item 2 of listResponse)'s code() as text
105      set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
106      refMe's NSLog("■:" & strErrorNO & strErrorMes)
107      return "エラーしました" & strErrorNO & strErrorMes
108    end if
109    set ocidTitleEN to ocidTitleNode's stringValue()
110    #【2】USのタイトル
111    set ocidTitleEN to (ocidTitleEN's stringByReplacingOccurrencesOfString:(" - Apple Support") withString:(""))
112    #
113    set listResponse to (ocidHeadElement's nodesForXPath:("//link") |error| :(reference))
114    if (item 2 of listResponse) = (missing value) then
115      set ocidLinkNodeArray to (item 1 of listResponse)
116    else if (item 2 of listResponse) ≠ (missing value) then
117      set strErrorNO to (item 2 of listResponse)'s code() as text
118      set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
119      refMe's NSLog("■:" & strErrorNO & strErrorMes)
120      return "エラーしました" & strErrorNO & strErrorMes
121    end if
122    repeat with itemNode in ocidLinkNodeArray
123      set ocidAttrRel to (itemNode's attributeForName:("rel"))'s stringValue() as text
124      if ocidAttrRel is "canonical" then
125        set ocidCanonicalURL to (itemNode's attributeForName:("href"))
126        if ocidCanonicalURL ≠ (missing value) then
127          #【2】USの元URL
128          set strCanonicalURL to ocidCanonicalURL's stringValue() as text
129          set ocidCanonicalURLString to (refMe's NSString's stringWithString:(strCanonicalURL))
130          set ocidCanonicalURLEn to (refMe's NSURL's alloc()'s initWithString:(ocidCanonicalURLString))
131          #【1】DOC番号
132          set ocidDocNo to ocidCanonicalURLEn's lastPathComponent()
133        end if
134      else if ocidAttrRel is "alternate" then
135        set ocidCanonicalLang to (itemNode's attributeForName:("hreflang"))
136        if ocidCanonicalLang ≠ (missing value) then
137          set strCanonicalLang to ocidCanonicalLang's stringValue() as text
138        end if
139        #【3】日本語URL
140        if strCanonicalLang is "ja-jp" then
141          set strCanonicalURLJP to (itemNode's attributeForName:("href"))'s stringValue() as text
142        end if
143      end if
144    end repeat
145    #############################
146    #日本用のURLを生成
147    
148    if strCanonicalURLJP is "" then
149      set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
150      (ocidURLComponents's setScheme:("https"))
151      (ocidURLComponents's setHost:("support.apple.com"))
152      (ocidURLComponents's setPath:("/kb/index"))
153      ##クエリー部
154      set ocidQueryItems to (refMe's NSMutableArray's alloc()'s initWithCapacity:(0))
155      (ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("page") value:("search")))
156      (ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("locale") value:("ja_JP")))
157      (ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("includeArchived") value:("true")))
158      (ocidQueryItems's addObject:(refMe's NSURLQueryItem's alloc()'s initWithName:("q") value:(ocidHTno)))
159      (ocidURLComponents's setQueryItems:(ocidQueryItems))
160      set ocidURLJP to ocidURLComponents's |URL|()
161      set strURLJP to ocidURLJP's absoluteString() as text
162    else
163      set ocidURLString to (refMe's NSString's stringWithString:(strCanonicalURLJP))
164      set ocidURLJP to (refMe's NSURL's alloc()'s initWithString:(ocidURLString))
165      set strURLJP to strCanonicalURLJP as text
166    end if
167    #
168    set ocidOption to (refMe's NSXMLDocumentTidyHTML)
169    set listReadXMLDoc to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidURLJP) options:(ocidOption) |error| :(reference))
170    set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
171    set ocidRootElement to ocidReadXMLDoc's rootElement()
172    set ocidHeadElement to (ocidRootElement's elementsForName:("head"))'s firstObject()
173    set listResponse to (ocidHeadElement's nodesForXPath:("//title") |error| :(reference))
174    if (item 2 of listResponse) = (missing value) then
175      set ocidTitleNode to (item 1 of listResponse)'s firstObject()
176    else if (item 2 of listResponse) ≠ (missing value) then
177      set strErrorNO to (item 2 of listResponse)'s code() as text
178      set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text
179      refMe's NSLog("■:" & strErrorNO & strErrorMes)
180      return "エラーしました" & strErrorNO & strErrorMes
181    end if
182    #
183    set ocidTitleJP to ocidTitleNode's stringValue()
184    set ocidTitleJP to (ocidTitleJP's stringByReplacingOccurrencesOfString:(" - Apple サポート (日本)") withString:(""))
185  end if
186  #############################
187  #必要なデータは揃いました
188  log ocidHTno as text
189    (*
190  log ocidDocNo as text
191  log strCanonicalURL
192  log ocidTitleEN as text
193  
194  log strURLJP
195  log ocidTitleJP as text
196  *)
197  #レコードに格納して
198  set recordContents to {|HTNO|:(ocidHTno as text), |DOCNO|:(ocidDocNo as text), |ENURL|:(strURL as text), |CANOEN|:(strCanonicalURL as text), |TITLEEN|:(ocidTitleEN as text), |CANOJP|:(strURLJP as text), |TITLEJP|:(ocidTitleJP as text)} as record
199  #順番にリストにしていく
200  copy recordContents to end of listMakeHTML
201end repeat
202
203
204########################################
205#headerに渡すエレメント
206set ocidH3Element to (refMe's NSXMLElement's elementWithName:("h3"))
207(ocidH3Element's setStringValue:("Appleサポートドキュメント一覧"))
208########################################
209#footerに渡すエレメント
210set ocidFotterAElement to (refMe's NSXMLElement's elementWithName:("a"))
211set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
212(ocidFotterAElement's addAttribute:(ocidAddNode))
213set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
214(ocidFotterAElement's addAttribute:(ocidAddNode))
215set strContents to ("AppleScriptで生成しました") as text
216(ocidFotterAElement's setStringValue:(strContents))
217
218
219########################################
220#articleに渡すエレメント
221#テーブル部生成開始
222set ocidTableElement to refMe's NSXMLElement's elementWithName:("table")
223#【caption】
224set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption")
225set strJpDate to doGetDateNo("yyyy MM dd")
226set strSetValue to ("URL取得日: " & strJpDate) as text
227ocidCaptionElement's setStringValue:(strSetValue)
228ocidTableElement's addChild:(ocidCaptionElement)
229#【colgroup】
230set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup")
231#テーブルのタイトル部
232set listColName to {"行番号", "HtNo", "DocNo", "EnTitle", "JpTitle", "Link"} as list
233
234#タイトル部の数だけ繰り返し
235repeat with itemColName in listColName
236  #【col】col生成
237  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
238  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
239  (ocidAddElement's addAttribute:(ocidAddNode))
240  (ocidColgroupElement's addChild:(ocidAddElement))
241end repeat
242#テーブルエレメントに追加
243ocidTableElement's addChild:(ocidColgroupElement)
244#【thead】
245set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead")
246#TR
247set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
248#タイトル部の数だけ繰り返し
249repeat with itemColName in listColName
250  #ここはTDではなくてTHを利用
251  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
252  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
253  (ocidAddElement's addAttribute:(ocidAddNode))
254  #値を入れる
255  (ocidAddElement's setStringValue:(itemColName))
256  #TH→TRにセット
257  (ocidTrElement's addChild:(ocidAddElement))
258end repeat
259#TRをTHEADにセット
260ocidTheadElement's addChild:(ocidTrElement)
261#THEADをテーブルにセット
262ocidTableElement's addChild:(ocidTheadElement)
263########################################
264#【tbody】
265set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
266###【3-4】:item
267
268set numLineNO to 1 as integer
269
270repeat with itemArray in listMakeHTML
271  
272  set strHTNO to (|HTNO| of itemArray) as text
273  set strDOCNO to (|DOCNO| of itemArray) as text
274  set strENURL to (|ENURL| of itemArray) as text
275  set strCANOEN to (|CANOEN| of itemArray) as text
276  set strTITLEEN to (|TITLEEN| of itemArray) as text
277  set strCANOJP to (|CANOJP| of itemArray) as text
278  set strTITLEJP to (|TITLEJP| of itemArray) as text
279  (*
280  log strHTNO as text
281  log strDOCNO as text
282  log strENURL
283  log strTITLEEN as text
284  
285  log strCANOJP
286  log strTITLEJP as text
287  *)
288  #TRの開始
289  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
290  #【行番号】をTHでセット
291  set strZeroSupp to ("00") as text
292  set strZeroSupp to ("00" & numLineNO) as text
293  set strLineNO to (text -3 through -1 of strZeroSupp) as text
294  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
295  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("行番号"))
296  (ocidThElement's addAttribute:(ocidAddNode))
297  (ocidThElement's setStringValue:(strLineNO))
298  (ocidTrElement's addChild:(ocidThElement))
299  #【HtNo】をTDでセット
300  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
301  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("HtNo"))
302  (ocidTdElement's addAttribute:(ocidAddNode))
303  set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
304  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strENURL))
305  (ocidAElement's addAttribute:(ocidAddNode))
306  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
307  (ocidAElement's addAttribute:(ocidAddNode))
308  (ocidAElement's setStringValue:(strHTNO))
309  (ocidTdElement's addChild:(ocidAElement))
310  (ocidTrElement's addChild:(ocidTdElement))
311  
312  #【DOCNO】をTDでセット
313  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
314  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("DocNo"))
315  (ocidTdElement's addAttribute:(ocidAddNode))
316  if strDOCNO is not "NULL" then
317    set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
318    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strCANOEN))
319    (ocidAElement's addAttribute:(ocidAddNode))
320    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
321    (ocidAElement's addAttribute:(ocidAddNode))
322    (ocidAElement's setStringValue:(strDOCNO))
323    (ocidTdElement's addChild:(ocidAElement))
324  else
325    (ocidTdElement's setStringValue:(""))
326  end if
327  (ocidTrElement's addChild:(ocidTdElement))
328  
329  #【strTITLEEN】をTDでセット
330  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
331  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("EnTitle"))
332  (ocidTdElement's addAttribute:(ocidAddNode))
333  if strTITLEEN is not "NULL" then
334    (ocidTdElement's setStringValue:(strTITLEEN))
335  else
336    (ocidTdElement's setStringValue:(""))
337  end if
338  (ocidTrElement's addChild:(ocidTdElement))
339  
340  #【strTITLEJP】をTDでセット
341  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
342  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("JpTitle"))
343  (ocidTdElement's addAttribute:(ocidAddNode))
344  if strTITLEEN is not "NULL" then
345    (ocidTdElement's setStringValue:(strTITLEJP))
346  else
347    (ocidTdElement's setStringValue:(""))
348  end if
349  (ocidTrElement's addChild:(ocidTdElement))
350  
351  #【リンク】をTDでセット
352  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
353  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("Link"))
354  (ocidTdElement's addAttribute:(ocidAddNode))
355  if strCANOJP is not "NULL" then
356    set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
357    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strCANOJP))
358    (ocidAElement's addAttribute:(ocidAddNode))
359    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
360    (ocidAElement's addAttribute:(ocidAddNode))
361    (ocidAElement's setStringValue:("LINK"))
362    (ocidTdElement's addChild:(ocidAElement))
363  else
364    (ocidTdElement's setStringValue:(""))
365  end if
366  (ocidTrElement's addChild:(ocidTdElement))
367  
368  #出来上がったTRをTBODYにセット
369  (ocidTbodyElement's addChild:(ocidTrElement))
370  set numLineNO to numLineNO + 1 as integer
371end repeat
372#TBODYをテーブルにセット
373ocidTableElement's addChild:(ocidTbodyElement)
374#【tfoot】 TRで
375set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot")
376set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
377#項目数を取得して
378set numCntCol to (count of listColName) as integer
379#colspan指定して1行でセット
380set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
381set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
382(ocidThElement's addAttribute:(ocidAddNode))
383set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
384(ocidThElement's addAttribute:(ocidAddNode))
385set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
386(ocidThElement's addAttribute:(ocidAddNode))
387#
388set ocidTfotterAElement to refMe's NSXMLElement's elementWithName:("a")
389set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://support.apple.com"))
390(ocidTfotterAElement's addAttribute:(ocidAddNode))
391set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
392(ocidTfotterAElement's addAttribute:(ocidAddNode))
393set strContents to ("AppleサポートTOP") as text
394(ocidTfotterAElement's setStringValue:(strContents))
395ocidThElement's addChild:(ocidTfotterAElement)
396#THをTRにセットして
397ocidTrElement's addChild:(ocidThElement)
398#TRをTFOOTにセット
399ocidTfootElement's addChild:(ocidTrElement)
400#TFOOTをテーブルにセット
401ocidTableElement's addChild:(ocidTfootElement)
402
403##############################
404#HTMLにする
405##############################
406set ocidHTML to doMakeRootElement({ocidH3Element, ocidTableElement, ocidFotterAElement})
407
408##############################
409#保存
410##############################
411###【5−2】保存
412#読み取りやすい表示
413set ocidXMLdata to ocidHTML's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
414
415set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference)
416
417###ブラウザで開く
418set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
419tell application "Finder"
420  open location aliasFilePath
421end tell
422
423###保存先を開く
424set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
425set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL)
426
427
428
429##############################
430# 基本的なHTMLの構造
431(*
432doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents})
433HTMLのBODY部
434header
435article
436footerにそれぞれAddchildするデータをリストで渡す
437戻り値はRootエレメントにセットされた
438NSXMLDocumentを戻すので 保存すればOK
439*)
440##############################
441to doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents})
442  #XML初期化
443  set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
444  ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)
445  # DTD付与
446  set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
447  ocidDTD's setName:("html")
448  ocidXMLDoc's setDTD:(ocidDTD)
449  #
450  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
451  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
452  ocidRootElement's addAttribute:(ocidAddNode)
453  #
454  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
455  #
456  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
457  ocidAddElement's setStringValue:("RSS一覧")
458  ocidHeadElement's addChild:(ocidAddElement)
459  # http-equiv
460  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
461  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
462  ocidAddElement's addAttribute:(ocidAddNode)
463  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
464  ocidAddElement's addAttribute:(ocidAddNode)
465  ocidHeadElement's addChild:(ocidAddElement)
466  #
467  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
468  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type")
469  ocidAddElement's addAttribute:(ocidAddNode)
470  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css")
471  ocidAddElement's addAttribute:(ocidAddNode)
472  ocidHeadElement's addChild:(ocidAddElement)
473  #
474  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
475  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type")
476  ocidAddElement's addAttribute:(ocidAddNode)
477  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript")
478  ocidAddElement's addAttribute:(ocidAddNode)
479  ocidHeadElement's addChild:(ocidAddElement)
480  #
481  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
482  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
483  ocidAddElement's addAttribute:(ocidAddNode)
484  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
485  ocidAddElement's addAttribute:(ocidAddNode)
486  ocidHeadElement's addChild:(ocidAddElement)
487  #
488  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
489  ocidAddElement's setStringValue:("body { margin: 10px; background-color: #FFFFFF; } table { border-spacing: 0; caption-side: top; font-family: system-ui; } thead th { border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:first-of-type { border-start-start-radius: .5em } &:last-of-type { border-start-end-radius: .5em; border-inline-end-width: 1px } } tbody td { word-wrap: break-word;max-width: 360px;border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:last-of-type { border-inline-end-width: 1px } } tbody th { border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; } tbody tr:nth-of-type(odd) { background: #F2F2F2; } .kind_string { font-size: 0.75em; } .date_string { font-size: 0.5em; } tfoot th { border: solid 1px #666666; padding: .5ch 1ch; &:first-of-type { border-end-start-radius: .5em } &:last-of-type { border-end-end-radius: .5em; border-inline-end-width: 1px } }")
490  ocidHeadElement's addChild:(ocidAddElement)
491  ocidRootElement's addChild:(ocidHeadElement)
492  #
493  #ボディエレメント
494  set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body")
495  #ヘッダー
496  set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header")
497  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")
498  ocidHeaderElement's addAttribute:(ocidAddNode)
499  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")
500  ocidHeaderElement's addAttribute:(ocidAddNode)
501  ocidHeaderElement's addChild:(argHeaderContents)
502  ocidBodyElement's addChild:(ocidHeaderElement)
503  #アーティクル
504  set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article")
505  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")
506  ocidArticleElement's addAttribute:(ocidAddNode)
507  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")
508  ocidArticleElement's addAttribute:(ocidAddNode)
509  ocidArticleElement's addChild:(argArticleContents)
510  ocidBodyElement's addChild:(ocidArticleElement)
511  #フッター
512  set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer")
513  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")
514  ocidFooterElement's addAttribute:(ocidAddNode)
515  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")
516  ocidFooterElement's addAttribute:(ocidAddNode)
517  ocidFooterElement's addChild:(argFooterContents)
518  ocidBodyElement's addChild:(ocidFooterElement)
519  
520  ocidRootElement's addChild:(ocidBodyElement)
521  ocidXMLDoc's setRootElement:(ocidRootElement)
522  return ocidXMLDoc
523end doMakeRootElement
524
525
526
527##########################################
528####日付情報の取得
529##########################################
530to doGetDateNo(strDateFormat)
531  ####日付情報の取得
532  set ocidDate to refMe's NSDate's |date|()
533  ###日付のフォーマットを定義
534  set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init()
535  ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"en_US")
536  ocidNSDateFormatter's setDateFormat:strDateFormat
537  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
538  set strDateAndTime to ocidDateAndTime as text
539  return strDateAndTime
540end doGetDateNo
AppleScriptで生成しました

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom