AppleScript XML SVG

SVG←→SVGZ


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

on run
  
  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
  set strDialogText to "ドロップしても利用できます"
  set strTitleText to "画像ファイルを選んでください"
  set listButton to {"ファイルを選びます", "キャンセル"} as list
display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
  
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  set listChooseFileUTI to {"public.svg-image"}
  set strPromptText to "イメージファイルを選んでください" as text
  set strPromptMes to "イメージファイルを選んでください" as text
  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
  
  -->値をOpenに渡たす
open listAliasFilePath
end run


on open listAliasFilePath
  ##対象の拡張子のURLだけ格納するARRAY
  set ocidFilePathURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
  ##開いたエイリアスの数だけ々
  repeat with itemAliasFilePath in listAliasFilePath
    #パス処理
    set strFilePath to (POSIX path of itemAliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    #拡張子を小文字で取得して
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set strExtensionName to ocidExtensionName's lowercaseString() as text
    #対象の拡張子のURLだけARRAYに格納していく
    if strExtensionName is "svg" then
(ocidFilePathURLArrayM's addObject:(ocidFilePathURL))
    else if strExtensionName is "svgz" then
(ocidFilePathURLArrayM's addObject:(ocidFilePathURL))
    end if
  end repeat
  ##########################
  ##対象の拡張子のURLファイルの数だけ繰り返し
  repeat with itemArray in ocidFilePathURLArrayM
    #Arrayの中身はURLなので
    set ocidFilePathURL to itemArray
    #ファイル名
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    #拡張子を小文字で取得
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set strExtensionName to ocidExtensionName's lowercaseString() as text
    #SVGZを解凍する
    if strExtensionName is "svgz" then
      #解凍先ディレクトリ 起動時に削除する項目
      set appFileManager to refMe's NSFileManager's defaultManager()
      set ocidTempDirURL to appFileManager's temporaryDirectory()
      set ocidUUID to refMe's NSUUID's alloc()'s init()
      set ocidUUIDString to ocidUUID's UUIDString
      set ocidSaveDirPathURL to (ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true)
      set appFileManager to refMe's NSFileManager's defaultManager()
      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
      # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
      #解凍先のファイルパス
      set ocidTmpFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false)
      #コマンド用にパステキストに
      set strFilePath to ocidFilePathURL's |path| as text
      set strTmpeFilePath to ocidTmpFilePathURL's |path| as text
      #
      set strCommandText to ("/usr/bin/gunzip -c \"" & strFilePath & "\" > \"" & strTmpeFilePath & "\"") as text
do shell script strCommandText
      set ocidFilePathURL to ocidTmpFilePathURL
    end if
    ####################################
    ##サイズ取得
    #ファイルを読み込み
    set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
    set ocidXmlDoc to (item 1 of listReadData)
    #ROOTエレメントを取得して
    set ocidRootElement to ocidXmlDoc's rootElement
    #viewBoxを取得
    set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
    #テキストにして
    set ocidViewBoxStr to ocidViewBox's stringValue()
    #スペースを区切り文字でリストにして
    set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
    #3番目と4番目が横縦ピクセルサイズ
    set ocidPixelWidth to (ocidViewBoxArray's objectAtIndex:(2))
    set ocidPixelHeight to (ocidViewBoxArray's objectAtIndex:(3))
    set numPixelWidth to ocidPixelWidth as integer
    set numPixelHeight to ocidPixelHeight as integer
    ##戻り値
    set strResponseText to ("W: " & numPixelWidth & "\nH: " & numPixelHeight & "\n<img src=\"パス\" width=\"" & numPixelWidth & "\" height=\"" & numPixelHeight & "\" alt=\"" & (ocidFileName as text) & "\">\n\nmax-width: " & numPixelWidth & "px;\nmax-height: " & numPixelHeight & "px;\n") as text
    
    #####ダイアログを前面に
    tell current application
      set strName to name as text
    end tell
    ####スクリプトメニューから実行したら
    if strName is "osascript" then
      tell application "Finder" to activate
    else
      tell current application to activate
    end if
    set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
    ###ダイアログ
    set recordResult to (display dialog "SVGサイズ戻り値です" with title "戻り値です" default answer strResponseText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
    ###クリップボードコピー
    if button returned of recordResult is "クリップボードにコピー" then
      set strText to text returned of recordResult as text
      ####ペーストボード宣言
      set appPasteboard to refMe's NSPasteboard's generalPasteboard()
      set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
(appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString))
    end if
    
    
  end repeat
end open


|

SVGの縦横サイズの取得(SVGZ対応)


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

on run
  
  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
  set strDialogText to "ドロップしても利用できます"
  set strTitleText to "画像ファイルを選んでください"
  set listButton to {"ファイルを選びます", "キャンセル"} as list
display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
  
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  set listChooseFileUTI to {"public.svg-image"}
  set strPromptText to "イメージファイルを選んでください" as text
  set strPromptMes to "イメージファイルを選んでください" as text
  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
  
  -->値をOpenに渡たす
open listAliasFilePath
end run


on open listAliasFilePath
  ##対象の拡張子のURLだけ格納するARRAY
  set ocidFilePathURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
  ##開いたエイリアスの数だけ々
  repeat with itemAliasFilePath in listAliasFilePath
    #パス処理
    set strFilePath to (POSIX path of itemAliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    #拡張子を小文字で取得して
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set strExtensionName to ocidExtensionName's lowercaseString() as text
    #対象の拡張子のURLだけARRAYに格納していく
    if strExtensionName is "svg" then
(ocidFilePathURLArrayM's addObject:(ocidFilePathURL))
    else if strExtensionName is "svgz" then
(ocidFilePathURLArrayM's addObject:(ocidFilePathURL))
    end if
  end repeat
  ##########################
  ##対象の拡張子のURLファイルの数だけ繰り返し
  repeat with itemArray in ocidFilePathURLArrayM
    #Arrayの中身はURLなので
    set ocidFilePathURL to itemArray
    #ファイル名
    set ocidFileName to ocidFilePathURL's lastPathComponent()
    #拡張子を小文字で取得
    set ocidExtensionName to ocidFilePathURL's pathExtension()
    set strExtensionName to ocidExtensionName's lowercaseString() as text
    #SVGZを解凍する
    if strExtensionName is "svgz" then
      #解凍先ディレクトリ 起動時に削除する項目
      set appFileManager to refMe's NSFileManager's defaultManager()
      set ocidTempDirURL to appFileManager's temporaryDirectory()
      set ocidUUID to refMe's NSUUID's alloc()'s init()
      set ocidUUIDString to ocidUUID's UUIDString
      set ocidSaveDirPathURL to (ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true)
      set appFileManager to refMe's NSFileManager's defaultManager()
      set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
      # 777-->511 755-->493 700-->448 766-->502
(ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions))
      set listBoolMakeDir to (appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
      #解凍先のファイルパス
      set ocidTmpFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:false)
      #コマンド用にパステキストに
      set strFilePath to ocidFilePathURL's |path| as text
      set strTmpeFilePath to ocidTmpFilePathURL's |path| as text
      #
      set strCommandText to ("/usr/bin/gunzip -c \"" & strFilePath & "\" > \"" & strTmpeFilePath & "\"") as text
do shell script strCommandText
      set ocidFilePathURL to ocidTmpFilePathURL
    end if
    ####################################
    ##サイズ取得
    #ファイルを読み込み
    set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
    set ocidXmlDoc to (item 1 of listReadData)
    #ROOTエレメントを取得して
    set ocidRootElement to ocidXmlDoc's rootElement
    #viewBoxを取得
    set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
    #テキストにして
    set ocidViewBoxStr to ocidViewBox's stringValue()
    #スペースを区切り文字でリストにして
    set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
    #3番目と4番目が横縦ピクセルサイズ
    set ocidPixelWidth to (ocidViewBoxArray's objectAtIndex:(2))
    set ocidPixelHeight to (ocidViewBoxArray's objectAtIndex:(3))
    set numPixelWidth to ocidPixelWidth as integer
    set numPixelHeight to ocidPixelHeight as integer
    ##戻り値
    set strResponseText to ("W: " & numPixelWidth & "\nH: " & numPixelHeight & "\n<img src=\"パス\" width=\"" & numPixelWidth & "\" height=\"" & numPixelHeight & "\" alt=\"" & (ocidFileName as text) & "\">\n\nmax-width: " & numPixelWidth & "px;\nmax-height: " & numPixelHeight & "px;\n") as text
    
    #####ダイアログを前面に
    tell current application
      set strName to name as text
    end tell
    ####スクリプトメニューから実行したら
    if strName is "osascript" then
      tell application "Finder" to activate
    else
      tell current application to activate
    end if
    set aliasIconPath to POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
    ###ダイアログ
    set recordResult to (display dialog "SVGサイズ戻り値です" with title "戻り値です" default answer strResponseText buttons {"クリップボードにコピー", "キャンセル", "OK"} default button "OK" cancel button "キャンセル" giving up after 20 with icon aliasIconPath without hidden answer)
    ###クリップボードコピー
    if button returned of recordResult is "クリップボードにコピー" then
      set strText to text returned of recordResult as text
      ####ペーストボード宣言
      set appPasteboard to refMe's NSPasteboard's generalPasteboard()
      set ocidText to (refMe's NSString's stringWithString:(strText))
appPasteboard's clearContents()
(appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString))
    end if
    
    
  end repeat
end open


|

SVGイメージのEpubフォルダを生成する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
自炊用
画像ファイル=各ページ で
EPUBのコンテンツを生成します
出来上がったフォルダを
[ドロップレット]EPUB用zip圧縮(半角スペース対応)
https://quicktimer.cocolog-nifty.com/icefloe/2023/11/post-c6729c.html
圧縮してEPUBの出来上がりになります
*)
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application


#############################
### 設定項目
###タイトル
set strDocumentTitle to ("ドキュメントのタイトル") as text

###一般的には著者 または 作成者
set strAuthor to ("com.cocolog-nifty.quicktimer") as text

###表紙のラベル (この設定は表紙なしなので設定しなくてもOK)
set strLabelTitle to ("表紙") as text

###表紙ページを付与するか trueで表紙ページあり falseで表紙ページなし
set boolCoverPage to true as boolean

### 左開き? ltr (left-to-right) 右開き? rtl (right-to-left)
# set strPageProgression to ("ltr") as text
set strPageProgression to ("rtl") as text

###見開き調整 trueで表紙をコンテンツから抜いて1ページずらします
##見開きページがズレる場合に true を入れてください
set boolProgression to false as boolean


#############################
### ここから本処理
(*
大まかな手順
【1】ROOT フォルダ:META-INF OPS ファイル:mimetype
【1−2】mimetype

【2】META-INF ファイル: container.xml com.apple.ibooks.display-options.xml
【2−1】container.xml
【2−2】com.apple.ibooks.display-options.xml

【3】OPS
【3−1】css book.css
【3−2】js book.js
【3−3】images
【3−4】toc.ncx
【3−5】content.opf
【3−6】toc.xhtml
【3−7】page-XXXX.xhtml
【3−8】cover.xhtml
*)
######
##設定項目(詳細)
##XMLファイル名の接頭語
set strBaseFileName to ("page-") as text
##コピー後のファイル名の接頭名 コピー後のファイル名を固定にする事で後処理を少し簡素化
set strBaseImageFileName to ("Image_") as text


#############################
###ドキュメントのUUID
set ocidUUID to refMe's NSUUID's alloc()'s init()
set strUUID to ocidUUID's UUIDString as text

#############################
###ダイアログ
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############ デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
############UTIリスト
set listUTI to {"public.svg-image"}
set strMes to ("画像ファイルを選んでください") as text
set strPrompt to ("画像ファイルを選んでください") as text
try
  ### ファイル選択
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
on error
log "エラーしました"
return "エラーしました"
end try
if listAliasFilePath is {} then
return "選んでください"
end if

##パス 保存先パス
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
###デスクトップ
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
###設定項目の名称がフォルダ名
set ocidEpubDirPathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strDocumentTitle)
set ocidEpubDirPath to ocidEpubDirPathURL's |path|()
##############################
##必要なフォルダを作る
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
##アクセス権755この値は後でも使う
(ocidAttrDict's setValue:(493) forKey:(refMe's NSFilePosixPermissions))
##フォルダのパスのリスト
set listDirName to {"OPS", "OPS/css", "OPS/images", "OPS/js", "META-INF"} as list
##stringsByAppendingPathsでARRAYにする
set ocidSubPathArray to ocidEpubDirPath's stringsByAppendingPaths:(listDirName)
##ARRAYの分だけ
repeat with itemSubPathArray in ocidSubPathArray
  ##フォルダを作る
  set listBoolMakeDir to (appFileManager's createDirectoryAtPath:(itemSubPathArray) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference))
end repeat
#################################################################################
### 【1】ROOT フォルダ:META-INF OPS ファイル:mimetype
set ocidEpubDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidEpubDirPath) isDirectory:true)
### 【1−2】mimetype
##保存先パス
set ocidMimetypeFilePathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("mimetype") isDirectory:false
##内容
set strMimetype to ("application/epub+zip") as text
set ocidMimetype to refMe's NSString's stringWithString:(strMimetype)
##ファイルに保存して
set listDone to ocidMimetype's writeToURL:(ocidMimetypeFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
##アクセス権755を指定する
set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidMimetypeFilePathURL's |path|) |error|:(reference)
#################################################################################
### 【3】OPS
set ocidOPSDirPathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("OPS") isDirectory:true
######◆ 【3−1】css book.css
##フォルダのパス
set ocidCssDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("css") isDirectory:true
###ファイルのパス
set ocidCssFilePathURL to ocidCssDirPathURL's URLByAppendingPathComponent:("book.css") isDirectory:false
##ファイルの中身
set strCssContents to ("body { margin: 0; padding: 0; border: 0;}") as text
set ocidCssContents to refMe's NSString's stringWithString:(strCssContents)
##保存
set listDone to ocidCssContents's writeToURL:(ocidCssFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
##アクセス権
set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidCssFilePathURL's |path|) |error|:(reference)
######◆ 【3−2】js book.js
##フォルダのパス
set ocidJsDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("js") isDirectory:true
###ファイルのパス
set ocidJsFilePathURL to ocidJsDirPathURL's URLByAppendingPathComponent:("book.js") isDirectory:false
##ファイルの中身
set strJsContents to ("function Body_onLoad() {}") as text
set ocidJsContents to refMe's NSString's stringWithString:(strJsContents)
##保存
set listDone to ocidJsContents's writeToURL:(ocidJsFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
##アクセス権
set listDone to appFileManager's setAttributes:(ocidAttrDict) ofItemAtPath:(ocidJsFilePathURL's |path|) |error|:(reference)
######◆ 【3−3】images イメージファイルをコピーします
set ocidImagesDirPathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("images") isDirectory:true

set numCntPage to 1 as integer
set numCntAllImage to (count of listAliasFilePath) as integer
set listImageFileName to {} as list
##画像ファイルの数だけ繰り返し
repeat with itemAliasFilePath in listAliasFilePath
  ##パス
  set aliasFilePath to itemAliasFilePath as alias
  set strFilePath to (POSIX path of aliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  ##拡張子
  set ocidExtensionName to ocidFilePathURL's pathExtension()
  ###コピー後の画像ファイルは連番処理 四桁のゼロサプレス
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  set strFileName to (strBaseImageFileName & strSeroSup) as text
  ##コピー先URL
  set ocidBaseFilePathURL to (ocidImagesDirPathURL's URLByAppendingPathComponent:(strFileName))
  set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:(ocidExtensionName))
  ##ファイル名のリストを作っておく
  set ocidImageFileName to ocidSaveFilePathURL's lastPathComponent()
  set strImageFileName to ocidImageFileName as text
  set end of listImageFileName to strImageFileName
  ###コピー
  set appFileManager to refMe's NSFileManager's defaultManager()
  set listDone to (appFileManager's copyItemAtURL:(ocidFilePathURL) toURL:(ocidSaveFilePathURL) |error|:(reference))
  ##カウントアップ
  set numCntPage to numCntPage + 1 as integer
end repeat


#################################
###◆ 【3−7】page-XXXX.xhtml
##配置オブジェクトが画像1つ限定なのでシンプルな構造
##【3−7−A】 root エレメント 【3−7−B】 head エレメント 【3−7−C】 body エレメント
##カウンター
set numCntPage to 1 as integer
##総画像ファイルする右=ページ数
set numCntAllImage to (count of listAliasFilePath) as integer
##画像の数だけ繰り返し
repeat numCntAllImage times
  ###ファイルは連番処理 四桁のゼロサプレス
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  set strFileName to (strBaseFileName & strSeroSup & ".xhtml") as text
  ##XHTMLのパス
  set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
  ##配置画像
  ##不具合の元かもしれないが拡張子判定する方法が見つからなかった
  set strImageName to (item numCntPage of listImageFileName)
  set ocidImagesFilePathURL to ocidImagesDirPathURL's URLByAppendingPathComponent:(strImageName) isDirectory:false
  #ファイルを読み込み
  set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
  set ocidXmlDoc to (item 1 of listReadData)
  #ROOTエレメントを取得して
  set ocidRootElement to ocidXmlDoc's rootElement
  #viewBoxを取得
  set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
  #テキストにして
  set ocidViewBoxStr to ocidViewBox's stringValue()
  #スペースを区切り文字でリストにして
  set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
  #3番目と4番目が横縦ピクセルサイズ
  set strPixelsWidth to (ocidViewBoxArray's objectAtIndex:(2)) as text
  set strPixelsHeight to (ocidViewBoxArray's objectAtIndex:(3)) as text
  
  ########
  ##◆【3−7−A】 root エレメント
  set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html"
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml"))
  ########
  ##◆【3−7−B】 head エレメント
  set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head")
  #CSS
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css"))
ocidHeadElement's addChild:(ocidMetaElement)
  #JS
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("script")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("js/book.js"))
ocidHeadElement's addChild:(ocidMetaElement)
  #文字コード
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8"))
ocidHeadElement's addChild:(ocidMetaElement)
  #タイトル
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title")
  set strPageTitle to ("Page : " & strSeroSup) as text
ocidMetaElement's setStringValue:(strPageTitle)
ocidHeadElement's addChild:(ocidMetaElement)
  #EPUBドキュメントのUUID
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID))
ocidHeadElement's addChild:(ocidMetaElement)
  #ビューポイント ここで画像のサイズ指定=全画面
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=" & strPixelsWidth & ",height=" & strPixelsHeight & ", initial-scale=1.0"))
ocidHeadElement's addChild:(ocidMetaElement)
  ########
  ##◆【3−7−C】 body エレメント
  set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body")
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("onload") stringValue:("Body_onLoad()"))
  #開き方向指定
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression))
  #一番外側のDIV要素
  set ocidOutDiivElement to refMe's NSXMLElement's alloc()'s initWithName:("div")
ocidOutDiivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("position:absolute;left:0;top:0;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;"))
  #imgタグ
  set ocidImgElement to refMe's NSXMLElement's alloc()'s initWithName:("img")
  set strPath to ("images/" & strImageName) as text
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strPath))
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("alt") stringValue:(strFileName))
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("object-fit: cover;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;"))
  #imgタグをDIVにセット
ocidOutDiivElement's addChild:(ocidImgElement)
  #DIVをbodyにセット
ocidBodyElement's addChild:(ocidOutDiivElement)
  ########
  ##【3−7−B】のheadエレメントをAのROOTにセット
ocidRootElement's addChild:(ocidHeadElement)
  ##【3−7−C】 bodyエレメントをAのROOTにセット
ocidRootElement's addChild:(ocidBodyElement)
  ## ↑からのROOTエレメントをセットしてXMLとする
  set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
  #XMLをテキストにして
  set ocidSaveStrings to ocidOutPutXML's XMLString()
  ###改行コードを指定して
ocidSaveStrings's appendString:"\n"
  ##保存
  set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
  ##
  set numCntPage to numCntPage + 1 as integer
end repeat

#################################
###◆【3−8】cover.xhtml いわゆる表紙ページ
# cover-page と cover-imageがあるがここではcover-pageを生成する
#保存パス
set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("cover.xhtml") isDirectory:false
# 表紙イメージ=1ページ目の画像
set aliasCoverImageFilePath to (item 1 of listAliasFilePath) as alias
set strCoverImageFilePath to (POSIX path of aliasCoverImageFilePath) as text
set ocidCoverImageFilePathStr to refMe's NSString's stringWithString:(strCoverImageFilePath)
set ocidCoverImageFilePath to ocidCoverImageFilePathStr's stringByStandardizingPath()
set ocidCoverImageFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidCoverImageFilePath) isDirectory:false)
set strExtensionName to (ocidCoverImageFilePathURL's pathExtension()) as text
#ファイルを読み込み
set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidCoverImageFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
set ocidXmlDoc to (item 1 of listReadData)
#ROOTエレメントを取得して
set ocidRootElement to ocidXmlDoc's rootElement
#viewBoxを取得
set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
#テキストにして
set ocidViewBoxStr to ocidViewBox's stringValue()
#スペースを区切り文字でリストにして
set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
#3番目と4番目が横縦ピクセルサイズ
set strPixelsWidth to (ocidViewBoxArray's objectAtIndex:(2)) as text
set strPixelsHeight to (ocidViewBoxArray's objectAtIndex:(3)) as text


#######【3−8-A】ルートエレメント XHTMLのルートエレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html"
#ネームスペースの追加
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("epub") stringValue:("http://www.idpf.org/2007/ops"))
#アトリビュートの追加
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja"))
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:prefix") stringValue:("ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/"))
#####【3−6-B】 headエレメント
set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head")
#タイトル
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title")
ocidMetaElement's setStringValue:("表紙:Cover Page")
ocidHeadElement's addChild:(ocidMetaElement)
#スタイルシートへのリンク
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css"))
ocidHeadElement's addChild:(ocidMetaElement)
#Jsへのリンク
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("script")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("js/book.js"))
ocidHeadElement's addChild:(ocidMetaElement)
#文字コード宣言
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8"))
ocidHeadElement's addChild:(ocidMetaElement)
#UUID設定
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID))
ocidHeadElement's addChild:(ocidMetaElement)
#ビューポイント
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=" & strPixelsWidth & ",height=" & strPixelsHeight & ", initial-scale=1.0"))
ocidHeadElement's addChild:(ocidMetaElement)
######【3−8-C】ボディエレメント
set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body")
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("onload") stringValue:("Body_onLoad()"))
#開き方向
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression))
#
set ocidOutDiivElement to refMe's NSXMLElement's alloc()'s initWithName:("div")
ocidOutDiivElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("position:absolute;left:0;top:0;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;"))
##
set ocidImgElement to refMe's NSXMLElement's alloc()'s initWithName:("img")
set strImageName to (strBaseImageFileName & "0001." & strExtensionName) as text
set strPath to ("images/" & strImageName) as text
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strPath))
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("alt") stringValue:(strFileName))
ocidImgElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("style") stringValue:("object-fit: cover;width: " & strPixelsWidth & "px;height:" & strPixelsHeight & "px;"))
ocidOutDiivElement's addChild:(ocidImgElement)
ocidBodyElement's addChild:(ocidOutDiivElement)
####
#【3−8-B】 head を【3−8-A】 ルートエレメントに追加
ocidRootElement's addChild:(ocidHeadElement)
#【3−8-C】 body を【3−8-A】ルートエレメントに追加
ocidRootElement's addChild:(ocidBodyElement)
## ↑からのROOTエレメントをセットしてXMLとする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###テキストにして
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
#################################
###◆ 【3−6】toc.xhtml いわゆる目次
#【3−6-B】 head 【3−6-C】 body
#保存パス
set ocidXHTMLFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("toc.xhtml") isDirectory:false
#【3−6-A】ルートエレメント XHTMLのルートエレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"html"
#ネームスペースの追加
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.w3.org/1999/xhtml"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("epub") stringValue:("http://www.idpf.org/2007/ops"))
#アトリビュートの追加
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("xml:lang") stringValue:("ja"))
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:prefix") stringValue:("ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/"))
#####【3−6-B】 headエレメント
set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head")
#タイトル
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("title")
ocidMetaElement's setStringValue:("目次:Table of Contents")
ocidHeadElement's addChild:(ocidMetaElement)
#スタイルシートへのリンク
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("link")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("rel") stringValue:("stylesheet"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text/css"))
ocidHeadElement's addChild:(ocidMetaElement)
#文字コード宣言
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("charset") stringValue:("UTF-8"))
ocidHeadElement's addChild:(ocidMetaElement)
#UUID設定
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("EPB-UUID"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID))
ocidHeadElement's addChild:(ocidMetaElement)
#ビューポイント
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=device-width, initial-scale=1.0"))
ocidHeadElement's addChild:(ocidMetaElement)
####【3−6-C】 body
set ocidBodyElement to refMe's NSXMLElement's alloc()'s initWithName:("body")
#bodyエレメントに開き方向のアトリビュート
ocidBodyElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("dir") stringValue:(strPageProgression))
#タイトルをH1で入れて
set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("h1")
ocidBodyItem's setStringValue:(strDocumentTitle)
ocidBodyElement's addChild:(ocidBodyItem)
#区切り線
set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("hr")
ocidBodyElement's addChild:(ocidBodyItem)
#メインの要素
set ocidBodyItem to refMe's NSXMLElement's alloc()'s initWithName:("div")
ocidBodyItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("class") stringValue:("nav-body"))
ocidBodyElement's addChild:(ocidBodyItem)
#ナビ
set ocidNavItem to refMe's NSXMLElement's alloc()'s initWithName:("nav")
ocidNavItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("toc"))
ocidNavItem's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("toc"))
#リスト
set ocidNavOL to refMe's NSXMLElement's alloc()'s initWithName:("ol")
#番号初期化
set numCntPage to 1 as integer
#総ページ数の数だけ繰り返し
repeat numCntAllImage times
  ###画像ファイルは連番処理 四桁のゼロサプレス
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  set strLinkFileName to (strBaseFileName & strSeroSup) as text
  set strFileName to (strBaseFileName & strSeroSup & ".xhtml") as text
  ####
  set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li")
  set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a")
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strFileName))
ocidNavA's setStringValue:(strLinkFileName)
ocidNavLI's addChild:(ocidNavA)
ocidNavOL's addChild:(ocidNavLI)
  set numCntPage to numCntPage + 1 as integer
