6 Replies Latest reply on May 1, 2016 8:09 AM by aouttier

    Applescript: read file

    aouttier

      I want to read a text file and put the contents into a field in Filemaker.

       

      I have a working applescript (script editor):

             set Mail to "Macintosh HD:Users:Amelie:Documents:Heron:DB:BronDocumenten:Mail:MailBwhr11.txt"

             set MailTekst to read posix fileMail as text

       

      But, Filemaker doesn't accept the script (perform applescript). It says: expected a line end but found an identifier and the word file is highlighted (translated from dutch, so there could be some errors in)

       

      What could be wrong?

       

      Thank in advance

        • 1. Re: Applescript: read file
          erolst

          FileMaker expects the code being specified as a text string (or an expression that resolves to a text result).

           

          Try entering this:

           

          List (

          "set Mail to \"Macintosh HD:Users:Amelie:Documents:Heron:DB:BronDocumenten:Mail:MailBwhr11.txt\"" ;

          "set MailTekst to read posix fileMail as text"

          )

           

          Note the escaped quotes – necessary if you are using quotes within a string (that is itself enclosed in quotes).

           

          A bit easier on the eyes:

           

          Let (

            myPath = "Macintosh HD:Users:Amelie:Documents:Heron:DB:BronDocumenten:Mail:MailBwhr11.txt" ;

            List (

              "set Mail to " & Quote ( myPath ) ;

              "set MailTekst to read posix fileMail as text"

            )

          )

          • 2. Re: Applescript: read file
            aouttier

            I'm à little bit confused. I use a native AppleScript. And, I always Just type the code as I type it in Scripteditor. In fact, I test the code in ScriptEditor and when iT works, I copy iT in FileMaker.

            • 3. Re: Applescript: read file
              erolst

              aouttier wrote:

              I use a native AppleScript.

               

              Sorry, I thought you were using "Calculated AppleScript". Keep my advice in mind for the next time you use that option …  

               

              On closer inspection, there's a typo in your code; it should (probably) read

               

              set Mail to "Macintosh HD:Users:Amelie:Documents:Heron:DB:BronDocumenten:Mail:MailBwhr11.txt"

              set MailTekst to read posix file Mail as text

               

              i.e. put in a blank.

              • 4. Re: Applescript: read file
                aouttier

                It is still not working. I still got the same error. It seems to be a syntax error, because I get the error when closing the native Applescript and not during running of the script.

                 

                Thank you for your time!

                 

                Schermafbeelding 2016-04-28 om 20.15.19.png

                • 5. Re: Applescript: read file
                  erolst

                  This is a context problem – FileMaker tries to compile your script, but doesn't know these keywords.

                   

                  Try wrapping your statements into a Tell block:

                   

                  tell application "Finder"

                  end tell

                   

                  If you want your dialog to appear in FileMaker, try

                   

                  using terms from application "Finder"

                  end using terms from

                  1 of 1 people found this helpful
                  • 6. Re: Applescript: read file
                    aouttier

                    Putting the statements into a tell block solved my problem. Thanks a lot