2 Replies Latest reply on Feb 12, 2015 7:52 PM by Danxyz

    Perform AppleScript Issue

    Danxyz

      Title

      Perform AppleScript Issue

      Post

      I have an Applescript that works fine outside of Filemaker but is failing to compile inside Filemaker using the "Perform Applescript" script step.

      The script opens a web page using Safari and copies the contents into the clipboard.  Then that content is written to a text file.  The relevant snippet is:

      Set someText to the clipboard
      Set myFile to open for access (path to documents folder as text) & "foo.text"
      write someText to myFile
      close access myFile

      The compiler is failing at "write someText to myFile".   The error message is "Expected end of line, etc.. but found identifier.

      Any ideas?

       

       

        • 1. Re: Perform AppleScript Issue
          FentonJones

          Oddly, I got an error in AppleScript Editor. But it worked fine if I added the end of the 2nd line, " with write permission"

           

          But it still would not work in FileMaker. It just won't go with the "write" command (as you said). One way to get past this is to use another app to run it, just as "Finder". A better add to use is "System Events", which is kind of made for such situations, as it's always available, and it doesn't show anything else. 

           

          set someText to the clipboard

          tell app "System Events"

          set myFile to open for access ((path to documents folder as text) & "foo.text") with write permission

          write someText to myFile

          close access myFile

          end tell

           

          This will "add to" above whatever text is in that file. However, this only works correctly if the file is empty to start with. As, without being told, it will just start writing, overwriting whatever is there. It seems there are two main options:

          A. Clear the file first, then write the new text

          Or

          B. Put the new text at the top, or add the bottom

           

          I (kind of) know how to do each. But which (if any)?

           

          Oh, a third alternative. Write a new file for each. Or is the "foo.txt" is just what you're showing us (for a shorter post)? That you are writing separate files for each?

          • 2. Re: Perform AppleScript Issue
            Danxyz

            Thanks.  At least I know I'm not crazy as you seem to have the same issue.  I'll give your idea a whirl.  Another approach is to use AppleScript to talk to TextEdit to write the file.  I've not quite figured that all out but it seems doable.