end repeat
##リストに表紙ページを追加
set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li")
set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a")
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml"))
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("ibooks:reader-start-page"))
ocidNavA's setStringValue:("Cover Page")
ocidNavLI's addChild:(ocidNavA)
ocidNavOL's addChild:(ocidNavLI)
#リストに目次を追加
set ocidNavLI to refMe's NSXMLElement's alloc()'s initWithName:("li")
set ocidNavA to refMe's NSXMLElement's alloc()'s initWithName:("a")
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml"))
ocidNavA's addAttribute:(refMe's NSXMLNode's attributeWithName:("epub:type") stringValue:("toc"))
ocidNavA's setStringValue:("Table of Contents")
ocidNavLI's addChild:(ocidNavA)
ocidNavOL's addChild:(ocidNavLI)
#出来上がったリストをbodyに追加
ocidNavItem's addChild:(ocidNavOL)
ocidBodyItem's addChild:(ocidNavItem)
####
#【3−6-B】 head を【3−6-A】 ルートエレメントに追加
ocidRootElement's addChild:(ocidHeadElement)
#【3−6-C】 body を【3−6-A】ルートエレメントに追加
ocidRootElement's addChild:(ocidBodyElement)
## ↑からのROOTエレメントをセットしてXMLとする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###テキストにして
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidXHTMLFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

#############################################
###◆【3−5】content.opf
##【B】メタ情報のheadからなる 【C】各種コンテンツへのパス manifest と 【D】コンテンツの配置 spine  【E】ガイドguide
##Pageの場合
## set ocidOptFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("epb.opf") isDirectory:false
##一般的な命名
set ocidOptFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("content.opf") isDirectory:false
##【A】ルートエレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"package"
#アトリビュートを追加
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("3.0"))
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("unique-identifier") stringValue:("BookId"))
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("prefix") stringValue:("ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/ rendition: http://www.idpf.org/vocab/rendition/#"))
#ネームスペースを追加
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.idpf.org/2007/opf"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("ibooks") stringValue:("http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/"))
##################
#【B】メタ情報のhead
set ocidMetaDataElement to refMe's NSXMLElement's alloc()'s initWithName:("metadata")
ocidMetaDataElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("dc") stringValue:("http://purl.org/dc/elements/1.1/"))
ocidMetaDataElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("opf") stringValue:("http://www.idpf.org/2007/opf"))
#◆【B-1】タイトル
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:title")
ocidMetaElement's setStringValue:(strDocumentTitle)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-2】作成者 著者
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:creator")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("creator"))
ocidMetaElement's setStringValue:(strAuthor)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-3】UUID
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:identifier")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("BookId"))
ocidMetaElement's setStringValue:(strUUID)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-4】言語
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:language")
ocidMetaElement's setStringValue:("ja")
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-5】作成日
set strSetDate to doGetDateNo("yyyy-MM-dd") as text
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:date")
ocidMetaElement's setStringValue:(strSetDate)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-6】修正日
set strSetDate to doGetDateNo("yyyy-MM-dd'T'HH:mm:ss'Z'") as text
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("dc:modified")
ocidMetaElement's setStringValue:(strSetDate)
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-7】コンテンツのプロパティ レイアウト
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:layout"))
##リフロータイプのレイアウト 柔軟な表示形式 文字中心なものに最適
# ocidMetaElement's setStringValue:("reflowable")
##固定型のレイアウト 画面サイズに依存しない表示 画面のレイアウトを優先したい場合
# ocidMetaElement's setStringValue:("fixed")
##事前にページ化されたレイアウト ページベースの表示形式 画像コンテンツに最適
ocidMetaElement's setStringValue:("pre-paginated")
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-8】コンテンツのプロパティ スプレッド 開き方
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:spread"))
##デバイスの向きに依存しない
ocidMetaElement's setStringValue:("both")
##横
#ocidMetaElement's setStringValue:("landscape")
##縦 非推奨
#ocidMetaElement's setStringValue:("portrait")
##単ページ
##ocidMetaElement's setStringValue:("none")
##自動
##ocidMetaElement's setStringValue:("auto")
ocidMetaDataElement's addChild:(ocidMetaElement)
#◆【B-9】向き
set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("property") stringValue:("rendition:orientation"))
#自動
ocidMetaElement's setStringValue:("auto")
##横
#ocidMetaElement's setStringValue:("landscape")
##縦
#ocidMetaElement's setStringValue:("portrait")
ocidMetaDataElement's addChild:(ocidMetaElement)
##表紙の有無での分岐
if boolCoverPage is true then
  set ocidMetaElement to refMe's NSXMLElement's alloc()'s initWithName:("meta")
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("cover"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("cover-image"))
ocidMetaDataElement's addChild:(ocidMetaElement)
end if

##################
### 【C】各種コンテンツへのパス manifest
##manifestのROOTエレメント
set ocidManifestElement to refMe's NSXMLElement's alloc()'s initWithName:("manifest")
#CSS追加
set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("stylesheet"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("css/book.css"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("text/css"))
ocidManifestElement's addChild:(ocidItemElement)
#JS追加
set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("javascript"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("js/book.js"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("text/javascript"))
ocidManifestElement's addChild:(ocidItemElement)
#NCX追加
set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("ncx"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.ncx"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/x-dtbncx+xml"))
ocidManifestElement's addChild:(ocidItemElement)
#目次追加
set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("toc"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/x-dtbncx+xml"))
ocidManifestElement's addChild:(ocidItemElement)
##表紙 表示画像
if boolCoverPage is true then
  ##表紙ページ設定
  set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("cover"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/x-dtbncx+xml"))
ocidManifestElement's addChild:(ocidItemElement)
  ##表紙画像
  set ocidExtensionName to ocidCoverImageFilePathURL's pathExtension()
  ####拡張子からUTI取得
  set ocidUTType to (refMe's UTType's typeWithFilenameExtension:(ocidExtensionName))
  set ocidFileMimeType to ocidUTType's preferredMIMEType()
  ##MimeTypeを取得してから
  set strFileMimeType to ocidFileMimeType as text
  #設定
  set strCoverImageFileName to (strBaseImageFileName & "0001." & (ocidExtensionName as text)) as text
  set strHref to ("images/" & strCoverImageFileName) as text
  set ocidItemElement to refMe's NSXMLElement's alloc()'s initWithName:("item")
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("cover-image"))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strHref))
ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:(strFileMimeType))
ocidManifestElement's addChild:(ocidItemElement)
end if


set numCntPage to 1 as integer
repeat with itemAliasFilePath in listAliasFilePath
  set aliasFilePath to itemAliasFilePath as alias
  set strFilePath to (POSIX path of aliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  set ocidExtensionName to ocidFilePathURL's pathExtension()
  ####拡張子からUTI取得
  set ocidUTType to (refMe's UTType's typeWithFilenameExtension:(ocidExtensionName))
  set ocidFileMimeType to ocidUTType's preferredMIMEType()
  set strFileMimeType to ocidFileMimeType as text
  ###画像ファイルは連番処理 四桁のゼロサプレス
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  #IDを定義
  set strBaseImageFileName to ("dataItem") as text
  set strFileName to (strBaseImageFileName & strSeroSup) as text
  ##メディア要素(イメージファイル)
  #itemエレメント
  set ocidItemElement to (refMe's NSXMLElement's alloc()'s initWithName:("item"))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:(strFileName)))
  #パス
  set strSetValue to ("images/Image_" & strSeroSup & "." & (ocidExtensionName as text)) as text
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSetValue)))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:(strFileMimeType)))
(ocidManifestElement's addChild:(ocidItemElement))
  ##ページ要素(XHTMLファイル)
  set strBaseFileName to ("page-") as text
  set strFileName to (strBaseFileName & strSeroSup) as text
  #itemエレメント
  set ocidItemElement to (refMe's NSXMLElement's alloc()'s initWithName:("item"))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:(strFileName)))
  #パス
  set strSetValue to (strBaseFileName & strSeroSup & ".xhtml") as text
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSetValue)))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/xhtml+xml")))
(ocidItemElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("properties") stringValue:("scripted")))
(ocidManifestElement's addChild:(ocidItemElement))
  ##カウントアップ
  set numCntPage to numCntPage + 1 as integer
end repeat

########################
#【D】コンテンツの配置 spine
set ocidSpineElement to refMe's NSXMLElement's alloc()'s initWithName:("spine")
##アトリビュート
ocidSpineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("toc") stringValue:("ncx"))
##開き方向指定
ocidSpineElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("page-progression-direction") stringValue:(strPageProgression))
##【D-1】表紙ページの有無
if boolCoverPage is true then
  #表紙ページ ID: cover-page
  set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover"))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
