-
do shell script
と違って文字数制限がないので使いやすい - 文字化けする場合は
dataUsingEncoding:
メソッドの引数を変更
convertHTMLToPlainText.scpt
use scripting additions
use framework "AppKit"
tell application "Safari"
my convertHTMLToPlainText(source of current tab of window 1)
end tell
on convertHTMLToPlainText(HTML)
--require framework: Foundation
set attributedString to my attributedStringOfHTMLText(HTML)
return attributedString's |string| as text
end convertHTMLToPlainText
on attributedStringOfHTMLText(HTML as text)
--require framework: AppKit, Foundation
set HTMLString to current application's NSString's stringWithString:HTML
set HTMLData to HTMLString's dataUsingEncoding:(current application's NSUnicodeStringEncoding)
return current application's NSAttributedString's alloc()'s initWithHTML:HTMLData documentAttributes:(missing value)
end attributedStringOfHTMLText
更新履歴
- 2016-01-27: CocoaのAppKitフレームワークにあるNSAttributedStringクラスを使って作成
- 2016-02-01:
attributedStringOfHTMLText
ハンドラ作成