見出し画像

【DTP作業効率化】テキストがアウトライン化されていた時の苛立ちを軽減するapple script

誰かが作ったデータや過去のデータからテキストを持ってこようとした時、アウトラインがかかっていることがある。イライライラっとする。

「PDF互換」のaiファイルを作ってAcrobatで開いてOCRを実行してテキストにすればいいのだけど、この手間がめんどくさい。もう一回、イライライラっとする。スクリーンショットをとって、それをAcrobatで開くでもいいけれど。。。

何かいい方法はないものかと思うけれど分からないので、せめて
・「PDF互換」のaiファイルを作る
・Acrobatで開く
はPCがやってくれればと思った。

下記のスクリプトはイラレで選択したものを新規ファイルにコピペして「PDF互換」でデスクトップに保存してAcrobatで開くところまでしてくれます。あとはAcrobatで「⌘A」とすれば運がよければテキストが取り戻せます。白いテキストは黒にしてから実行します。

イラレで選択してスクリプト実行


Acrobatで開いてくれる


自分以外にこれを必要とする人がいるのだろうか。。。
スクリプトとアプリケーションファイル

set as_of_now to my as_of_the_time()

tell application "Finder"
	set my_desktop to path to desktop as string
end tell

tell application "Adobe Illustrator"
	tell document 1
		set selec to selection
		copy selec
	end tell
	set new_doc to make a new document
	tell new_doc
		paste
		set the_doc to save in my_desktop as Illustrator with options {PDF compatible:true, embed linked files:false, embed ICC profile:false, compressed:true}
		set the_document_name to name of the_doc
		close
	end tell
end tell
tell application "Finder"
	set the_ai to my_desktop & the_document_name as string as alias
	set new_name to "ocr用__" & as_of_now & ".ai"
	set name of the_ai to new_name
	set new_file to my_desktop & new_name as string as alias
	set new_file to POSIX path of new_file
end tell
tell application "Adobe Acrobat"
	open new_file
	activate
end tell


------------------------
to as_of_the_time()
	set {month:m, day:d} to (current date)
	set m to m as integer
	set the_moment to time string of (current date)
	set the_moment to my divide_text(the_moment, ":")
	set the_hour to item 1 of the_moment
	set the_minute to item 2 of the_moment
	set the_second to item 3 of the_moment
	set as_of to m & "月" & d & "日" & the_hour & "時" & the_minute & "分" & the_second & "秒" as string
	return as_of
end as_of_the_time

to divide_text(the_text, the_delimiter)
	tell application "Finder"
		set the_original_delimiters to AppleScript's text item delimiters
		set AppleScript's text item delimiters to the_delimiter
		set these_items to text items of the_text
		set AppleScript's text item delimiters to the_original_delimiters
		return these_items
	end tell
end divide_text

この記事が気に入ったらサポートをしてみませんか?