ocidSpineElement's addChild:(ocidItemRef)
  (*
#表紙画像 ID: cover-image
set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover-image"))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
ocidSpineElement's addChild:(ocidItemRef)
#表紙ページ ID: cover-page
set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("cover-page"))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
ocidSpineElement's addChild:(ocidItemRef)
*)
  ##【D-2】目次ページ
  set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:("toc"))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
ocidSpineElement's addChild:(ocidItemRef)
end if

#カウンタ初期化
set numCntPage to 1 as integer
#事前に取得している総ページ数回繰り返す
repeat numCntAllImage times
  ###画像ファイルは連番処理 四桁のゼロサプレス
  set strZeroSup to "0000" as text
  set strSeroSup to (strZeroSup & (numCntPage as text)) as text
  set strSeroSup to (text -4 through -1 of strSeroSup) as text
  set strSetFileID to (strBaseFileName & strSeroSup) as text
  ##ファイル名をitemrefとして登録
  set ocidItemRef to refMe's NSXMLElement's alloc()'s initWithName:("itemref")
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("idref") stringValue:(strSetFileID))
ocidItemRef's addAttribute:(refMe's NSXMLNode's attributeWithName:("linear") stringValue:("yes"))
  if boolProgression is true then
    if numCntPage = 1 then
log "spineから1ページ目を抜きます"
    else
      ##ページ要素itemrefをspineの子要素に追加
ocidSpineElement's addChild:(ocidItemRef)
    end if
  else
    ##ページ要素itemrefをspineの子要素に追加
ocidSpineElement's addChild:(ocidItemRef)
  end if
  set numCntPage to numCntPage + 1 as integer
end repeat
##################
#【E】ガイドguide
(* referenceのtypeの要素
toc(Table of Contents): 目次へのリンク。
cover: 書籍の表紙ページへのリンク。
title-page: 書籍のタイトルページへのリンク。
colophon: 制作者や印刷情報を含むページへのリンク。
acknowledgements: 著者への謝辞が含まれるページへのリンク。
dedication: 書籍の献辞が含まれるページへのリンク。
*)
set ocidGuideElement to refMe's NSXMLElement's alloc()'s initWithName:("guide")
#【E-1】目次追加
set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("toc"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("toc.xhtml"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("目次"))
ocidGuideElement's addChild:(ocidReferenceElement)
##【E-2】表紙ページの有無 設定依存
if boolCoverPage is true then
  set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("cover"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:("cover.xhtml"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("表紙"))
ocidGuideElement's addChild:(ocidReferenceElement)
  ##1ページ目指定
  set strStartFileName to (strBaseFileName & "0001.xhtml") as text
  set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("other.reader-start-page"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strStartFileName))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("最初のページ"))
ocidGuideElement's addChild:(ocidReferenceElement)
  ##1ページ目指定
  set ocidReferenceElement to (refMe's NSXMLElement's alloc()'s initWithName:("reference"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("text"))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("href") stringValue:(strStartFileName))
ocidReferenceElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("title") stringValue:("最初のコンテンツ"))
ocidGuideElement's addChild:(ocidReferenceElement)
end if

##################
#↑からの各子要素をセット
## 【B】メタ部を【A】のROOTエレメントに追加
ocidRootElement's addChild:(ocidMetaDataElement)
## 【C】manifest部を【A】のROOTエレメントに追加
ocidRootElement's addChild:(ocidManifestElement)
## 【D】spine部を【A】のROOTエレメントに追加
ocidRootElement's addChild:(ocidSpineElement)
## 【E】ガイド部を【A】のROOTエレメントに追加
ocidRootElement's addChild:(ocidGuideElement)
## 【A】をROOTエレメントをセットしてXMLとする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
### 【A】をテキストにして
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidOptFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####################################
###◆ 【3−4】toc.ncx 主に閲覧者が必要な情報や
##ページや項目の順番等を指定する
##マルチメディア系やアクセシビリティ要素もここで指定する
###ファイルパス
##Pageの場合
## set ocidNcxFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("epb.ncx") isDirectory:false
##一般的な命名
set ocidNcxFilePathURL to ocidOPSDirPathURL's URLByAppendingPathComponent:("toc.ncx") isDirectory:false
######【A】ROOTのエレメント 4つの子要素がある
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"ncx"
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("2005-1"))
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("http://www.daisy.org/z3986/2005/ncx/"))
######【B】head メタ情報部分
set ocidHeadElement to refMe's NSXMLElement's alloc()'s initWithName:("head")
##【B-1】uid
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:uid"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strUUID))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-2】depth
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:depth"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:("1"))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-3】totalPageCount
set strCntAllImage to numCntAllImage as text
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:totalPageCount"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strCntAllImage))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-4】maxPageNumber
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dtb:maxPageNumber"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strCntAllImage))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-5】作成日
set strSetDate to doGetDateNo("yyyy-MM-dd") as text
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dc:date"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strSetDate))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
##◆【B-6】修正日
set strSetDate to doGetDateNo("yyyy-MM-dd'T'HH:mm:ss'Z'") as text
###エレメント名meta
set ocidMetaElement to refMe's NSXMLElement's elementWithName:("meta")
##アトリビュートを設定して
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("dc:modified"))
ocidMetaElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("content") stringValue:(strSetDate))
##親要素の【B】head に追加する
ocidHeadElement's addChild:(ocidMetaElement)
######【C】docTitle タイトル
##エレメント名docTitle
set ocidTitleElement to refMe's NSXMLElement's alloc()'s initWithName:("docTitle")
##子要素のtext
set ocidTextElement to refMe's NSXMLElement's elementWithName:("text")
##子要素textにドキュメント名を値として設定して
ocidTextElement's setStringValue:(strDocumentTitle)
##CのdocTitleエレメントに子要素として追加する
ocidTitleElement's addChild:(ocidTextElement)
######【D】docAuthor 作者 著者
##エレメント名 docAuthor
set ocidAuthorElement to refMe's NSXMLElement's alloc()'s initWithName:("docAuthor")
##子要素のtext
set ocidTextElement to refMe's NSXMLElement's elementWithName:("text")
##子要素textに作者情報を値として設定して
ocidTextElement's setStringValue:(strAuthor)
##DのdocAuthorエレメントに子要素として追加する
ocidAuthorElement's addChild:(ocidTextElement)
######【E】navMap navMapは閲覧時の順番を指定するので表紙イメージの設定とは異なる
set ocidMapElement to refMe's NSXMLElement's alloc()'s initWithName:("navMap")
#navMapの子要素navPoint
set ocidNavPointElement to refMe's NSXMLElement's elementWithName:("navPoint")
##navPointのアトリビュート カバー表紙を最初のページとして読み順指定する
ocidNavPointElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("navpoint-1"))
ocidNavPointElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("playOrder") stringValue:("1"))
##【E-1】 navLabel ↑このnavPointの意図するラベル名
set ocidNavLabelElement to refMe's NSXMLElement's elementWithName:("navLabel")
set ocidTextElement to refMe's NSXMLElement's elementWithName:("text")
ocidTextElement's setStringValue:(strLabelTitle)
##ラベルテキストをnavLabelに子要素として追加
ocidNavLabelElement's addChild:(ocidTextElement)
##↑追加したラベルをnavPointに子要素として追加
ocidNavPointElement's addChild:(ocidNavLabelElement)
##【E-2】contentはnavPointとして指定するファイルのリソースパス
set ocidNavContentElement to refMe's NSXMLElement's elementWithName:("content")
###表紙設定ありの場合は
if boolCoverPage is true then
  ##アトリビュートでパス指定する =表紙ページ
ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:("cover.xhtml"))
else
  ##見開き調整ありの場合は
  if boolProgression is true then
    set strStartFileName to (strBaseFileName & "0002.xhtml") as text
ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strStartFileName))
  else
    set strStartFileName to (strBaseFileName & "0001.xhtml") as text
ocidNavContentElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("src") stringValue:(strStartFileName))
  end if
end if
##contentをnavPointに子要素として追加
ocidNavPointElement's addChild:(ocidNavContentElement)
##複数のnavPointを指定する場合はこの下に追加していく
###navPointをnavMapに子要素として追加
ocidMapElement's addChild:(ocidNavPointElement)
## ↑からの子要素をセット
##【A】に【B】を追加
ocidRootElement's addChild:(ocidHeadElement)
##【A】に【C】を追加
ocidRootElement's addChild:(ocidTitleElement)
##【A】に【D】を追加
ocidRootElement's addChild:(ocidAuthorElement)
##【A】に【E】を追加
ocidRootElement's addChild:(ocidMapElement)
## ↑からのROOTエレメントをセットしてXMLとする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存 これでCNXファイルの出来上がり
set listWritetoUrlArray to ocidSaveStrings's writeToURL:(ocidNcxFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

#################################################################
### 【2】META-INF ファイル: container.xml com.apple.ibooks.display-options.xml
set ocidMetaDirPathURL to ocidEpubDirPathURL's URLByAppendingPathComponent:("META-INF") isDirectory:true
##################
###◆【2−1】container.xml
###ファイルのパス
set ocidContainerFilePathURL to ocidMetaDirPathURL's URLByAppendingPathComponent:("container.xml") isDirectory:false
###【A】ROOT エレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"container"
##【A】にアトリビュートを追加
ocidRootElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.0"))
##【A】にネームスペースを追加
ocidRootElement's addNamespace:(refMe's NSXMLNode's namespaceWithName:("") stringValue:("urn:oasis:names:tc:opendocument:xmlns:container"))
###【B】子要素 rootfiles エレメント
set ocidRootFilesElement to refMe's NSXMLElement's alloc()'s initWithName:"rootfiles"
###【C】Bの子要素 rootfileノード
set ocidRootFilesNode to refMe's NSXMLElement's alloc()'s initWithName:"rootfile"
##【C】にアトリビュートを追加
ocidRootFilesNode's addAttribute:(refMe's NSXMLNode's attributeWithName:("full-path") stringValue:("OPS/content.opf"))
ocidRootFilesNode's addAttribute:(refMe's NSXMLNode's attributeWithName:("media-type") stringValue:("application/oebps-package+xml"))
## ↑からの子要素をセット(【B】に【C】を追加)
ocidRootFilesElement's addChild:(ocidRootFilesNode)
## ↑からの子要素をセット(【A】に【B】を追加)
ocidRootElement's addChild:(ocidRootFilesElement)
## ↑からのROOTエレメントをセットしてXMLとする  【A】をXMLドキュメントに
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidContainerFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)

