FileMakerから出力したファイルにおいてフィールド内改行を改行に変更する(Macintosh) [FileMaker]
FileMakerからCSVなどのテキスト出力をすると、FileMakerのフィールド内改行は改行されない状態で表示される。出力後も改行の状態にするには、ファイルメーカーのフィールド内改行記号 ¶ 垂直タブ Chr(11)をMacの改行記号Chr(13)に変換すればよい。この変換はAppleScriptで行なう。
【必要なフィールド】
(1) ExportFileName テキスト(グローバル格納)
(2) fullpath 計算(結果:テキスト)
Substitute ( Get ( ファイルパス ) ; [ "file:/" ; "" ] ; [ "/" ; ":" ] ; [ Get ( ファイル名 ) & ".fp7" ; ExportFileName ] )
【スクリプト:Export】
・レコードエクスポート[ダイアログなし;「ExportFile.csv」;日本語 (Shift-JIS)]
・AppleScriptを実行
---------------------------
set filepath to cell "VtabReturn::fullpath" of current record
tell application "Finder"
set OpenFile to file ( filepath ) as alias
set aFilePointer to open for access OpenFile
set aData to read aFilePointer
close access aFilePointer
set CurDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "FMPの改行文字*"
set buf to text items of aData
set AppleScript's text item delimiters to return
set buf to buf as string
set WriteFile to file ( filepath ) as alias
set aFilePointer to open for access WriteFile with write permission
set eof of aFilePointer to 0
write buf to aFilePointer
close access aFilePointer
end tell
---------------------------
*"FMPの改行文字"は、はじめに書き出したファイルをテキストエディターで開いて、FMPの改行文字にあたる部分をコピーしてAppleScript内にペーストする。
【サンプルファイル】
サンプルVtabReturnMacのzip圧縮ファイル(12_VtabReturnMac.zip)をアップしておきますのでお試しください。
http://www001.upp.so-net.ne.jp/MedFiles/samples.html
【必要なフィールド】
(1) ExportFileName テキスト(グローバル格納)
(2) fullpath 計算(結果:テキスト)
Substitute ( Get ( ファイルパス ) ; [ "file:/" ; "" ] ; [ "/" ; ":" ] ; [ Get ( ファイル名 ) & ".fp7" ; ExportFileName ] )
【スクリプト:Export】
・レコードエクスポート[ダイアログなし;「ExportFile.csv」;日本語 (Shift-JIS)]
・AppleScriptを実行
---------------------------
set filepath to cell "VtabReturn::fullpath" of current record
tell application "Finder"
set OpenFile to file ( filepath ) as alias
set aFilePointer to open for access OpenFile
set aData to read aFilePointer
close access aFilePointer
set CurDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "FMPの改行文字*"
set buf to text items of aData
set AppleScript's text item delimiters to return
set buf to buf as string
set WriteFile to file ( filepath ) as alias
set aFilePointer to open for access WriteFile with write permission
set eof of aFilePointer to 0
write buf to aFilePointer
close access aFilePointer
end tell
---------------------------
*"FMPの改行文字"は、はじめに書き出したファイルをテキストエディターで開いて、FMPの改行文字にあたる部分をコピーしてAppleScript内にペーストする。
【サンプルファイル】
サンプルVtabReturnMacのzip圧縮ファイル(12_VtabReturnMac.zip)をアップしておきますのでお試しください。
http://www001.upp.so-net.ne.jp/MedFiles/samples.html
3日間もハマっていた問題がこちらの方法で解決できました。
貴重な情報ありがとうございました。
by 神下篤 (2015-07-30 19:33)
〉神下篤さん
お役に立てて良かったです。最近ファイルメーカーのtipsは更新しておりませんが、またネタができたらアップします。ご連絡ありがとうございました。
by kinda (2015-07-31 00:55)