9 Replies Latest reply on Nov 9, 2009 9:25 AM by webflys1

    Windows CRLF on FMP10 Apple

    webflys1

      Title

      Windows CRLF on FMP10 Apple

      Post

      I have a web utility I must use and the ONLY format they accept in CRLF - Anyone know of a plug in for FMP or a quick way around this? I already wrote an apple script to scub and rewrite the data BUT, need an internal solution.

        • 1. Re: Windows CRLF on FMP10 Apple
          david_lalonde@d-cogit.ca
             I am fairly certain you are stuck. I did some tests a while back in the days of FileMaker Pro 8 to create an ASCII to number function (and vice-versa) and found that the character for newline was identical to the character for carriage return, once pasted in a FileMaker Pro field.
          • 2. Re: Windows CRLF on FMP10 Apple
            webflys1
               Thanks David - I'll get by on my Apple Script to clean it up I suppose - A little ugly but it works : )
            • 3. Re: Windows CRLF on FMP10 Apple
              david_lalonde@d-cogit.ca
                

              Actually, I use AppleScript a lot and I do not find solutions that make use of AppleScript ugly at all. Thanks to AppleScript, FileMaker Pro was able to be part of some mission critical applications I made for clients that would have been impossible otherwise.

               

              In my opinion, AppleScript is one of the hidden Mac OS gems. 

              • 4. Re: Windows CRLF on FMP10 Apple
                webflys1
                   I am sure what I wrote is NOT what you would write - ha. Mine is a combo of Automater and Apple Script (because of my lack of knowledge) and you can see the mouse dance around the screen and do its little thing - funny. It does work though! (takes 14 seconds where a true script would do it in 1) : ) But since we only run it once a day (to run credit card batches) its okay I guess.
                • 5. Re: Windows CRLF on FMP10 Apple
                  FentonJones
                    

                  This is an AppleScript which converts line endings of the chosen file to Windows (CRLF). The original file can have either Mac (CR) or Unix (LF) line endings to start with. The file will be replaced with the converted text.

                   

                  [Extra tell "Finder" lines needed inside a FileMaker Perform AppleScript step. It does not like "read" or "write".] 

                   

                   

                  (*

                  You can read the paragraphs of the file into a list.

                  AppleScript treats LF, CR and CRLF as paragraph delimiters.

                  Then flatten the list using a specified text item delimiter and write the file back to disk

                  *)

                   

                  tellapplication "Finder"

                  setaFileto (choose file)

                  settxttoparagraphsof (readaFile)

                  endtell

                   

                  set {TID, text item delimiters} to {text item delimiters, (return & (ASCII character 10))} -- CRLF

                  settxttotxtastext

                  set text item delimiters to TID

                   

                  tellapplication "Finder"

                  try

                  set ff to open for access aFile with write permission

                  set eofofffto 0

                  write txt to ff

                  close access ff

                  returntrue

                  onerror

                  try

                  close access file aFile

                  endtry

                  returnfalse

                  endtry

                  endtell

                   

                   

                  [P.S. Normally I would use the Unix command `sed` for this. But since upgrading to Snow Leopard, Unix redirection is adding an extra line feed when writing files. So back to vanilla AppleScript until I can figure out an easy way to fix that.] 

                  • 6. Re: Windows CRLF on FMP10 Apple
                    webflys1
                       Wow! Great - thank you VERY much!!!
                    • 7. Re: Windows CRLF on FMP10 Apple
                      webflys1
                        

                      Fenton - sorry, but when I run:

                       

                      tell application "Finder"
                          set aFile to ("eGateway.csv")
                          set txt to paragraphs of (read aFile)
                      end tell

                      set {TID, text item delimiters} to {text item delimiters, (return & (ASCII character 10))} -- CRLF
                      set txt to txt as text
                      set text item delimiters to TID

                      tell application "Finder"
                          try
                              set ff to open for access aFile with write permission
                              set eof of ff to 0
                              write txt to ff
                              close access ff
                              return true
                          on error
                              try
                                  close access file aFile
                              end try
                              return false
                          end try
                      end tell

                       

                      I get the error:

                       

                      "Finder got a error. Can't make "eGateway.csv" into this file type. What am I missing? I tried opening the file first:

                       

                      tell application "Finder"
                          activate
                          open document file "eGateway.csv" of folder "Desktop" of folder "tedandrzejczyk" of folder "Users" of startup disk
                          select window of desktop
                      end tell
                       

                      A few different ways.













                      • 8. Re: Windows CRLF on FMP10 Apple
                        FentonJones
                          

                        You need a full absolute path to the file, not just its name. AppleScript does not really support relative paths. You also need to use the term "alias" or "file" (or "folder"), as AppleScript also does not support using just the plain text path (unlike Unix).

                         

                        You didn't notice this in my earlier example, because I used the "choose file" command, which automatically returns an alias (which can be thought of as a "reference to the file", much as an "alias file" is a file which references its "original file". 

                         

                        tellapplication "Finder"

                        setaFileto "Macintosh HD:Users:fej:Desktop:eGateway.csv"

                        settxttoparagraphsof (readfileaFile)

                        end tell

                         

                        Notice that the startup drive name and my user name is hard-coded in the above path. To make an AppleScript usable by other people, there are ways to get known locations of any Mac, then combine the result with the rest of your file path.

                         

                        path to startup disk as text

                        path to Desktop as text

                         

                         

                        Or put together the full file path in a field in your database, and read it from there.

                         

                        tell application "FileMaker Pro Advanced"

                        set mac_path to cell "MacPath" of current record

                        end tell

                         

                        Since the full path still needs the startup disk and user name (if the file is in a user's home folder), there are FileMaker functions which can get this.

                        Get (SystemDrive) or Get (DesktopPath)

                        You'd need to strip off the leading "/", and convert the others to ":" in order to use the path in AppleScript

                         

                         

                        [P.S. In the AppleScript above, the "tell FileMaker" and "end tell" lines would be --commented out within FileMaker; it knows who it is. The field "MacPath" would need to be on the layout, to specify it the simple way above.]

                        • 9. Re: Windows CRLF on FMP10 Apple
                          webflys1
                             Works like a charm - thanks again!