##################
###◆ 【2−2】com.apple.ibooks.display-options.xml
##ファイルパス
set ocidContainerFilePathURL to ocidMetaDirPathURL's URLByAppendingPathComponent:("com.apple.ibooks.display-options.xml") isDirectory:false
###【A】ROOT エレメント
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"display_options"
###【B】子要素 platform エレメント
set ocidPlatformElement to refMe's NSXMLElement's alloc()'s initWithName:("platform")
###【B】にアトリビュートを追加
ocidPlatformElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("*"))
###【C】Bの子要素としてのoption エレメント
set ocidOptionElement to refMe's NSXMLElement's elementWithName:("option")
###【C】にアトリビュートを追加
ocidOptionElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("specified-fonts"))
###【C】にテキストの値を設定
ocidOptionElement's setStringValue:("false")
## 子要素をセット 【C】を【B】に追加
ocidPlatformElement's addChild:(ocidOptionElement)
## ↑からの子要素をセット 【B】を【A】に追加
ocidRootElement's addChild:(ocidPlatformElement)
## ↑からのROOTエレメントをセットしてXMLとする 【A】をXMLドキュメントにする
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidRootElement)
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
###XML形式のテキストに出力
set ocidSaveStrings to ocidOutPutXML's XMLString()
###改行コードを指定して
ocidSaveStrings's appendString:"\n"
##保存
set listDone to ocidSaveStrings's writeToURL:(ocidContainerFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


return


##############################
### 今の日付日間 テキスト
##############################
to doGetDateNo(argDateFormat)
  ####日付情報の取得
  set ocidDate to current application's NSDate's |date|()
  ###日付のフォーマットを定義
  set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX")
  set ocidTimeZone to refMe's NSTimeZone's alloc()'s initWithName:"Asia/Tokyo"
ocidNSDateFormatter's setTimeZone:(ocidTimeZone)
ocidNSDateFormatter's setDateFormat:(argDateFormat)
  set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
  set strDateAndTime to ocidDateAndTime as text
return strDateAndTime
end doGetDateNo


|

SVG画像のサイズを求める


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

on run
  
  set aliasIconPass to (POSIX file "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns") as alias
  set strDialogText to "ドロップしても利用できます"
  set strTitleText to "画像ファイルを選んでください"
  set listButton to {"ファイルを選びます", "キャンセル"} as list
display dialog strDialogText buttons listButton default button 1 cancel button 2 with title strTitleText with icon aliasIconPass giving up after 1 with hidden answer
  
  set aliasDefaultLocation to (path to desktop folder from user domain) as alias
  set listChooseFileUTI to {"public.svg-image"}
  set strPromptText to "イメージファイルを選んでください" as text
  set strPromptMes to "イメージファイルを選んでください" as text
  set listAliasFilePath to (choose file strPromptMes with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with showing package contents, invisibles and multiple selections allowed) as list
  
  -->値をOpenに渡たす
open listAliasFilePath
end run


