« 単位換算 詰め合わせ 2024-1 | トップページ | ブランクのPDFを生成するmm指定 大きく変更 »

[Fonts]Microsoft Officeの付属フォントのGDIファミリー名一覧 を取得する(ちょっと修正)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# ダイアログでfontsGDIFamilyNames.plistを選んでください
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKIt"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

########################################
#######ファイル選択
---プロンプトの文言改行が使えます\nを入れます
set theWithPrompt to "ファイルを選択してください"
---ファイル選択ダイアログのデフォルトのディレクトリ
try
  set aliasDefaultLocation to (POSIX file "/Applications/Microsoft PowerPoint.app/Contents/Resources") as alias
on error
return "Microsoft Officeをインストールしてないとファイルがないです"
end try

set theFileTypeList to {"com.apple.property-list"}
---ダイアログを出して選択されたファイルは「open」に渡す
set aliasFilePath to (choose file default location aliasDefaultLocation ¬
  with prompt theWithPrompt ¬
  of type theFileTypeList ¬
invisibles false ¬
  with showing package contents without multiple selections allowed) as alias
####入力ファイル関連
set strFilePath to POSIX path of aliasFilePath as text
###NSストリングに
set ocidFilePath to refMe's NSString's stringWithString:strFilePath
###NSURLに
set ocidFilePathURL to refMe's NSURL's fileURLWithPath:ocidFilePath
##ファイル名取得
set strFileName to (ocidFilePathURL's lastPathComponent) as text

########################################
######出力ファイル
##ファイル名
set strFileName to (strFileName & ".html") as text
set aliasSaveFilePath to choose file name with prompt "htmlのファイル名を付けてください" default name strFileName default location (aliasDefaultLocation)
###パス
set strSaveFilePath to POSIX path of aliasSaveFilePath as text
###NSストリングに
set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
###NSURLに
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
##拡張子
set strFileExtension to (ocidFilePathURL's pathExtension) as text
###拡張子つけ忘れ対策
if strFileExtension is not "html" then
  set strSaveFilePath to (POSIX path of aliasSaveFilePath & ".html") as text
  ###NSストリングに
  set ocidSaveFilePath to refMe's NSString's stringWithString:strSaveFilePath
  ###NSURLに
  set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath
end if

########################################
######データ処理
###PLISTのデータをレコードとして読み込む
set ocidReadPlistData to refMe's NSMutableDictionary's dictionaryWithContentsOfURL:ocidFilePathURL |error|:(reference)

set ocidPlistDict to item 1 of ocidReadPlistData
set ocidAllKeysArray to ocidPlistDict's allKeys()

set ocidAllKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidAllKeyArray's addObjectsFromArray:(ocidAllKeysArray)
##############################
####並び替え並び替え compare
(*
compare:
caseInsensitiveCompare:
localizedCompare:
localizedStandardCompare:
localizedCaseInsensitiveCompare:
*)
#NSSortDescriptor's
set ocidSortDescriptorsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
set ocidSortDescriptor to (refMe's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:(true) selector:"localizedStandardCompare:")
ocidSortDescriptorsArray's addObject:(ocidSortDescriptor)
##
ocidAllKeyArray's sortUsingDescriptors:(ocidSortDescriptorsArray)
#######################################
##まずはHTMLの基本的部分を生成
########################################
#headerに渡すエレメント
set ocidH3Element to refMe's NSXMLElement's elementWithName:("h3")
(ocidH3Element's setStringValue:("Microsoft Officeの付属フォントのGDIファミリー名一覧"))

########################################
#footerに渡すエレメント
set ocidFotterAElement to refMe's NSXMLElement's elementWithName:("a")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
(ocidFotterAElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidFotterAElement's addAttribute:(ocidAddNode))
set strContents to ("AppleScriptで生成しました") as text
(ocidFotterAElement's setStringValue:(strContents))

########################################
#articleに渡すエレメント
#テーブル部生成開始
set ocidTableElement to refMe's NSXMLElement's elementWithName:("table")
#####【caption】
set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption")
ocidCaptionElement's setStringValue:("Microsoft Officeの付属フォントのGDIファミリー名一覧")
ocidTableElement's addChild:(ocidCaptionElement)
#####【colgroup】
set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup")
#タイトル部の数だけ繰り返し
set listColName to {"LineNo", "ファミリー名", "フォント名"} as list
repeat with itemColName in listColName
  #######【col】col生成
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
end repeat
#テーブルエレメントに追加
ocidTableElement's addChild:(ocidColgroupElement)
#######【thead】
set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead")
#TR
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  if (itemColName as text) is "LineNo" then
    #ここはTDではなくてTHを利用
    set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
    ####項番処理
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
    #
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidAddElement's addAttribute:(ocidAddNode))
    #値を入れる
(ocidAddElement's setStringValue:("\"))
    #TH→TRにセット
(ocidTrElement's addChild:(ocidAddElement))
  else
    #ここはTDではなくてTHを利用
    set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
    #
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidAddElement's addAttribute:(ocidAddNode))
    #値を入れる
(ocidAddElement's setStringValue:(itemColName))
    #TH→TRにセット
(ocidTrElement's addChild:(ocidAddElement))
  end if
end repeat
#TRをTHEADにセット
ocidTheadElement's addChild:(ocidTrElement)
#THEADをテーブルにセット
ocidTableElement's addChild:(ocidTheadElement)

##################################
#本処理
######【tbody】
set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
set numCntRow to 1 as integer
repeat with itemArray in ocidAllKeyArray
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  ####項番処理
  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("項目番号:" & numCntRow))
(ocidThElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("LineNo"))
(ocidThElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidThElement's addAttribute:(ocidAddNode))
(ocidThElement's setStringValue:(numCntRow as text))
(ocidTrElement's addChild:(ocidThElement))
  ##################################
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  #
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemArray as text))
(ocidTdElement's addAttribute:(ocidAddNode))
(ocidTdElement's setStringValue:(itemArray as text))
(ocidTrElement's addChild:(ocidTdElement))
  ##################################
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  #
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("フォント名"))
(ocidTdElement's addAttribute:(ocidAddNode))
  #
  set ocidItemArray to (ocidPlistDict's objectForKey:(itemArray))
  set strSetValue to ("") as text
  repeat with itemValue in ocidItemArray
    set strSetValue to strSetValue & (itemValue as text) & "\n"
  end repeat
(ocidTdElement's setStringValue:(strSetValue))
(ocidTrElement's addChild:(ocidTdElement))
  
(ocidTbodyElement's addChild:(ocidTrElement))
  set numCntRow to numCntRow + 1 as integer
end repeat
#TBODYをテーブルにセット
ocidTableElement's addChild:(ocidTbodyElement)


######【tfoot】 TRで
set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot")
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#項目数を取得して
set numCntCol to (count of listColName) as integer
#colspan指定して1行でセット
set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
(ocidThElement's addAttribute:(ocidAddNode))
#
set numCntContents to (count of ocidAllKeyArray) as integer
set strContents to ("項目数 : " & (numCntContents - 1)) as text
(ocidThElement's setStringValue:(strContents))
#THをTRにセットして
ocidTrElement's addChild:(ocidThElement)
#TRをTFOOTにセット
ocidTfootElement's addChild:(ocidTrElement)
#TFOOTをテーブルにセット
ocidTableElement's addChild:(ocidTfootElement)

##############################
#HTMLにする
##############################
set ocidHTML to doMakeRootElement({ocidH3Element, ocidTableElement, ocidFotterAElement})
##############################
#保存
##############################
#読み取りやすい表示
set ocidXMLdata to ocidHTML's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)


set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)

####【6】ブラウザで開く
set aliasFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
tell application "Finder"
open location aliasFilePath
end tell










############################################################
# 基本的なHTMLの構造
(*
doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents})
HTMLのBODY部
header
article
footerにそれぞれAddchildするデータをリストで渡す
戻り値はRootエレメントにセットされた
NSXMLDocumentを戻すので 保存すればOK
*)
############################################################
to doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents})
  #XML初期化
  set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)
  # DTD付与
  set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("html")
ocidXMLDoc's setDTD:(ocidDTD)
  #
  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
ocidRootElement's addAttribute:(ocidAddNode)
  #
  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
ocidAddElement's setStringValue:("ImageList")
ocidHeadElement's addChild:(ocidAddElement)
  # http-equiv
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
ocidAddElement's setStringValue:("body {margin: 10px;background-color: #FFFFFF;}table {max-width: 1280px;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 th {border-spacing: 0;width: 40px !important;border: solid 1px #666666;padding: .5ch 1ch;border-block-width: 1px 0;border-inline-width: 1px 0;}tbody td {word-wrap: break-word;width: 720px;max-width: 720px;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 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}}img {max-width: 720px;}")
ocidHeadElement's addChild:(ocidAddElement)
ocidRootElement's addChild:(ocidHeadElement)
  #
  #ボディエレメント
  set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body")
  #ヘッダー
  set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")
ocidHeaderElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")
ocidHeaderElement's addAttribute:(ocidAddNode)
ocidHeaderElement's addChild:(argHeaderContents)
ocidBodyElement's addChild:(ocidHeaderElement)
  #アーティクル
  set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")
ocidArticleElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")
ocidArticleElement's addAttribute:(ocidAddNode)
ocidArticleElement's addChild:(argArticleContents)
  set ocidH6Element to refMe's NSXMLElement's elementWithName:("h6")
(ocidH6Element's setStringValue:("イメージ一覧"))
ocidArticleElement's addChild:(ocidH6Element)
ocidBodyElement's addChild:(ocidArticleElement)
  #フッター
  set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")
ocidFooterElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")
ocidFooterElement's addAttribute:(ocidAddNode)
ocidFooterElement's addChild:(argFooterContents)
ocidBodyElement's addChild:(ocidFooterElement)
  #ボディをROOTエレメントにセット
ocidRootElement's addChild:(ocidBodyElement)
  #ROOTをXMLにセット
ocidXMLDoc's setRootElement:(ocidRootElement)
  #値を戻す
return ocidXMLDoc
end doMakeRootElement

|

« 単位換算 詰め合わせ 2024-1 | トップページ | ブランクのPDFを生成するmm指定 大きく変更 »

AppleScript Microsoft」カテゴリの記事