Illustrator

Illustratorの合成フォントファイルから使用されているフォント名を表示する

ダウンロード - 20240507_175450.html


あくまでも参考にしてください

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

サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004合成フォントファイル(書き出し保存したもの)を調べて
005含まれているフォント名を表示します
006com.cocolog-nifty.quicktimer.icefloe
007*)
008----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013
014property refMe : a reference to current application
015set boolDirExists to false as boolean
016
017
018##使用中のバージョン
019set listVersion to {"28", "27", "26"} as list
020
021###デフォルトロケーションタイプBアプリケーションサポート
022set appFileManager to refMe's NSFileManager's defaultManager()
023set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask))
024set ocidApplicatioocidupportDirPathURL to ocidURLsArray's firstObject()
025repeat with itemVarsion in listVersion
026  set ocidDirPathURL to (ocidApplicatioocidupportDirPathURL's URLByAppendingPathComponent:("Adobe/Adobe Illustrator " & itemVarsion & "/ja_JP/合成フォント"))
027  set ocidDirPath to ocidDirPathURL's |path|()
028  set boolDirExists to (appFileManager's fileExistsAtPath:(ocidDirPath) isDirectory:(true))
029  if boolDirExists is true then
030    set aliasDefaultLocation to (ocidDirPathURL's absoluteURL()) as alias
031    exit repeat
032  end if
033end repeat
034if boolDirExists is false then
035  ### デフォルトロケーションタイプAデスクトップ
036  set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
037  set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
038  set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
039end if
040set listUTI to {"public.data"}
041set strMes to ("合成フォントファイルを選んでください") as text
042set strPrompt to ("合成フォントファイルを選んでください") as text
043try
044  ### ファイル選択時
045  set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias
046on error
047  log "エラーしました"
048  return "エラーしました"
049end try
050
051#パス
052set strFilePath to (POSIX path of aliasFilePath) as text
053set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
054set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
055set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
056#データ読み込み
057set ocidOption to (refMe's NSDataReadingMappedIfSafe)
058set listResponse to refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference)
059if (item 2 of listResponse) ≠ (missing value) then
060  log (item 2 of listResponse)'s localizedDescription() as text
061  return "Data読み込みでエラーしました"
062else if (item 2 of listResponse) = (missing value) then
063  set ocidReadData to (item 1 of listResponse)
064end if
065#ここの100は調整する必要があるかも
066#テキストにするために不要な部分を削除
067set numOffSet to 100 as integer
068set ocidDataLength to ocidReadData's |length|()
069set ocidRage to refMe's NSRange's NSMakeRange(numOffSet, (ocidDataLength - numOffSet))
070repeat
071  #レンジの幅のみのデータを受け取り
072  set ocidTrimData to ocidReadData's subdataWithRange:(ocidRage)
073  #テキストに変換
074  set ocidReadText to refMe's NSString's alloc()'s initWithData:(ocidTrimData) encoding:(refMe's NSUTF8StringEncoding)
075  #エラーがなくなるまで繰り返し
076  if ocidReadText = (missing value) then
077    #ファイルの末尾の読み込みを削っていく
078    set ocidDataLength to ocidDataLength - 100
079    #レンジにして
080    set ocidRage to refMe's NSRange's NSMakeRange(numOffSet, (ocidDataLength))
081  else
082    exit repeat
083  end if
084end repeat
085
086#出力用のテキスト
087set ocidOutPutstring to refMe's NSMutableString's alloc()'s initWithCapacity:(0)
088#テキストにしたデータを改行毎リストに
089set ocidChrSet to refMe's NSCharacterSet's characterSetWithCharactersInString:("\r\n")
090set ocidReadArray to ocidReadText's componentsSeparatedByCharactersInSet:(ocidChrSet)
091#合成フォントIDを取得
092repeat with itemLine in ocidReadArray
093  set boolContain to (itemLine's hasPrefix:("%%BeginResource:"))
094  if boolContain is true then
095    set ocidInsText to (itemLine's stringByReplacingOccurrencesOfString:("%%BeginResource: Font ") withString:("合成フォントID\n"))
096    (ocidOutPutstring's appendString:(ocidInsText))
097    (ocidOutPutstring's appendString:("\n"))
098  end if
099end repeat
100#ソートして
101set ocidSelf to refMe's NSString's stringWithString:("self")
102set ocidSortedArray to ocidReadArray's sortedArrayUsingSelector:"localizedCaseInsensitiveCompare:"
103#可変リストにセット
104set ocidSortedArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
105ocidSortedArrayM's addObjectsFromArray:(ocidSortedArray)
106####重複行削除と不要行削除
107set numCntArray to ocidSortedArrayM's |count|()
108repeat with itemIntNo from (numCntArray - 1) to 1 by -1
109  set ocidLineText to (ocidSortedArrayM's objectAtIndex:(itemIntNo))
110  set boolContain to (ocidLineText's hasPrefix:("%%+ Font"))
111  if boolContain is true then
112    set strNextText to (ocidSortedArrayM's objectAtIndex:(itemIntNo - 1)) as text
113    if (ocidLineText as text) is strNextText then
114      (ocidSortedArrayM's removeObjectAtIndex:(itemIntNo))
115    end if
116  else
117    (ocidSortedArrayM's removeObjectAtIndex:(itemIntNo))
118  end if
119end repeat
120(ocidSortedArrayM's removeObjectAtIndex:(0))
121
122#戻り値用にテキストを整形
123(ocidOutPutstring's appendString:("使用されているフォント"))
124(ocidOutPutstring's appendString:("\n"))
125###置換
126repeat with itemArray in ocidSortedArrayM
127  set ocidPsFontName to (itemArray's stringByReplacingOccurrencesOfString:("%%+ Font ") withString:(""))
128  (ocidOutPutstring's appendString:(ocidPsFontName))
129  (ocidOutPutstring's appendString:("\n"))
130end repeat
131##############################
132#####ダイアログ
133##############################
134tell current application
135  set strName to name as text
136end tell
137if strName is "osascript" then
138  tell application "Finder"
139    activate
140  end tell
141else
142  tell current application
143    activate
144  end tell
145end if
146set aliasIconPath to (POSIX file "/Applications/Utilities/Adobe Sync/CoreSync/Core Sync.app/Contents/Resources/CreativeCloudIcons.icns") as alias
147set strMes to "Postscriptフォント名です"
148try
149  set recordResult to (display dialog strMes with title "戻り値です" default answer (ocidOutPutstring as text) buttons {"クリップボードにコピー", "終了", "再実行"} default button "再実行" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record
150on error
151  return "エラーしました"
152end try
153if (gave up of recordResult) is true then
154  return "時間切れです"
155end if
156##############################
157#####自分自身を再実行
158##############################
159if button returned of recordResult is "再実行" then
160  tell application "Finder"
161    set aliasPathToMe to (path to me) as alias
162  end tell
163  run script aliasPathToMe with parameters "再実行"
164end if
165##############################
166#####値のコピー
167##############################
168if button returned of recordResult is "クリップボードにコピー" then
169  try
170    set strText to text returned of recordResult as text
171    ####ペーストボード宣言
172    set appPasteboard to refMe's NSPasteboard's generalPasteboard()
173    set ocidText to (refMe's NSString's stringWithString:(strText))
174    appPasteboard's clearContents()
175    appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)
176  on error
177    tell application "Finder"
178      set the clipboard to strText as text
179    end tell
180  end try
181end if
182
183
184return 0
AppleScriptで生成しました

|

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の初期化(途中)

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

#!/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 scripting additions

property refMe : a reference to current application


#################################
########### DTD
#################################
set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setPublicID:"-//W3C//DTD SVG 20001102//EN"
ocidDTD's setSystemID:"http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd"
ocidDTD's setName:"svg"


#################################
### NSXMLDTDNode ここでは ENTITY
#################################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_graphs"
ocidDTDNode's setStringValue:"http://ns.adobe.com/Graphs/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_vars"
ocidDTDNode's setStringValue:"http://ns.adobe.com/Variables/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_imrep"
ocidDTDNode's setStringValue:"http://ns.adobe.com/ImageReplacement/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_custom"
ocidDTDNode's setStringValue:"http://ns.adobe.com/GenericCustomNamespace/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_flows"
ocidDTDNode's setStringValue:"http://ns.adobe.com/Flows/1.0/"
ocidDTD's addChild:ocidDTDNode

################
set ocidDTDNode to refMe's NSXMLDTDNode's alloc()'s initWithKind:(refMe's NSXMLAttributeIDRefsKind) options:(refMe's NSXMLNodeLoadExternalEntitiesAlways)
ocidDTDNode's setName:"ns_extend"
ocidDTDNode's setStringValue:"http://ns.adobe.com/Extensibility/1.0/"
ocidDTD's addChild:ocidDTDNode


#################################
########### Root element
#################################
set ocidRootElement to refMe's NSXMLElement's alloc()'s initWithName:"svg"
#################################
########### variableSets element
#################################
set ocidVariableSets to refMe's NSXMLElement's alloc()'s initWithName:"variableSets"
set ocidNameSpaceNode to refMe's NSXMLNode's namespaceWithName:"" stringValue:"&ns_vars;"
ocidVariableSets's addNamespace:ocidNameSpaceNode
ocidRootElement's addChild:ocidVariableSets

#################################
########### variableSet element
#################################
set ocidVariableSet to refMe's NSXMLElement's alloc()'s initWithName:"variableSet"
set ocidVariableSetNode to refMe's NSXMLNode's attributeWithName:"varSetName" stringValue:"データセット名"
ocidVariableSet's addAttribute:ocidVariableSetNode
set ocidVariableSetNode to refMe's NSXMLNode's attributeWithName:"locked" stringValue:"none"
ocidVariableSet's addAttribute:ocidVariableSetNode
ocidVariableSets's addChild:ocidVariableSet
#################################
########### variables element
#################################
set ocidVariables to refMe's NSXMLElement's alloc()'s initWithName:"variables"
ocidVariableSet's addChild:ocidVariables
#################################
########### variable element
#################################
set ocidVariable to refMe's NSXMLElement's alloc()'s initWithName:"variable"
set ocidVariableNode to refMe's NSXMLNode's attributeWithName:"varName" stringValue:"可変:名前"
ocidVariable's addAttribute:ocidVariableNode
set ocidVariableNode to refMe's NSXMLNode's attributeWithName:"trait" stringValue:"textcontent"
ocidVariable's addAttribute:ocidVariableNode
set ocidVariableNode to refMe's NSXMLNode's attributeWithName:"category" stringValue:"http://ns.adobe.com/Flows/1.0/"
ocidVariable's addAttribute:ocidVariableNode
ocidVariables's addChild:ocidVariable

#################################
########### sampleDataSets element
#################################
set ocidSampleDataSets to refMe's NSXMLElement's alloc()'s initWithName:"v:sampleDataSets"
set ocidNameSpaceNode to refMe's NSXMLNode's namespaceWithName:"" stringValue:"http://ns.adobe.com/GenericCustomNamespace/1.0/"
ocidSampleDataSets's addNamespace:ocidNameSpaceNode
set ocidNameSpaceNode to refMe's NSXMLNode's namespaceWithName:"v" stringValue:"http://ns.adobe.com/Variables/1.0/"
ocidSampleDataSets's addNamespace:ocidNameSpaceNode
ocidVariableSet's addChild:ocidSampleDataSets

#################################
########### sampleDataSet element
#################################
set ocidSampleDataSet to refMe's NSXMLElement's alloc()'s initWithName:"v:sampleDataSet"
set ocidSampleDataSetNode to refMe's NSXMLNode's attributeWithName:"dataSetName" stringValue:"可変:セット1"
ocidSampleDataSet's addAttribute:ocidSampleDataSetNode
ocidSampleDataSets's addChild:ocidSampleDataSet

#################################
########### 可変データセット1
#################################
set ocidSampleDataSetItem to refMe's NSXMLElement's alloc()'s initWithName:"可変:名前"
ocidSampleDataSet's addChild:ocidSampleDataSetItem

#################################
########### 可変データセット1 の項目1
#################################
set ocidSampleDataSetItemP to refMe's NSXMLElement's alloc()'s initWithName:"p"
ocidSampleDataSetItem's addChild:ocidSampleDataSetItemP
ocidSampleDataSetItemP's setStringValue:"名前データ"

#################################
###NSXMLDocument を生成する
#################################
set ocidOutPutXML to refMe's NSXMLDocument's alloc()'s initWithRootElement:ocidRootElement
ocidOutPutXML's setVersion:"1.0"
ocidOutPutXML's setCharacterEncoding:"UTF-8"
#####DTDを追加
ocidOutPutXML's setDTD:ocidDTD

#################################
###改行コード変換
#################################
####テキスト形式に戻して
set ocidXMLstrings to ocidOutPutXML's XMLString()
####改行コードをCRLF WINDOWSにする
###StringValue内に改行があると置き換えちゃうのでこれはNG
##set ocidCRLFstrings to ocidXMLstrings's stringByReplacingOccurrencesOfString:"\n" withString:"\r\n"
###XMLStringには改行が含まれないためWindows改行にするには最後にWINDOW改行を入れれば良い
ocidCRLFstrings's appendString:"\r\n"
########
(* わざわざ正規表現使わなくても
set ocidCRLFstrings to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidCRLFstrings's setString:ocidXMLstrings
set ocidRange to ocidXMLstrings's rangeOfString:ocidCRLFstrings
ocidCRLFstrings's replaceOccurrencesOfString:"(>)\n" withString:"$1\r\n" options:(refMe's NSRegularExpressionSearch) range:ocidRange
ocidCRLFstrings's replaceOccurrencesOfString:"(>)$" withString:"$1\r\n" options:(refMe's NSRegularExpressionSearch) range:ocidRange
ocidCRLFstrings's replaceOccurrencesOfString:"\n$" withString:"$1\r\n" options:(refMe's NSRegularExpressionSearch) range:ocidRange
*)
####################
####保存
####################
####ファイルパス
set strSaveFilePath to "~/Desktop/AiVariables.xml" as text
set ocidSaveFilePathStr to refMe's NSString's stringWithString:strSaveFilePath
set ocidSaveFilePath to ocidSaveFilePathStr's stringByStandardizingPath()
set ocidSaveFilePathURL to refMe's NSURL's fileURLWithPath:ocidSaveFilePath

####################
#####UTF8でテキストデータにして
set ocidCFLFdata to ocidCRLFstrings's dataUsingEncoding:(refMe's NSUTF8StringEncoding)
###NSDATAとして保存
set listResults to ocidCFLFdata's writeToURL:ocidSaveFilePathURL options:(refMe's NSDataWritingAtomic) |error|:(reference)

|

[Illustrator]配置画像をファイル名のレイヤを作成してそこに移動する

#!/usr/bin/env osascript

----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

#

# 配置画像を個別のレイヤーに移動します

#レイヤ名にリンク画像は Link: 

#埋め込み画像は 埋込:を付与してレイヤを作成する+版

# com.cocolog-nifty.quicktimer.icefloe

----+----1----+----2----+-----3----+----4----+----5----+----6----+----7


use AppleScript version "2.4"

use framework "Foundation"

use scripting additions


property refMe : a reference to current application

property refNSString : a reference to refMe's NSString



tell application "Adobe Illustrator"

activate

tell the current document

########レイヤーの数を数える

set numLayerNo to (do javascript "app.activeDocument.layers.length;") as text

set numCnt to 0 as number

repeat numLayerNo times

##レイヤーの名前の取得部

do javascript "app.activeDocument.activeLayer= app.activeDocument.layers[" & numCnt & "];"

do javascript "app.activeDocument.activeLayer.name;"

set numCnt to numCnt + 1 as number

end repeat

end tell

end tell

tell application "Adobe Illustrator"

activate

tell the current document

########埋め込みラスタ画像の数を数える

do javascript "app.activeDocument.selection;"

set numSelectionCnt to (do javascript "app.activeDocument.rasterItems.length;") as text

end tell

end tell

set numCnt to 0 as number

repeat numSelectionCnt times

##

tell application "Adobe Illustrator"

activate

tell the current document

########埋め込みラスタ画像の名前を取得する

set strFileNamet to (do javascript "app.activeDocument.rasterItems[" & numCnt & "].file.name;") as text

end tell

end tell

###文字化けファイル名を読める形にする

set strFileNamet to ("埋込:" & decodeURL(strFileNamet)) as text

tell application "Adobe Illustrator"

activate

tell the current document

########ファイル名でレイヤー名を作成

do javascript "var objRastFile=app.activeDocument.rasterItems[" & numCnt & "];"

do javascript "var objNewLayer=app.activeDocument.layers.add();"

do javascript "objNewLayer.name=\"" & strFileNamet & "\""

##レイヤに移動する

do javascript "objRastFile.move(objNewLayer, ElementPlacement.PLACEATBEGINNING);"

end tell

end tell

set numCnt to numCnt + 1 as number

end repeat




tell application "Adobe Illustrator"

activate

tell the current document

########リンク画像の数を数える

set numSelectionCnt to (do javascript "app.activeDocument.placedItems.length;") as text

end tell

end tell

set numCnt to 0 as number

repeat numSelectionCnt times

##

tell application "Adobe Illustrator"

tell the current document

########リンク画像のファイル名を取得する

set strFileNamet to (do javascript "app.activeDocument.placedItems[" & numCnt & "].file.name;") as text

end tell

end tell

###文字化けファイル名を読める形にする

set strFileNamet to ("Link:" & decodeURL(strFileNamet)) as text

tell application "Adobe Illustrator"

activate

tell the current document

########ファイル名でレイヤー名を作成

do javascript "var objPlacedFile=app.activeDocument.placedItems[" & numCnt & "];"

do javascript "var objNewLayer=app.activeDocument.layers.add();"

do javascript "objNewLayer.name=\"" & strFileNamet & "\""

##レイヤに移動する

do javascript "objPlacedFile.move(objNewLayer, ElementPlacement.PLACEATBEGINNING);"

end tell

end tell


set numCnt to numCnt + 1 as number

end repeat


####%エンコードされたファイル名をデコードするサブルーチン

on decodeURL(theText)

set ocidStringText to refNSString's stringWithString: theText

set ocidEncodedText to ocidStringText's stringByRemovingPercentEncoding()

set strEncodedText to ocidEncodedText as text

return strEncodedText

end decodeURL

|

[Illustrator]アートボードサイズの長方形を描く

アートボードサイズの長方形を描く
https://3fl.jp/is041/
こちらのアップルスクリプト版

ダウンロード - draw_rectangle_by_artboard_siz.zip

#!/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 scripting additions




####イラストレータでの処理はここから
tell application "Adobe Illustrator"
###全面の処理するファイルを定義
try
set activDoc to current document
on error
return "ドキュメントがありません"
error number -128
end try
tell activDoc
####カラースペース
set strColorSpace to (color space) as text
###
set listCropMarks to crop marks as list
set numWidth to width as number
set numHeight to height as number
set numXa to item 1 of listCropMarks as number
set numYa to item 2 of listCropMarks as number
set numXb to item 3 of listCropMarks as number
set numYb to item 4 of listCropMarks as number
###最上部にレイヤ追加(前面= front)
##make layer at front with properties {name:strLayerName}
set strLayerName to ("Background") as text
###最下部にレイヤ追加
make layer at end with properties {name:strLayerName}
####作ったレイヤ
tell layer strLayerName
###レイヤ追加
set strBkLayerName to ("BasePath")
make layer at end with properties {name:strBkLayerName}
###
tell layer strBkLayerName
set strBackgroundPathName to ("BackgroundPath")

if strColorSpace is "CMYK" then
## fill color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:0.0}, fill overprint:false,
make new path item with properties {closed:true, guides:false, filled:false, stroked:false, clipping:false, evenodd:false, resolution:720.0, entire path:{{class:path point info, anchor:{numXb, numYb}, left direction:{numXb, numYb}, right direction:{numXb, numYb}, point type:corner}, {class:path point info, anchor:{numXa, numYb}, left direction:{numXa, numYb}, right direction:{numXa, numYb}, point type:corner}, {class:path point info, anchor:{numXa, numYa}, left direction:{numXa, numYa}, right direction:{numXa, numYa}, point type:corner}, {class:path point info, anchor:{numXb, numYa}, left direction:{numXb, numYa}, right direction:{numXb, numYa}, point type:corner}}, polarity:positive, URL:"", note:"", locked:false, hidden:false, selected:true, position:{numXa, numYa}, width:numWidth, height:numHeight, geometric bounds:listCropMarks, name:strBackgroundPathName, blend mode:normal, opacity:100.0, isolated:false, knockout:disabled, editable:true, sliced:false, pixel aligned:false, wrapped:false}
else
### fill color:{class:RGB color info, red:255.0, green:255.0, blue:255.0}, fill overprint:false,
make new path item with properties {closed:true, guides:false, filled:false, stroked:false, clipping:false, evenodd:false, resolution:720.0, entire path:{{class:path point info, anchor:{numXb, numYb}, left direction:{numXb, numYb}, right direction:{numXb, numYb}, point type:corner}, {class:path point info, anchor:{numXa, numYb}, left direction:{numXa, numYb}, right direction:{numXa, numYb}, point type:corner}, {class:path point info, anchor:{numXa, numYa}, left direction:{numXa, numYa}, right direction:{numXa, numYa}, point type:corner}, {class:path point info, anchor:{numXb, numYa}, left direction:{numXb, numYa}, right direction:{numXb, numYa}, point type:corner}}, polarity:positive, URL:"", note:"", locked:false, hidden:false, selected:true, position:{numXa, numYa}, width:numWidth, height:numHeight, geometric bounds:listCropMarks, name:strBackgroundPathName, blend mode:normal, opacity:100.0, isolated:false, knockout:disabled, editable:true, sliced:false, pixel aligned:false, wrapped:false}
end if
set locked to true
end tell
set locked to true
end tell
end tell
end tell

|

[Illustrator]文字の置き換え

#!/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 scripting additions


###アプリケーション
tell application "Adobe Illustrator"
###前面のドキュメントを定義
set activDoc to current document
###値をリストに格納するための初期化
set listSelectFrame to {} as list
###全面のドキュメントに対してのみ処理
tell activDoc
###選択中のテキストをリストに
set listSelectFrame to every text frame whose selected is true
###選んだテキストフレームの数を数えておく
set numCntEveryFrame to count of listSelectFrame
-->テキストフレームを指定しているのでここで他の要素は除外されている
###全部対象の場合はこちら
##set listSelectFrame to every text frame
###繰り返しの初期化
set numSelectFrameNo to 0
###選択したテキストフレームの繰り返し
#####この方法だと最後の1つを誤認識する
repeat with objSelectFrame in listSelectFrame
###カウントアップ
set numSelectFrameNo to numSelectFrameNo + 1
###種類を調べて
set classKind to kind of objSelectFrame
###
tell objSelectFrame
set strContents to contents as text
end tell
#####半角スペースを
set AppleScript's text item delimiters to " "
set listContents to every text item of strContents
#####改行に置き換え
set AppleScript's text item delimiters to "\n"
set strContents to (listContents) as text
tell objSelectFrame
set contents to strContents as text
end tell
set AppleScript's text item delimiters to ""
###お約束の再描画
redraw
end repeat

end tell
###お約束の再描画
redraw
end tell

|

[Illustrator]アイテムに名前をつける(連番)

[Illustrator]アイテムに名前をつける(レイヤ毎)
https://quicktimer.cocolog-nifty.com/icefloe/2022/04/post-285072.htmlこちらの
『連番』命名版↑こちらのはレイヤ毎連番

ダウンロード - e382aae38395e38299e382b7e38299e382a7e382afe38388e5908de4bb98e4b88ee980a3e795aa.scpt.zip




#!/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 scripting additions

####################################
####ドキュメントのカラースペース
tell application "Adobe Illustrator"
tell the current document
set strColorSpace to color space
end tell
end tell
####################################
####パスアイテムに名称を付与する
tell application "Adobe Illustrator"
###ドキュメントの名前
name of every document
###ドキュメントの場所
file path of every document
###全面の処理するファイルを定義
set activDoc to current document
##############################パスアイテム
tell activDoc
###レイヤをリストにして
set listLayer to every layer
###各レイヤ毎に処理
repeat with objLayer in listLayer
tell objLayer
set numLayerID to index as number
if numLayerID < 10 then
set numLayerID to ("00" & numLayerID) as text
set numLayerID to text -2 through -1 of numLayerID as text
end if
######レイヤ名は上下関係によってindexは随時変わります
######そのためレイヤ名の命名は最後がよろしいです
###set name to "Layer" & numLayerID & ""
end tell
end repeat
end tell
##############################
tell activDoc
set listEveryPageItem to every page item as list

set numCntEveryPageItem to (count of listEveryPageItem) as number
set numIndex to 0 as number
repeat with objPageItem in listEveryPageItem
set numIndex to numIndex + 1 as number
set objClass to class of objPageItem

if objClass is text frame then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("TextFrame" & numIndex) as text
end tell
else if objClass is path item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("PathItem" & numIndex) as text
end tell
else if objClass is placed item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("PlacedItem" & numIndex) as text
end tell
else if objClass is raster item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("RasterItem" & numIndex) as text
end tell
else if objClass is plugin item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("PluginItem" & numIndex) as text
end tell
else if objClass is mesh item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("MeshItem" & numIndex) as text
end tell
else if objClass is compound path item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("CompoundItem" & numIndex) as text
end tell
else if objClass is embedded item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("EmbeddedItem" & numIndex) as text
end tell
else if objClass is graph item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("GraphItem" & numIndex) as text
end tell
else if objClass is grid repeat item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("GridRepeatItem" & numIndex) as text
end tell
else if objClass is group item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("GroupItem" & numIndex) as text
end tell
else if objClass is legacy text item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("LegacyTextItem" & numIndex) as text
end tell
else if objClass is non native item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("NonNativeItem" & numIndex) as text
end tell
else if objClass is radial repeat item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("RadialRepeatItem" & numIndex) as text
end tell
else if objClass is symbol item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("SymbolItem" & numIndex) as text
end tell
else if objClass is symmetry repeat item then
tell objPageItem
##set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("SymmetryRepeatItem" & numIndex) as text
end tell

end if

log listEveryPageItem

end repeat
end tell
end tell

|

[Illustrator]アイテムに名前をつける(レイヤ毎)

レイヤ番号(index)は上下関係に依存して、変更されますが
他のアイテムはレイヤ毎番号になります。
_20220425_20_21_25_20220425_20_21_37

[Illustrator]アイテムに名前をつける(連番)もあります
https://quicktimer.cocolog-nifty.com/icefloe/2022/04/post-aee426.html
↑こちらは全てのページアイテムで連番となります。


ダウンロード - e382aae38395e38299e382b7e38299e382a7e382afe38388e5908de38292e4bb98e4b88ee38199e3828b.scpt.zip





#!/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 scripting additions

####################################
####ドキュメントのカラースペース
tell application "Adobe Illustrator"
tell the current document
set strColorSpace to color space
end tell
end tell
####################################
####パスアイテムに名称を付与する
tell application "Adobe Illustrator"
###ドキュメントの名前
name of every document
###ドキュメントの場所
file path of every document
###全面の処理するファイルを定義
set activDoc to current document
##############################パスアイテム
tell activDoc
###レイヤをリストにして
set listLayer to every layer
###各レイヤ毎に処理
repeat with objLayer in listLayer
tell objLayer
set numLayerID to index as number
if numLayerID < 10 then
set numLayerID to ("00" & numLayerID) as text
set numLayerID to text -2 through -1 of numLayerID as text
end if
######レイヤ名は上下関係によってindexは随時変わります
######そのためレイヤ名の命名は最後がよろしいです
###set name to "Layer" & numLayerID & ""
end tell
end repeat
end tell
##############################
tell activDoc
set listEveryPageItem to every page item as list
repeat with objPageItem in listEveryPageItem

set objClass to class of objPageItem

if objClass is text frame then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("TextFrame" & numIndex) as text
end tell
else if objClass is path item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("PathItem" & numIndex) as text
end tell
else if objClass is placed item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("PlacedItem" & numIndex) as text
end tell
else if objClass is raster item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("RasterItem" & numIndex) as text
end tell
else if objClass is plugin item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("PluginItem" & numIndex) as text
end tell
else if objClass is mesh item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("MeshItem" & numIndex) as text
end tell
else if objClass is compound path item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("CompoundItem" & numIndex) as text
end tell
else if objClass is embedded item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("EmbeddedItem" & numIndex) as text
end tell
else if objClass is graph item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("GraphItem" & numIndex) as text
end tell
else if objClass is grid repeat item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("GridRepeatItem" & numIndex) as text
end tell
else if objClass is group item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("GroupItem" & numIndex) as text
end tell
else if objClass is legacy text item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("LegacyTextItem" & numIndex) as text
end tell
else if objClass is non native item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("NonNativeItem" & numIndex) as text
end tell
else if objClass is radial repeat item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("RadialRepeatItem" & numIndex) as text
end tell
else if objClass is symbol item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("SymbolItem" & numIndex) as text
end tell
else if objClass is symmetry repeat item then
tell objPageItem
set numIndex to index as number
if numIndex < 10 then
set numIndex to ("00" & numIndex) as text
set numIndex to text -2 through -1 of numIndex as text
end if
set name to ("SymmetryRepeatItem" & numIndex) as text
end tell

end if

log listEveryPageItem

end repeat
end tell
end tell

|

[AppleScript]テキストのフォント名を付与する(ファミリ名+スタイル)

[AppleScript]テキストのフォント名を付与するの改良版
実際に付与するテキストの内容を『ファミリー名』+『スタイル名』にした

ダウンロード - e38395e382a9e383b3e38388e5908de4bb98e4b88er2.scpt.zip


#!/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 scripting additions


####################################
####
tell application "Adobe Illustrator"
###全面の処理するファイルを定義
set activDoc to current document
##############################
###各値をリストに格納するための初期化
set listTextFramePos to {} as list
set listOrgWidth to {} as list
set listOrgFontName to {} as list
set listOrgFontFamilyName to {} as list
set listOrgFontStyleName to {} as list
set listOrgFontSize to {} as list
###全面のドキュメント
tell activDoc
###選択中のテキストをリストに
set listSelectFrame to every text frame whose selected is true
###繰り返しの初期化
set numFontNameFrameNo to 1
####選択中のテキスト分繰り返す
repeat with objSelectFrame in listSelectFrame
tell item numFontNameFrameNo of listSelectFrame
##場所
set objOrgPos to position
copy objOrgPos to the end of listTextFramePos
##
set numOrgWidth to width
copy numOrgWidth to the end of listOrgWidth
get character 1
##フォント名
set strOrgFontName to name of text font of character 1 as text
copy strOrgFontName to the end of listOrgFontName
##ファミリ名
set strOrgFontFamilyName to family of text font of character 1 as text
copy strOrgFontFamilyName to the end of listOrgFontFamilyName
##スタイル
set strOrgFontStyleName to style of text font of character 1 as text
copy strOrgFontStyleName to the end of listOrgFontStyleName
##サイズ
set numOrgFontSize to size of character 1 as integer
copy numOrgFontSize to the end of listOrgFontSize
end tell
set numFontNameFrameNo to numFontNameFrameNo + 1
end repeat
#####↑でリストになった各種値で
#####↓テキストを新規作成します
set numFontNameFrameNo to 1
repeat with objSelectFrame in listSelectFrame
###ポジション取得
set objOrgPos to item numFontNameFrameNo of listTextFramePos
###幅取得
set numOrgWidth to item numFontNameFrameNo of listOrgWidth
###フォント名取得
set strOrgFontName to item numFontNameFrameNo of listOrgFontName
###ファミリ名
set strOrgFontFamilyName to item numFontNameFrameNo of listOrgFontFamilyName
###スタイル
set strOrgFontStyleName to item numFontNameFrameNo of listOrgFontStyleName
####フォントサイズ取得
set numOrgFontSize to item numFontNameFrameNo of listOrgFontSize
###ポジションをXYにバラす
set numOrgPosX to item 1 of objOrgPos as number
set numOrgPosy to item 2 of objOrgPos as number
set numDistPosX to numOrgPosX as number
###新規テキスト用にフォントサイズ分上部に新規ポジションにする
set numDistPosy to numOrgPosy + numOrgFontSize as number
###テキストフレームの名前を作っておく
set strFontNameFrame to ("FontName" & strOrgFontName & "") as text
###追加する文字列=フォントファミリー名+スタイル
##PostScript名の場合はこちらを
##set strIndexFontName to ("" & strOrgFontName & "") as text
set strIndexFontName to ("" & strOrgFontFamilyName & " " & strOrgFontStyleName & "") as text
###テキストを作成する
set objFontName to make new text frame with properties {kind:point text, name:strFontNameFrame, contents:strIndexFontName, position:{numDistPosX, numDistPosy}}
###出来上がったテキストについて
tell objFontName
####フォントサイズは元のサイズの半分
set numFontNameFontSize to numOrgFontSize / 2 as integer
###文字数数えて
set numCntChr to count of character
set numCheChrNo to 1
###全ての文字のサイズを変更する
repeat numCntChr times
set size of character numCheChrNo to numFontNameFontSize
set numCheChrNo to numCheChrNo + 1
end repeat
end tell
set numFontNameFrameNo to numFontNameFrameNo + 1
end repeat
###お約束の再描画
redraw
end tell
end tell

|

その他のカテゴリー

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