on open listAliasFilePath
  
  ##########################
  ####ファイルの数だけ繰り返し
  repeat with itemAliasFilePath in listAliasFilePath
    ####まずはUNIXパスにして
    set strFilePath to (POSIX path of itemAliasFilePath) as text
    set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
    set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
    set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath))
    ####################################
    ##サイズ取得
    #ファイルを読み込み
    set listReadData to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(refMe's NSXMLNodeOptionsNone) |error|:(reference))
    set ocidXmlDoc to (item 1 of listReadData)
    #ROOTエレメントを取得して
    set ocidRootElement to ocidXmlDoc's rootElement
    #viewBoxを取得
    set ocidViewBox to (ocidRootElement's attributeForName:("viewBox"))
    #テキストにして
    set ocidViewBoxStr to ocidViewBox's stringValue()
    #スペースを区切り文字でリストにして
    set ocidViewBoxArray to (ocidViewBoxStr's componentsSeparatedByString:(" "))
    #3番目と4番目が横縦ピクセルサイズ
    set ocidPixelWidth to (ocidViewBoxArray's objectAtIndex:(2))
    set ocidPixelHeight to (ocidViewBoxArray's objectAtIndex:(3))
log ocidPixelWidth as integer
log ocidPixelHeight as integer
  end repeat
end open


|

TSV2AdobeXML タブ区切りテキストからAdobe Illustratorの変数印字用の『変数ライブラリ』を生成する(1ページに複数面付け版)

TSV2AdobeXML タブ区切りテキストからAdobe Illustratorの変数印字用の『変数ライブラリ』を生成する
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-bba3c3.html

複数項目を1ページ内に面付けする用

ダウンロード - tsv2adobexml4entries.zip



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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
TSVタブ区切りテキストから
Adobe Illustrator用の変数用のXMLを生成します

設定項目で1ページに面付けする数を設定してください
デフォルトは10です
-->1ページに10件分のデータを割り付けます

【制限事項】その1
TSVの1行目の項目がデータセット名になります
表の1行目が項目名称になるようなTSVで利用してください
【制限事項】その2
可変テキストのみ設定可能です
他の要素の付与はご相談ください
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
set appFileManager to refMe's NSFileManager's defaultManager()

#################################
### 【1】設定項目
#################################
#1ページの面付け数
set numPageEntries to 10 as integer

#################################
### 【1】入力ファイル
#################################
#ダイアログ
tell current application
  set strName to name as text
end tell
#スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#デフォルトロケーション
tell application "Finder"
  set aliasPathToMe to (path to me) as alias
  set aliasContainerDir to (container of aliasPathToMe) as alias
end tell
#
set listUTI to {"public.tab-separated-values-text"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath to (choose file strMes with prompt strPrompt default location aliasContainerDir of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is (missing value) then
return "選んでください"
end if
#ファイルパス
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
#################################
### 【2】保存先
#################################
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasContainerDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
set strMes to "フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください\n同名ファイルがある場合\n『上書き』になります" as text
try
  ###ダイアログを前面に出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  #
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasContainerDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
#戻り値エイリアスをURLに
set strSaveDirPath to (POSIX path of aliasResponse) as text
set ocidSaveDirPathStr to (refMe's NSString's stringWithString:(strSaveDirPath))
set ocidSaveDirPath to ocidSaveDirPathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveDirPath) isDirectory:true)
##出力用ファイルパス
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("variables.xml")
#################################
### 【3】本処理
#################################
#ファイル読み込み
set listResponse to (refMe's NSString's alloc()'s initWithContentsOfURL:(ocidFilePathURL) usedEncoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
set ocidReadString to (item 1 of listResponse)
if ocidReadString = (missing value) then
return "文字コードを判定出来ませんでした : " & strFileName
end if

#改行コードをUNIXに強制
set ocidCRChar to refMe's NSString's stringWithString:("\r")
set ocidLFChar to refMe's NSString's stringWithString:("\n")
set ocidCRLFChar to refMe's NSString's stringWithString:("\r\n")
set ocidReadStringsA to ocidReadString's stringByReplacingOccurrencesOfString:(ocidCRLFChar) withString:(ocidLFChar)
set ocidReadStrings to ocidReadStringsA's stringByReplacingOccurrencesOfString:(ocidCRChar) withString:(ocidLFChar)

#改行毎でリストにする
set ocidCharSet to (refMe's NSCharacterSet's newlineCharacterSet)
set ocidLineArray to (ocidReadStrings's componentsSeparatedByCharactersInSet:(ocidCharSet))

#出力用のリスト
set ocidEditLineArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)

#読み取ったデータに項目連番を入れておく
set numCntLineNo to 0 as integer
repeat with itemLineArray in ocidLineArray
  set ocidEditLineText to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
  if numCntLineNo = 0 then
    set strAppendText to ("rowno\t") as text
(ocidEditLineText's appendString:(strAppendText))
(ocidEditLineText's appendString:(itemLineArray))
  else
    if (itemLineArray as text) is "" then
      exit repeat
    end if
    #タブ区切りで挿入
    set strAppendText to (numCntLineNo & "\t") as text
(ocidEditLineText's appendString:(strAppendText))
(ocidEditLineText's appendString:(itemLineArray))
  end if
(ocidEditLineArray's addObject:(ocidEditLineText))
  #カウントアップ
  set numCntLineNo to (numCntLineNo + 1) as integer
end repeat

#最初の1行目だけ別で取得しておく
set ocidFirstObjectString to ocidEditLineArray's firstObject()
set ocidFirstRowArray to ocidFirstObjectString's componentsSeparatedByString:("\t")

################################
###XML初期化
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setVersion:("1.0")
ocidXMLDoc's setCharacterEncoding:("utf-8")
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentXMLKind)
###DTD生成
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("svg")
ocidDTD's setPublicID:("-//W3C//DTD SVG 20001102//EN")
ocidDTD's setSystemID:("http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd")
#Entitry付与
set strEntitry to ("<!ENTITY ns_graphs \"http://ns.adobe.com/Graphs/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_vars \"http://ns.adobe.com/Variables/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_imrep \"http://ns.adobe.com/ImageReplacement/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_custom \"http://ns.adobe.com/GenericCustomNamespace/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_flows \"http://ns.adobe.com/Flows/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_extend \"http://ns.adobe.com/Extensibility/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
##DTDをXMLDOCにセット
ocidXMLDoc's setDTD:(ocidDTD)
###ROOTエレメント
set ocidRootElement to refMe's NSXMLElement's elementWithName:("svg")
#【1】variableSets
set ocidVsetsElement to refMe's NSXMLElement's elementWithName:("variableSets")
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("") stringValue:("&ns_vars;")
ocidVsetsElement's addNamespace:(ocidSetNameSpace)

#【2】variableSet
set ocidVsetElement to refMe's NSXMLElement's elementWithName:("variableSet")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("varSetName") stringValue:("binding1"))
(ocidVsetElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("locked") stringValue:("none"))
(ocidVsetElement's addAttribute:(ocidAddNode))

#【3−1】variables
set ocidVariablesElement to refMe's NSXMLElement's elementWithName:("variables")
################
#【3−2】variable
(*
可変テキスト:trait="textcontent" category="&ns_flows;"
フィアルパス:trait="fileref" category="&ns_vars;"
表示有無:trait="visibility" category="&ns_vars;"
表示有無?:trait="graphdata" category="&ns_graphs;"
*)
###########################
##ページレイアウト
###########################
repeat with itemEntries from 1 to numPageEntries by 1
  #【3−2−1】連番用の追加項目
  set ocidVariableElement to (refMe's NSXMLElement's elementWithName:("variable"))
  
  #【3−2−2】読み込みデータの項目
  repeat with itemFirstRowArray in ocidFirstRowArray
    set strFirstRowArray to itemFirstRowArray as text
    set ocidVariableElement to (refMe's NSXMLElement's elementWithName:("variable"))
    #ページのエントリー数を入れる
    set strSetVarName to ("E" & itemEntries & "-" & strFirstRowArray) as text
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("varName") stringValue:(strSetVarName))
(ocidVariableElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("category") stringValue:("&ns_flows;"))
(ocidVariableElement's addAttribute:(ocidAddNode))
    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("trait") stringValue:("textcontent"))
(ocidVariableElement's addAttribute:(ocidAddNode))
    #【3−2−2】variableを【3−1】variablesにセット
(ocidVariablesElement's addChild:(ocidVariableElement))
  end repeat
end repeat

################
#【4−1】DataSets
set ocidDataSetsElement to refMe's NSXMLElement's elementWithName:("v:sampleDataSets")
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("v") stringValue:("&ns_vars;")
ocidDataSetsElement's addNamespace:(ocidSetNameSpace)
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("") stringValue:("&ns_custom;")
ocidDataSetsElement's addNamespace:(ocidSetNameSpace)

################
#【4−2】DataSet
#データのリスト行数 先頭行の項目名行を除くので1引く
set numCntEditArray to ((count of ocidEditLineArray) - 1) as integer
#データの行数から何ページ分のデータ=dataSetの数
set numMakePage to (round of (numCntEditArray / numPageEntries) rounding up) as integer
#取り出すデータ行番号初期化
set numCntRowNoAll to 1 as integer
#作成される予定ページ数=dataSetの数ぶん繰り返す
repeat with itemdataSet from 1 to numMakePage by 1
  #【4−2】DataSetのエレメント
  set ocidDataSetElement to (refMe's NSXMLElement's elementWithName:("v:sampleDataSet"))
  #DataSetのアトリビュートに項目番号+2列目のデータで命名する
  set strSetDataSetName to (itemdataSet & ":ページ目") as text
  #↑の内容でdataSetNameをセット
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("dataSetName") stringValue:(strSetDataSetName))
(ocidDataSetElement's addAttribute:(ocidAddNode))
  #1ページに入る行目数分くりかえし
  repeat with itemPageEntries from 1 to numPageEntries by 1
    #指定行数の行データを取得
    set ocidRowStrings to (ocidEditLineArray's objectAtIndex:(numCntRowNoAll))
    #区切り文字タブでリストにして
    set ocidRowArray to (ocidRowStrings's componentsSeparatedByString:("\t"))
    #OS用の0スタートで行の項目数
    set numCntRowItemAll to ((count of ocidRowArray) - 1) as integer
    #行項目のリストから取得するための項目数初期化
    set numCntRowItem to 0 as integer
    #項目の数だけ繰り返し
    repeat with itemFirstRowArray in ocidFirstRowArray
      #ページ内での項目数+項目名でセット
      set strSetVarName to ("E" & itemPageEntries & "-" & itemFirstRowArray) as text
      set ocidDataSetChildElement to (refMe's NSXMLElement's elementWithName:(strSetVarName))
      #対象行列データを取得
      set strSetValieRowItem to (ocidRowArray's objectAtIndex:(numCntRowItem)) as text
      #Pエレメント内にテキストとして値をセット
      set ocidPElement to (refMe's NSXMLElement's elementWithName:("p"))
(ocidPElement's setStringValue:(strSetValieRowItem))
(ocidDataSetChildElement's addChild:(ocidPElement))
(ocidDataSetElement's addChild:(ocidDataSetChildElement))
      #カウントアップ
      set numCntRowItem to (numCntRowItem + 1) as integer
    end repeat
    set numCntRowNoAll to numCntRowNoAll + 1 as integer
    #データ行項目数より行カウンターが多くなったら終わり
    if numCntRowNoAll > (numCntEditArray) then
      exit repeat
    end if
  end repeat
  #【4−2】DataSetを【4−1】DataSetsにセット
(ocidDataSetsElement's addChild:(ocidDataSetElement))
end repeat

#【3−1】variablesを【2】のvariableSetにセット
ocidVsetElement's addChild:(ocidVariablesElement)
#【4−1】DataSetsを【2】のvariableSetにセット
ocidVsetElement's addChild:(ocidDataSetsElement)
#【2】variableSetを【1】のvariableSetsにセット
ocidVsetsElement's addChild:(ocidVsetElement)
#【1】のvariableSetsをROOTにセット
ocidRootElement's addChild:(ocidVsetsElement)
#
################################
###保存
ocidXMLDoc's setRootElement:(ocidRootElement)
###NSXMLNodePrettyPrint形式でデータにして
###NSXMLNodeCompactEmptyElementにすると少しデータサイズが節約できる
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodeExpandEmptyElement)
###データをテキストに戻して
set ocidXMLString to refMe's NSString's alloc()'s initWithData:(ocidXMLdata) encoding:(refMe's NSUTF8StringEncoding)
###改行コードをWindowsに
set ocidSaveStrings to ocidXMLString's stringByReplacingOccurrencesOfString:(ocidLFChar) withString:(ocidCRLFChar)
###保存
set listDone to (ocidSaveStrings's writeToURL:(ocidSaveFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))

return




|

TSV2AdobeXML タブ区切りテキストからAdobe Illustratorの変数印字用の『変数ライブラリ』を生成する

TSV2AdobeXML タブ区切りテキストからAdobe Illustratorの変数印字用の『変数ライブラリ』を生成する(1ページに複数面付け版)
https://quicktimer.cocolog-nifty.com/icefloe/2024/03/post-143f05.html
もあります
このページのスクリプトは1ページに1項目版です

変数パネルを使った可変テキスト
1:変数パネルを出す
2:変数パネル
3:ハンバーガーから『変数ライブラリの読み込み』
4:読み込んだ状態
5:テキストオブジェクトを生成して
6:使用したい変数を選択してから『テキスト動的に設定』を実行
7:動作確認

ダウンロード - makevariables.zip


1:変数パネルを出す
1_20240306130101
2:変数パネル
2_20240306130101
3:ハンバーガーから『変数ライブラリの読み込み』
3_20240306130101
4:読み込んだ状態
4_20240306130101
5:テキストオブジェクトを生成して
5_20240306130101
6:使用したい変数を選択してから『テキスト動的に設定』を実行
6_20240306130101
7:動作確認
7_20240306130101


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
TSVタブ区切りテキストから
Adobe Illustrator用の変数用のXMLを生成します
【制限事項】その1
TSVの1行目の項目がデータセット名になります
表の1行目が項目名称になるようなTSVで利用してください
【制限事項】その2
可変テキストのみ設定可能です
他の要素の付与はご相談ください
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
set appFileManager to refMe's NSFileManager's defaultManager()


#################################
### 【1】入力ファイル
#################################
#ダイアログ
tell current application
  set strName to name as text
end tell
#スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#デフォルトロケーション
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
#
set listUTI to {"public.tab-separated-values-text"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set aliasFilePath to (choose file strMes with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
if aliasFilePath is (missing value) then
return "選んでください"
end if
#ファイルパス
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
#################################
### 【2】保存先
#################################
set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
set aliasContainerDirPath to (ocidContainerDirPathURL's absoluteURL()) as alias
set strMes to "フォルダを選んでください" as text
set strPrompt to "保存先フォルダを選択してください\n同名ファイルがある場合\n『上書き』になります" as text
try
  ###ダイアログを前面に出す
  set strName to (name of current application) as text
  if strName is "osascript" then
    tell application "Finder" to activate
  else
    tell current application to activate
  end if
  #
  set aliasResponse to (choose folder strMes with prompt strPrompt default location aliasContainerDirPath with invisibles and showing package contents without multiple selections allowed) as alias
on error
log "エラーしました"
return "エラーしました"
end try
#戻り値エイリアスをURLに
set strSaveDirPath to (POSIX path of aliasResponse) as text
set ocidSaveDirPathStr to (refMe's NSString's stringWithString:(strSaveDirPath))
set ocidSaveDirPath to ocidSaveDirPathStr's stringByStandardizingPath()
set ocidSaveDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSaveDirPath) isDirectory:true)
##出力用ファイルパス
set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("variables.xml")
#################################
### 【3】本処理
#################################
#ファイル読み込み
set listResponse to (refMe's NSString's alloc()'s initWithContentsOfURL:(ocidFilePathURL) usedEncoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
set ocidReadString to (item 1 of listResponse)
if ocidReadString = (missing value) then
return "文字コードを判定出来ませんでした : " & strFileName
end if

#改行コードをUNIXに強制
set ocidCRChar to refMe's NSString's stringWithString:("\r")
set ocidLFChar to refMe's NSString's stringWithString:("\n")
set ocidCRLFChar to refMe's NSString's stringWithString:("\r\n")
set ocidReadStringsA to ocidReadString's stringByReplacingOccurrencesOfString:(ocidCRLFChar) withString:(ocidLFChar)
set ocidReadStrings to ocidReadStringsA's stringByReplacingOccurrencesOfString:(ocidCRChar) withString:(ocidLFChar)
#改行毎でリストにする
set ocidCharSet to (refMe's NSCharacterSet's newlineCharacterSet)
set ocidLineArray to (ocidReadStrings's componentsSeparatedByCharactersInSet:(ocidCharSet))
#出力用のリスト
set ocidEditLineArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
#読み取ったデータに項目連番を入れておく
set numCntLineNo to 0 as integer
repeat with itemLineArray in ocidLineArray
  set ocidEditLineText to (refMe's NSMutableString's alloc()'s initWithCapacity:(0))
  if numCntLineNo = 0 then
    set strAppendText to ("rowno\t") as text
(ocidEditLineText's appendString:(strAppendText))
(ocidEditLineText's appendString:(itemLineArray))
  else
    if (itemLineArray as text) is "" then
      exit repeat
    end if
    set strAppendText to (numCntLineNo & "\t") as text
(ocidEditLineText's appendString:(strAppendText))
(ocidEditLineText's appendString:(itemLineArray))
  end if
(ocidEditLineArray's addObject:(ocidEditLineText))
  #カウントアップ
  set numCntLineNo to (numCntLineNo + 1) as integer
end repeat

#最初の1行目だけ別で取得しておく
set ocidFirstObjectString to ocidEditLineArray's firstObject()
set ocidFirstRowArray to ocidFirstObjectString's componentsSeparatedByString:("\t")

################################
###XML初期化
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setVersion:("1.0")
ocidXMLDoc's setCharacterEncoding:("utf-8")
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentXMLKind)
###DTD生成
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("svg")
ocidDTD's setPublicID:("-//W3C//DTD SVG 20001102//EN")
ocidDTD's setSystemID:("http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd")
#Entitry付与
set strEntitry to ("<!ENTITY ns_graphs \"http://ns.adobe.com/Graphs/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_vars \"http://ns.adobe.com/Variables/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_imrep \"http://ns.adobe.com/ImageReplacement/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_custom \"http://ns.adobe.com/GenericCustomNamespace/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_flows \"http://ns.adobe.com/Flows/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
#Entitry付与
set strEntitry to ("<!ENTITY ns_extend \"http://ns.adobe.com/Extensibility/1.0/\">") as text
set ocidEntitry to refMe's NSString's stringWithString:(strEntitry)
set ocidEntityNode to refMe's NSXMLDTDNode's alloc()'s initWithXMLString:(ocidEntitry)
ocidEntityNode's setDTDKind:(refMe's NSXMLAttributeEntityKind)
ocidDTD's addChild:(ocidEntityNode)
##DTDをXMLDOCにセット
ocidXMLDoc's setDTD:(ocidDTD)
###ROOTエレメント
set ocidRootElement to refMe's NSXMLElement's elementWithName:("svg")
#【1】variableSets
set ocidVsetsElement to refMe's NSXMLElement's elementWithName:("variableSets")
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("") stringValue:("&ns_vars;")
ocidVsetsElement's addNamespace:(ocidSetNameSpace)

#【2】variableSet
set ocidVsetElement to refMe's NSXMLElement's elementWithName:("variableSet")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("varSetName") stringValue:("binding1"))
(ocidVsetElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("locked") stringValue:("none"))
(ocidVsetElement's addAttribute:(ocidAddNode))

#【3−1】variables
set ocidVariablesElement to refMe's NSXMLElement's elementWithName:("variables")
################
#【3−2】variable
(*
可変テキスト:trait="textcontent" category="&ns_flows;"
フィアルパス:trait="fileref" category="&ns_vars;"
表示有無:trait="visibility" category="&ns_vars;"
表示有無?:trait="graphdata" category="&ns_graphs;"
*)
#【3−2−1】連番用の追加項目
set ocidVariableElement to (refMe's NSXMLElement's elementWithName:("variable"))

#【3−2−2】読み込みデータの項目
repeat with itemFirstRowArray in ocidFirstRowArray
  set strFirstRowArray to itemFirstRowArray as text
  set ocidVariableElement to (refMe's NSXMLElement's elementWithName:("variable"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("varName") stringValue:(strFirstRowArray))
(ocidVariableElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("category") stringValue:("&ns_flows;"))
(ocidVariableElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("trait") stringValue:("textcontent"))
(ocidVariableElement's addAttribute:(ocidAddNode))
  #【3−2−2】variableを【3−1】variablesにセット
(ocidVariablesElement's addChild:(ocidVariableElement))
end repeat

################
#【4−1】DataSets
set ocidDataSetsElement to refMe's NSXMLElement's elementWithName:("v:sampleDataSets")
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("v") stringValue:("&ns_vars;")
ocidDataSetsElement's addNamespace:(ocidSetNameSpace)
set ocidSetNameSpace to refMe's NSXMLNode's namespaceWithName:("") stringValue:("&ns_custom;")
ocidDataSetsElement's addNamespace:(ocidSetNameSpace)
################
#【4−2】DataSet
#データのリストの数
set numCntEditArray to (count of ocidEditLineArray) as integer
#データリストの2行目から最後まで繰り返す
repeat with itemIntNo from 1 to (numCntEditArray - 1) by 1
  #【4−2】DataSetのエレメント
  set ocidDataSetElement to (refMe's NSXMLElement's elementWithName:("v:sampleDataSet"))
  #DataSetのアトリビュートに項目番号+2列目のデータで命名する
  set ocidRowStrings to (ocidEditLineArray's objectAtIndex:(itemIntNo))
  set ocidRowArray to (ocidRowStrings's componentsSeparatedByString:("\t"))
  #ここが行番号
  set strRowNo to (ocidRowArray's objectAtIndex:(0)) as text
  #ここが2列目
  set strRowName to (ocidRowArray's objectAtIndex:(1)) as text
  #データセット名にする
  set strSetName to (strRowNo & ":" & strRowName) as text
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("dataSetName") stringValue:(strSetName))
(ocidDataSetElement's addAttribute:(ocidAddNode))
  #【4−2】の子要素の生成
  set numCntFirstRowArray to (count of ocidFirstRowArray) as integer
  repeat with itemIntNo from 0 to (numCntFirstRowArray - 1) by 1
    set ocidFirstRowValue to (ocidFirstRowArray's objectAtIndex:(itemIntNo))
    set ocidDataSetChildElement to (refMe's NSXMLElement's elementWithName:(ocidFirstRowValue))
    #Pパラグラフのエレメントのテキストの値として生成する
    set strSetRowItem to (ocidRowArray's objectAtIndex:(itemIntNo))
    set ocidPElement to (refMe's NSXMLElement's elementWithName:("p"))
    #テキストの値を入れる
(ocidPElement's setStringValue:(strSetRowItem))
(ocidDataSetChildElement's addChild:(ocidPElement))
(ocidDataSetElement's addChild:(ocidDataSetChildElement))
  end repeat
(ocidDataSetsElement's addChild:(ocidDataSetElement))
end repeat

#【3−1】のvariablesを【2】のvariableSetにセット
ocidVsetElement's addChild:(ocidVariablesElement)
#【4−1】DataSetsを【2】のvariableSetにセット
ocidVsetElement's addChild:(ocidDataSetsElement)
#【2】variableSetを【1】のvariableSetsにセット
ocidVsetsElement's addChild:(ocidVsetElement)
#【1】のvariableSetsをROOTにセット
ocidRootElement's addChild:(ocidVsetsElement)
#
################################
###保存
ocidXMLDoc's setRootElement:(ocidRootElement)
###NSXMLNodePrettyPrint形式でデータにして
###NSXMLNodeCompactEmptyElementにすると少しデータサイズが節約できる
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodeExpandEmptyElement)
###データをテキストに戻して
set ocidXMLString to refMe's NSString's alloc()'s initWithData:(ocidXMLdata) encoding:(refMe's NSUTF8StringEncoding)
###改行コードをWindowsに
set ocidSaveStrings to ocidXMLString's stringByReplacingOccurrencesOfString:(ocidLFChar) withString:(ocidCRLFChar)
###保存
set listDone to (ocidSaveStrings's writeToURL:(ocidSaveFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))

return




|

[XML]XMLとしてSVGを生成する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "UniformTypeIdentifiers"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
set appFileManager to refMe's NSFileManager's defaultManager()


###設定
set strWidth to ("360") as text
set strHight to ("720") as text
set strText to ("美しい日本語") as text
set strFontSize to ("36") as text
#
set strTextRange to (strFontSize * (count of strText))

###【1】保存先ファイルパス
###デスクトップ
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
###保存ファイルURL
set strFileName to ("test.svg") as text
set ocidSaveFilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:(strFileName)

###【2】XML生成
set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setVersion:("1.0")
ocidXMLDoc's setCharacterEncoding:("UTF-8")
ocidXMLDoc's setStandalone:("no")
(*
NSXMLDocumentXMLKind: XML形式
NSXMLDocumentXHTMLKind: XHTML形式の
NSXMLDocumentHTMLKind: HTML形式の
NSXMLDocumentTextKind: プレーンテキスト形式
*)
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentXMLKind)

###【3】DTD生成
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("svg")
ocidDTD's setPublicID:("-//W3C//DTD SVG 1.1//EN")
ocidDTD's setSystemID:("http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd")
####【3-1】DTDをXMLにセットする
ocidXMLDoc's setDTD:(ocidDTD)

###【4】ROOTエレメントを生成
set ocidRootElement to refMe's NSXMLElement's elementWithName:("svg")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("version") stringValue:("1.1")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("xmlns") stringValue:("http://www.w3.org/2000/svg")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("xmlns:xlink") stringValue:("http://www.w3.org/1999/xlink")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("xml:space") stringValue:("preserve")
ocidRootElement's addAttribute:(ocidAddNode)
#背景色を指定する場合はここ
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("style") stringValue:("fill-rule:nonzero;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("width") stringValue:("" & strWidth & ".0px")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("height") stringValue:("" & strHight & ".0px")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("viewBox") stringValue:("0 0 " & strWidth & " " & strHight & "")
ocidRootElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("stroke-miterlimit") stringValue:("10")
ocidRootElement's addAttribute:(ocidAddNode)
###【4-1】defs ここは空で
set ocidDefsElement to refMe's NSXMLElement's elementWithName:("defs")
ocidRootElement's addChild:(ocidDefsElement)
###【4-2】path一番下のレイヤー
set ocidBackgroundElement to refMe's NSXMLElement's elementWithName:("path")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("d") stringValue:("M0 0L" & strWidth & " 0L" & strWidth & " " & strHight & "L0 " & strHight & "L0 0Z")
ocidBackgroundElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("fill") stringValue:("#AAAAAA")
ocidBackgroundElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("fill-rule") stringValue:("nonzero")
ocidBackgroundElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("opacity") stringValue:("1")
ocidBackgroundElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("stroke") stringValue:("none")
ocidBackgroundElement's addAttribute:(ocidAddNode)
#【4-2】pathをrootエレメントにセット
ocidRootElement's addChild:(ocidBackgroundElement)
###【4-3】g
set ocidGElement to refMe's NSXMLElement's elementWithName:("g")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("text")
ocidGElement's addAttribute:(ocidAddNode)
###【4-3-1】text
set ocidTextElement to refMe's NSXMLElement's elementWithName:("text")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("fill") stringValue:("#000000")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("font-family") stringValue:("mono")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("font-size") stringValue:("" & strFontSize & "")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("opacity") stringValue:("1")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("stroke") stringValue:("none")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("x") stringValue:("0")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("y") stringValue:("0")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("text-anchor") stringValue:("start")
ocidTextElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("transform") stringValue:("matrix(1 0 0 1 0 360)")
ocidTextElement's addAttribute:(ocidAddNode)
###【4-3-2】tspan
set ocidTSpanElement to refMe's NSXMLElement's elementWithName:("tspan")
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("x") stringValue:("0")
ocidTSpanElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("y") stringValue:("0")
ocidTSpanElement's addAttribute:(ocidAddNode)
set ocidAddNode to refMe's NSXMLNode's attributeWithName:("textLength") stringValue:(strTextRange)
ocidTSpanElement's addAttribute:(ocidAddNode)
ocidTSpanElement's setStringValue:(strText)

#######
#【4-3-2】tspan を【4-3-1】textの子要素にセット
ocidTextElement's addChild:(ocidTSpanElement)
#【4-3-1】textを 【4-3】gの子要素にセット
ocidGElement's addChild:(ocidTextElement)
#【4-3】gをrootエレメントの子要素としてセット
ocidRootElement's addChild:(ocidGElement)
#【4-3】ROOTエレメントXMLにセットする
ocidXMLDoc's setRootElement:(ocidRootElement)
###【5】XMLデータにして(ここでテキスト形式のXMLに)
set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
###【6】ファイルに保存
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)


return


|

[SVG] adobe illustrator の編集機能 adobe_illustrator_pgfを削除する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
(*
adobe_illustrator_pgf
Preserve Graphic Formatを削除する
*)
# 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
property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

set listUTI to {"public.svg", "public.svgz", "public.svg-image"}

##XML宣言の無いSVGの場合の処理
# ture --> XML処理をする
# false --> XML処理をせず手を加えずそのままにする
set boolDoXML to false as boolean


###################################
#####入力ダイアログ
###################################
##デフォルトパス
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
set strPromptText to "SVGファイルを選んでください" as text
set strMesText to "SVGファイルを選んでください" as text
set listAliasFilePath to (choose file strMesText with prompt strPromptText default location (aliasDesktopDirPath) of type listUTI with invisibles and multiple selections allowed without showing package contents) as list

###################################
#####保存先
###################################
set ocidSaveDirPathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:("SVG処理済")
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
set aliasSaveDirPathURL to (ocidSaveDirPathURL's absoluteURL()) as alias
###################################
#####入力ファイルの数だけ繰り返し
###################################

repeat with itemAliasFilePath in listAliasFilePath
  set aliasFilePath to itemAliasFilePath as alias
  set strFilePath to (POSIX path of aliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  set ocidFileName to ocidFilePathURL's lastPathComponent()
  #保存先
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName))
  ####UTIの取得
  set listResourceValue to (ocidFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
  set ocidContentType to (item 2 of listResourceValue)
  set strUTI to (ocidContentType's identifier) as text
  ###拡張子
  set strExtensionName to (ocidFilePathURL's pathExtension()) as text
  
  if strUTI is "public.svgz" then
return "圧縮SVGは処理しない"
    set ocidOption to (refMe's NSFileManagerItemReplacementWithoutDeletingBackupItem)
    set listDone to (appFileManager's replaceItemAtURL:(ocidSaveFilePathURL) withItemAtURL:(ocidFilePathURL) backupItemName:(missing value) options:(ocidOption) resultingItemURL:(missing value) |error|:(reference))
    set listDone to (appFileManager's copyItemAtURL:(ocidSaveFilePathURL) toURL:(ocidFilePathURL) |error|:(reference))
  else if strExtensionName is "svgz" then
return "圧縮SVGは処理しない"
    set ocidOption to (refMe's NSFileManagerItemReplacementWithoutDeletingBackupItem)
    set listDone to (appFileManager's replaceItemAtURL:(ocidSaveFilePathURL) withItemAtURL:(ocidFilePathURL) backupItemName:(missing value) options:(ocidOption) resultingItemURL:(missing value) |error|:(reference))
    set listDone to (appFileManager's copyItemAtURL:(ocidSaveFilePathURL) toURL:(ocidFilePathURL) |error|:(reference))
  end if
  ###【1】ファイル読み込み
  ##NSDATAに読み込んで
  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
  set listReadData to (refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference))
  set ocidReadData to (item 1 of listReadData)
  ###DTDを保存した形式でXMLドキュメントにする
  set ocidOption to (refMe's NSXMLNodePreserveCDATA as integer) + (refMe's NSXMLNodePreserveWhitespace as integer)
  set listReadXMLDoc to (refMe's NSXMLDocument's alloc()'s initWithData:(ocidReadData) options:(ocidOption) |error|:(reference))
  set ocidReadXMLDoc to (item 1 of listReadXMLDoc)
  ##XML宣言があるか?チェック用にXMLとして読み込む
  set ocidOption to (refMe's NSXMLDocumentTidyXML)
  set listReadXMLFile to (refMe's NSXMLDocument's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference))
  set ocidReadXMLFile to (item 1 of listReadXMLFile)
  ###XML宣言の有無チェック
  set ocidError to (item 2 of listReadXMLFile)
  if ocidError = (missing value) then
log "svgタグから始まるpublic.svg-image xml宣言が無いタイプ"
    if boolDoXML is false then
log "XML宣言の無いSVGは処理しない"
      set listDone to (appFileManager's copyItemAtURL:(ocidFilePathURL) toURL:(ocidSaveFilePathURL) |error|:(reference))
      if (item 1 of listDone as boolean) is false then
        set ocidOption to (refMe's NSFileManagerItemReplacementWithoutDeletingBackupItem)
        set listDone to (appFileManager's replaceItemAtURL:(ocidSaveFilePathURL) withItemAtURL:(ocidFilePathURL) backupItemName:(missing value) options:(ocidOption) resultingItemURL:(missing value) |error|:(reference))
        set listDone to (appFileManager's copyItemAtURL:(ocidSaveFilePathURL) toURL:(ocidFilePathURL) |error|:(reference))
      end if
      
    else
      ##XML宣言が無い場合は新規でルートエレメントにテキストとして読み込み
      ##テキストで読み込みなおして
      set listReadStrings to (refMe's NSString's stringWithContentsOfURL:(ocidFilePathURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
      set ocidReadStrings to (item 1 of listReadStrings)
      ##ルートエレメントとしてエレメントにする
      set listReadSvgElement to (refMe's NSXMLElement's alloc()'s initWithXMLString:(ocidReadStrings) |error|:(reference))
      set ocidReadSvgElement to (item 1 of listReadSvgElement)
      ##ルートエレメントとして新規の保存用のXMLドキュメントにセットする
      set ocidReadXMLDoc to (refMe's NSXMLDocument's alloc()'s initWithRootElement:(ocidReadSvgElement))
(ocidReadXMLDoc's setVersion:"1.0")
(ocidReadXMLDoc's setCharacterEncoding:"UTF-8")
    end if
  else
log "xml宣言があるタイプ"
    ### DTD取得しておく
    set ocidReadDTD to ocidReadXMLDoc's DTD
  end if
  ###共通処理
  ###【2】ROOTエレメント
  set ocidRootElement to ocidReadXMLDoc's rootElement()
  ###【3】adobe_illustrator_pgfエレメント
  set ocidAiPgfArray to (ocidRootElement's elementsForName:("i:aipgf"))
  ##数を数えて
  set numCntAIPGF to (count of ocidAiPgfArray) as integer
  ##0なら編集機能はない
  if numCntAIPGF = 0 then
log "adobe_illustrator_pgfが見つかりませんので処理しません"
    ###そのままテキストで保存する この時XML宣言を付与する
    ###XML形式のテキストに出力
    set ocidSaveStrings to ocidReadXMLDoc's XMLString()
  else
log "adobe_illustrator_pgf イラストレーターの編集機能が見つかりました"
    ##ルートエレメントの子要素のArray
    set ocidChidArray to ocidRootElement's children()
    set numCntChild to 0 as integer
    ##子要素の数だけ繰り返し
    repeat with itemChild in ocidChidArray
      try
        ##子要素の名前を取得して
        set strChildName to itemChild's |name| as text
        ##adobe_illustrator_pgf なら削除する
        if strChildName is "i:aipgf" then
(ocidRootElement's removeChildAtIndex:(numCntChild))
        end if
      end try
      set numCntChild to numCntChild + 1 as integer
    end repeat
    ##adobe_illustrator_pgfを削除したXMLにDTDを追加して
(ocidReadXMLDoc's setDTD:(ocidReadDTD))
    ###テキストにする
    set ocidSaveStrings to ocidReadXMLDoc's XMLString()
  end if
  
  ###################################
  #####保存
  ###################################
  ###改行コードを指定して
(ocidSaveStrings's appendString:"\n")
  ##保存
  set listDone to (ocidSaveStrings's writeToURL:(ocidSaveFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference))
  
end repeat

##保存先を開く
# set appShardWorkspace to refMe's NSWorkspace's sharedWorkspace()
# set boolResults to appShardWorkspace's activateFileViewerSelectingURLs:({ocidSaveDirPathURL})

tell application "Finder"
make new Finder window to aliasSaveDirPathURL
activate
end tell
return


|

[svg]adobe_illustrator_pgf

Illustratorの編集機能を保持してSVG生成すると付与される

<i:aipgf  id="adobe_illustrator_pgf" i:pgfEncoding="zstd/base64" i:pgfVersion="24">
  <![CDATA[
ここにデータ
]]>
</i:aipgf>

基本的には削除して問題ない
Screen-3

Screen-4

ImageOptimでバッチ処理+クリーニングは可能だが
ImageOptimのSVGクリーニングは、結構ソースに手が入る(変更される)ので
ソースやIDの変更に伴なう『責任』を取れる場合のみの利用が良いだろう
グラデーションやアニメが使われているものは、クリーニングするにしても
オリジナルファイルを保持しておかないと何がおきても…ってことになる
Screen_5

|

[Python]SVGをPNGに変換

ダウンロード - svg2png.zip


#!/usr/bin/env python3
########################
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF, renderPM
import sys
import os

args = sys.argv

strFilePath = args[1]
strSavePath = args[2]

print("strFilePath:" + strFilePath)
print("strSavePath:" + strSavePath)

drawing = svg2rlg(strFilePath)
renderPDF.drawToFile(drawing, strSavePath)



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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "PDFKit"
use framework "Quartz"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

##設定項目
set strPyFileName to "svg2pdf.py"

###パス取得
set aliasPathToMe to path to me as alias
tell application "Finder"
  set aliasPathToMeContainerDir to container of aliasPathToMe as alias
end tell
###パスを生成
set strPathToMeContainerDir to POSIX path of aliasPathToMeContainerDir as text
set strBinPath to strPathToMeContainerDir & "bin/" as text
set strPyPath to strBinPath & strPyFileName as text
####ダイアログ用デスクトップパス
set aliasDefaultLocation to path to desktop folder from user domain as alias
####ダイアログ
set listAliasFilePath to (choose file with prompt "ファイルを選んでください" default location aliasDefaultLocation of type {"public.svg-image"} with multiple selections allowed without showing package contents and invisibles) as list

################################
###カラープロファイルを読み出しておく ファイルはお好みで
set strIccFilePath to "/System/Library/ColorSync/Profiles/sRGB Profile.icc"
set ocidIccFilePathStr to refMe's NSString's stringWithString:(strIccFilePath)
set ocidIccFilePath to ocidIccFilePathStr's stringByStandardizingPath
set ocidIccFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidIccFilePath) isDirectory:(false)
set ocidProfileData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidIccFilePathURL)

###ディレクトリ
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTempDirURL to appFileManager's temporaryDirectory()
set ocidUUID to refMe's NSUUID's alloc()'s init()
set ocidUUIDString to ocidUUID's UUIDString
set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:true
#
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
# 777-->511 755-->493 700-->448 766-->502
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)

####ファイルの数だけ繰り返し
repeat with itemAliasFilePath in listAliasFilePath
  ###UNIXパスに変換
  set strFilePath to (POSIX path of itemAliasFilePath) as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
  ##
  set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent()
  set ocidBaseFilePathURL to ocidFilePathURL's URLByDeletingPathExtension()
  set strBaseFileName to ocidBaseFilePathURL's lastPathComponent() as text
  
  ###PDFパス
  set strPDFFileName to (strBaseFileName & ".pdf") as text
  set ocidPDFFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(strPDFFileName) isDirectory:false)
  set strPDFSaveFilePath to (ocidPDFFilePathURL's |path|()) as text
  
  ###スクリプトに渡す
  set strCommandText to "\"" & strPyPath & "\" \"" & strFilePath & "\" \"" & strPDFSaveFilePath & "\"" as text
do shell script strCommandText
  
  
  ###PNGパス
  set strSaveFileName to (strBaseFileName & ".png") as text
  set ocidSaveFilePathURL to (ocidContainerDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:false)
  ###NSDATAに読み込む
  set ocidReadPdfData to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidPDFFilePathURL))
  ####NSPDFImageRepに変換
  set ocidPdfPep to (refMe's NSPDFImageRep's alloc()'s initWithData:(ocidReadPdfData))
  ##1ページ目を読み込み
(ocidPdfPep's setCurrentPage:0)
  ####ページデータをNSIMAGEに格納
  set ocidPageImageData to refMe's NSImage's alloc()'s init()
(ocidPageImageData's addRepresentation:ocidPdfPep)
  ###中間ファイルとしてのTIFFに変換
  set ocidOsDispatchData to ocidPageImageData's TIFFRepresentation()
  ####出力されるBmpImageRepに格納
  set ocidBmpImageRep to (refMe's NSBitmapImageRep's imageRepWithData:ocidOsDispatchData)
  ##PNG書出オプション
  set ocidPropertyDict to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0)
(ocidPropertyDict's setObject:true forKey:(refMe's NSImageInterlaced))
  ####ガンマ値が不要な場合はコメントアウト
(ocidPropertyDict's setObject:0.45455 forKey:(refMe's NSImageGamma))
(ocidPropertyDict's setObject:ocidProfileData forKey:(refMe's NSImageColorSyncProfileData))
  set ocidFileType to refMe's NSBitmapImageFileTypePNG
  ##変換
  set ocidNSInlineData to (ocidBmpImageRep's representationUsingType:(ocidFileType) |properties|:(ocidPropertyDict))
  #####保存
  set boolDone to (ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference))
  
end repeat



|

その他のカテゴリー

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