fed Posted October 27, 2009 Posted October 27, 2009 Is it possible to use "Export Field Contents" to export as utf-8 rather than utf-16?
Vaughan Posted October 27, 2009 Posted October 27, 2009 No, I don't think so. A solution might be to put the field text into a global field and normal-export a singe record with the global field.
Søren Dyhr Posted October 27, 2009 Posted October 27, 2009 You could try this: http://macscripter.net/viewtopic.php?id=28482 --sd
fed Posted October 28, 2009 Author Posted October 28, 2009 Thanks for the suggestion. I tried it. It looks much better, only the line feeds seem to be hex 0B, rather than the required hex 0A Any idea how to fix this problem?
Fenton Posted October 29, 2009 Posted October 29, 2009 Here is a brute force vanilla AppleScript which writes a UTF-8 file, with Mac carriage returns: set the_text to cell "Text_" of current record set my_path to (path to desktop folder from user domain) as text set the_file to (my_path & "test.txt") tell application "Finder" try close access file the_file end try set my_file to (open for access file the_file with write permission) set eof my_file to 0 set the_text to my replace_chars(the_text, ASCII character 11, ASCII character 13) write ((ASCII character 239) & (ASCII character 187) & (ASCII character 191)) to my_file --> not as «class utf8» write the_text to my_file as «class utf8» close access my_file end tell on replace_chars(this_text, search_string, replacement_string) set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as text set AppleScript's text item delimiters to "" return this_text end replace_chars
Søren Dyhr Posted October 29, 2009 Posted October 29, 2009 I have thought about it, but havn't got any snippet doing the requrired particular task, so it would have taken somewhat an hour tinkering... --sd
fed Posted November 2, 2009 Author Posted November 2, 2009 Thank you for the code. I do not know how to use applescript, actually. Is this code for using within FMP, or after the export is done? Fed
fed Posted November 2, 2009 Author Posted November 2, 2009 Is there a way of automatically putting something into the clipboard in FMP?
bcooney Posted November 2, 2009 Posted November 2, 2009 Copy? That can't be it. What are you trying to achieve?
Søren Dyhr Posted November 2, 2009 Posted November 2, 2009 He changes the file after the export! --sd
Fenton Posted November 2, 2009 Posted November 2, 2009 (edited) No, if you mean my AppleScript, it does not change the file after export,* it explicitly writes the file as UTF-8, first adding the 2 invisible characters that identify it as UTF-8. The "find/replace" subroutine is converting the internal FileMaker "returns" (ASCII 11) to regular Mac returns. AppleScript itself is "line ending agnostic" (so it would keep the ASCII 11 unless you change them). You run AppleScript like this by putting it in a Perform AppleScript FileMaker script step. The AppleScript hard-codes the field (cell) name as "Text_", and puts a file named "test.txt" on your Desktop. But these things can be changed. FileMaker runs AppleScript very well (with a few quirks (like the fact that I had to enclose the "write" command within a Finder tell block). But FileMaker no longer includes much documentation (the Help page is so old it's funny, "AppleWorks 6"?). Some of the documentation (without the examples) is here: http://fmdl.filemaker.com/MISC/fmp10/fp/apple_events_reference_wwe.zip *Well, it writes to the file twice, once for the 2 invisible characters, again for the real text. So I guess you could say it changes it after "export". But the writes are almost simultaneous. The word "export" does not really apply, as there is no such command in AppleScript itself, so it's hard to say. Edited November 2, 2009 by Guest export
fed Posted November 2, 2009 Author Posted November 2, 2009 So you can paste to another program outside FMP.
bcooney Posted November 3, 2009 Posted November 3, 2009 Paste what? A single field's content? FM supports the clipboard, and as Lee mentioned, you can export data in many formats. If you provide more details, so will we. :(
fed Posted November 3, 2009 Author Posted November 3, 2009 I've tried exporting (see http://fmforums.com/forum/showtopic.php?tid/211846/fromactivity/myposts/), but it doesn't seem to work for what I need. I need utf-8 format with hex 0A as linefeeds, and I cannot seem to get it by exporting. If I copy, then paste into BBedit, I can save the file just the way I need it.
fed Posted November 3, 2009 Author Posted November 3, 2009 (edited) I cannot seem to get it to work. Does the field have to have a special name? I get the error: "Object not found." followed by "Unknown Error: -1728." Thanks again, Fed Edited November 3, 2009 by Guest
fed Posted November 3, 2009 Author Posted November 3, 2009 I changed "Text_" to the name of the field I want to export, and it worked! The problem, is that the linefeeds are still hex 0D, and I need them to be 0A. How can I achieve this. Also, The first three bytes (EF BB BF) should be excluded. Thanks again, Fed
Lee Smith Posted November 3, 2009 Posted November 3, 2009 Do not double post your questions. If you need to try a different approach, just make it part of the original request. No wonder Barbara and I couldn't figure out what you were trying to do. I have merged your two topics. Lee
fed Posted November 3, 2009 Author Posted November 3, 2009 I didn't double post. I would like to keep the two topics separate, at least until I get the answer I need for this topic. It is VERY important to me. I am making a billing program, and the final part (exporting to a file in the required format for use on a mainframe) is where I am stuck. I am almost there, thanks to Søren Dyhr for all his help. Please do not merge the two topics until I have my export working properly. I really need it to work. The other question was about putting information into the clipboard in FMP for use outside FMP. It is for a quite different use.
Søren Dyhr Posted November 3, 2009 Posted November 3, 2009 While Fenton should take the credit here and not me! Would I like to lead your attention to this: http://www.macosxhints.com/article.php?story=20081231012753422 ...and in particular to this snippet: set theFileReference to open for access fileToCopy set theFileContents to read theFileReference as «class utf8» close access theFileReference set the clipboard to theFileContents Which is the oppsite way to handle filemakers eksport ... --sd
fed Posted November 3, 2009 Author Posted November 3, 2009 That's great! Thanks again! About the file I need to make, The problem, is that the linefeeds are still hex 0D, and I need them to be 0A. How can I achieve this. Also, The first three bytes (EF BB BF) should be excluded.
Søren Dyhr Posted November 3, 2009 Posted November 3, 2009 (edited) Have you read up upon both pbpaste and sed here?... when it comes to it would they perhaps be better bets than applescript? http://www.cs.hmc.edu/tech_docs/qref/sed.html And the way to use it inside filemaker is brewed over this recipee: http://www.newcenturydata.com/downloads/text_write.zip ...the piping allows several things to happen simultaneously in every branch of the piping, which is much faster than applescript even when it's compiled. --sd Edited November 3, 2009 by Guest
fed Posted November 3, 2009 Author Posted November 3, 2009 Too complicated for me. Thanks anyway. I almost have it!! I changed some things and now have what I want: set the_text to cell "Batch" of current record set my_path to (path to desktop folder from user domain) as text set the_file to (my_path & "test.txt") tell application "Finder" try close access file the_file end try set my_file to (open for access file the_file with write permission) set eof my_file to 0 set the_text to my replace_chars(the_text, ASCII character 13, ASCII character 10) write the_text to my_file as «class utf8» close access my_file end tell on replace_chars(this_text, search_string, replacement_string) set AppleScript's text item delimiters to the search_string set the item_list to every text item of this_text set AppleScript's text item delimiters to the replacement_string set this_text to the item_list as text set AppleScript's text item delimiters to "" return this_text end replace_chars
fed Posted November 3, 2009 Author Posted November 3, 2009 Now I need to be able to change the file name. I tried a 'calculated' applescript rather than 'native' (ie using Perform Applescript) I cannot seem to get it working. I am having problems with the quotation marks. Any suggestions?
fed Posted November 3, 2009 Author Posted November 3, 2009 I think I did it! "set the_text to cell " & Char ( 34 ) & "Batch" & Char ( 34 ) & " of current record" & ¶ & "" & ¶ & "set my_path to (path to desktop folder from user domain) as text" & ¶ & "set the_file to (my_path & " & Char ( 34 ) & $Batch Name & Char ( 34 ) & ")" & ¶ & "" & ¶ & "tell application " & Char ( 34 ) & "Finder" & Char ( 34 ) & ¶ & " try" & ¶ & " close access file the_file" & ¶ & " end try" & ¶ & " set my_file to (open for access file the_file with write permission)" & ¶ & " set eof my_file to 0" & ¶ & " set the_text to my replace_chars(the_text, ASCII character 13, ASCII character 10)" & ¶ & " write the_text to my_file as «class utf8»" & ¶ & " close access my_file" & ¶ & "end tell" & ¶ & "" & ¶ & "on replace_chars(this_text, search_string, replacement_string)" & ¶ & " set AppleScript's text item delimiters to the search_string" & ¶ & " set the item_list to every text item of this_text" & ¶ & " set AppleScript's text item delimiters to the replacement_string" & ¶ & " set this_text to the item_list as text" & ¶ & " set AppleScript's text item delimiters to " & Char ( 34 ) & Char ( 34 ) & ¶ & " return this_text" & ¶ & "end replace_chars " I'm now sending in the file it generated to see if it passes the tech specs.
Fenton Posted November 3, 2009 Posted November 3, 2009 Yes, that calculation produces the AppleScript needed. Just a tip. You can use the FileMaker Quote ("text") function instead of Char (34) & "text" & Char(34). Char(34) is fine, just kind of long (and requires FileMaker 10, for you pre-10 readers). P.S. You can also use """, but that can be awkward.
Newbies Filemaker User Posted February 9, 2016 Newbies Posted February 9, 2016 (edited) Is there any way to do it in windows 7 ( "Export Field Contents" to export as utf-8 rather than utf-16 ) ? Edited February 9, 2016 by Filemaker User
Newbies Filemaker User Posted February 9, 2016 Newbies Posted February 9, 2016 I found this nice article. An In-Depth Look at “Export Field Contents” | FileMakerHacks This allows exporting as UTF-8 in windows
Recommended Posts
This topic is 3208 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now