14)UTF8をInDesignTag付きテキストに

| コメント(0) | トラックバック(0)

■■■このスクリプトについて■■■
UTF8をInDesignTag付きテキスト用のUTF16に変換します。
AppleScriptドロップレットです。

■■■インストール方法■■■
特にありません。お好きな場所にコピーしてください。

■■■使い方■■■
InDesignTag付きテキストはUTF16-LEのBOM付きでないと読み込めませんが
なかなかうまくファイルが作れなくて困るときがあります。
UTF8のファイルをこのスクリプトにドロップするとUTF16-LEのBOM付き保存しますので
InDesignTag付きテキストとして読み込むことができます。
基本的に文字化け等の問題は無いはずなのですが保障はしません。

上の段がUTF8をそのままInDesignに読み込んだところ。

下の段は変換後に読み込んだところ。

もしドロップしても、全く動かなければスクリプトエディタで開いて
別名保存でアプリケーション保存してください。

on run
	set Drop_File to choose file with prompt "テキストファイルを選択してください" ---テスト用テキストファイルを指定
	my main(Drop_File)
end run

on open Drop_Files
	repeat with Drop_File in Drop_Files --ドロップされたファイルに繰り返し
		my main(Drop_File)
	end repeat
end open

on main(Drop_File)
	--UTF8を読み込む
	set foo to (open for access Drop_File)
	set utf8txt to (read foo for (get eof foo) as «class utf8»)
	close access foo
	
	set utf8txt to my replaceAll(utf8txt, (ASCII character (13)) & (ASCII character (10)), ASCII character (13))
	set utf8txt to my replaceAll(utf8txt, (ASCII character (10)), ASCII character (13))
	set headstr to paragraph 1 of utf8txt
	--display dialog "☆" & headstr & "☆"
	if headstr is not "<UNICODE-MAC>" then
		set headstr to "<UNICODE-MAC>" & (ASCII character (13)) & "<vsn:6>" & (ASCII character (13))
		set utf8txt to headstr & utf8txt
	end if
	--ファイル名変更
	set Fname to Drop_File as string
	set theFile to Fname & "_u16.txt"
	--UTF16保存BOMを負荷
	set fh to open for access file theFile with write permission
	set eof fh to 0
	write (ASCII character 254) to fh
	write (ASCII character 255) to fh
	write utf8txt to fh as Unicode text
	close access fh
end main


on replaceAll(motoStr, FindStr, repStr)
	set OriginalDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {FindStr}
	set motoStr to text items of motoStr
	set AppleScript's text item delimiters to {repStr}
	set motoStr to motoStr as string
	set AppleScript's text item delimiters to OriginalDelimiters
	return motoStr
end replaceAll

ダウンロードはこちら
UTF8toInDtag.zip

indesign41

トラックバック(0)

トラックバックURL: http://www.adg7.com/mt/mt-tb.cgi/619

Comments are nofollow setting

コメントする

エントリー一覧

OpenID対応しています OpenIDについて
Powered by Movable Type 7.902.0
漢字イラストロジック-脳トレ京
FREE ONLINE SUDOKU