お仕事とAppleScriptの話。
いまとあるデータブックからのテキスト抜き出しを行っている。
もちろん手でやるのは面倒だし、リスクが高いので、以前作ったAppleScriptを使っている。
本当はコマの部分だけのテキストがほしいのだが、スタイルシートの適用がまちまちなので、結局総当りで抜き出して、オペレーターが原本を見ながら整形する羽目に。
フォーマットを作った人やオペレーションをする人がきちんとスタイルシートを使っていてくれれば、ねぇ(^^;
フォントやQ数で条件分岐してもいいんだけど、よその会社で作ったデータなので、信用できないんだよなぁ。
うっかり間違えてある一行だけ延々抜き出せてなかったりすると、頭からやり直す羽目になってしまうし。
仕事を取ってきた上司Iは「お前ならどうにかして形にするから」と言っていたが、なかなか難しいよね。
まぁ全部AppleScriptでやろうなんて毛頭思っていないから(私にAppleScriptを教えた上司Kは全部AppleScriptでやらないと気がすまない人)、誰か適当な後輩つかまえて、地道にがんばってテキスト整形してもらいましょう♪
私がやらないのかって?
私はそんな不毛な作業はしたくない(笑)
ドロップしたQuarkXressファイル(複数可)の名前のテキストが指定したフォルダにできます。
QX3.3とQX4.1に対応。
Tanaka's osax 2.0.1が必要。
on open a
--保存先フォルダを指定
set savepath to choose folder with prompt "保存先を指定してください"
set savepath to savepath as text
--display dialog savepath
repeat with thisFile in a
tell application "QuarkXPress"
open thisFile use doc prefs yes do auto picture import no
tell application "QuarkXPress"
tell document 1
activate
--ドキュメント名を変数に代入
set doc_name to name as text
--doc_nameの文字数をバイトで数えて27バイトより小さければ
if (MT Byte Length doc_name) < 27 then
--.txtを付け足す
set doc_name to doc_name & ".txt"
else
--doc_nameの文字数(1バイト・2バイト関係なく1文字を1とカウント)をzに代入
set z to count character of doc_name
--doc_nameの1~z-2文字目まで文字を抽出して.txtを足してもう一度代入し直す
set doc_name to *1 to ツ
file (savepath & doc_name) with appending
end if
end tell
end repeat
end tell
end repeat
close
end tell
end tell
end tell
end repeat
activate
display dialog ((count a) as text) & "ファイルを処理しました。" buttons {"OK"} default button 1
end open
*1:text 1 thru (z - 2) of doc_name) & ".txt")
end if
count every page
set ttl_pages to result
repeat with i from 1 to ttl_pages
tell page i
set cnt_boxes to (count every text box)
repeat with j from 1 to cnt_boxes
tell text box j
if previous text box is null then
set page_txt to story 1 as string --of text box j
MT Write File ("★☆抜き出したテキスト☆★" & (ASCII character 13) & page_txt & (ASCII character 13) & (ASCII character 13