2 Replies Latest reply on Jan 11, 2014 2:52 PM by LyndsayHowarth

    Would like some Applescript help?


      Given a specifc folder path in a FM text field, I need to search the folder for any file with the extension ".log" and



      1 Repalce any single quote in the file's contents with a double quote


      2 Change the file's extension to ".csv"



      Any guidance will be much appreciated!



      I have to import these files as if they were csv files but FM does not like to do that when th extension is .log, and also it treats single quotes as a data character


      The data does not contain any double quotes initally, otherwise I guess I could first subtstiute double double quotes for those.

        • 1. Re: Would like some Applescript help?

          Hello Oliver,



          If you are comfortable using a little bit of shell scripting:


          When it comes to the task of replacing the single quote chars in a target file, one avenue that you might consider would be the use of the command line utility:  tr


          The tr utility will allow you to perform a simple character replacement in a file, and output the result to another file.


          This will not help you with the task of scanning the directory and identifying which files you wish to process, but it will help with the actual processing of each file, i.e. with the task of replacing single quote chars with double quote chars.


          Very best,







          As an example, a simplified AppleScript which operates on a single file might look like this:



          set varPath to "/Users/MyOSXUserName/Desktop"


          processFileSwapQuotes(varPath, varPath, "MyTargetFile")



          on processFileSwapQuotes(varInputFolder, varOutputFolder, varFileNameSansExtension)


                    set varTargetPath to varInputFolder & "/" & varFileNameSansExtension & ".log"


                    set varOutputPath to varOutputFolder & "/" & varFileNameSansExtension & ".csv"


                    set varShellScript to "cat " & varTargetPath & " | tr \\' \\\" > " & varOutputPath


            do shell script varShellScript


          end processFileSwapQuotes










          • 2. Re: Would like some Applescript help?

            You could do it with PHP in a web browser....

            (I would get stuck where you are with the AppleScript I think)


            Sent from my iPad

            Lyndsay Howarth

            11th Hour Group Pty Ltd