11 Replies Latest reply on Oct 9, 2012 10:57 PM by ijontichy

    Applescript...a little help



      Applescript...a little help


           FIlemaker Pro Advanced v11.   Mac osX 10.7.5


           I have a little applet that appends some necessary text to the front of a text file that Filemaker generates.   


           I'd love to know how I get Filemaker to basically "drop" that recently created file on the applet, so I can make a "one button" solution out of what is currently "one button plus one drag and drop."   I don't know enough about applescript so I could use a bit of help.   And folder actions have failed me as well, though I suspect that's strictly a scripting shortcoming as well.

           I'll share scripts and more details...anyone want to offer any help?

           And to answer the obvious, it's easier to append the text to the file that Filemaker generates than it is to do it in filemaker because of highly specific formatting concerns.   More detail if needed.



        • 1. Re: Applescript...a little help

               Please supply the "more detail" this sounds like something that is very easy to do fully in a FileMaker script.

          • 2. Re: Applescript...a little help

                 Okay.  Thanks Phil!.


                 Here is a sample of what filemaker generates:


                 25n_1_a_ns0070_v3004_le.mov    V    13:03:56:06    13:03:57:19    20121004_001    MET    Final        25n_1_a_ns0070_v3004.s3d    MONOCULAR_LEFT    Right
                 25n_1_a_ns0070_v3004_re.mov    V    13:03:56:06    13:03:57:19    20121004_001    MET    Final        25n_1_a_ns0070_v3004.s3d    MONOCULAR_RIGHT    Right
                 31f_3_a_ns0074_v3003_le.mov    V    19:05:25:12    19:05:27:10    20121004_001    MET    Final        31f_3_a_ns0074_v3003.s3d    MONOCULAR_LEFT    Right
                 31f_3_a_ns0074_v3003_re.mov    V    19:05:25:12    19:05:27:10    20121004_001    MET    Final        31f_3_a_ns0074_v3003.s3d    MONOCULAR_RIGHT    Right
                 59b_2_a_ns0082_v3003_le.mov    V    20:14:28:05    20:14:29:20    20121004_001    MET    Final        59b_2_a_ns0082_v3003.s3d    MONOCULAR_LEFT    Right
                 59b_2_a_ns0082_v3003_re.mov    V    20:14:28:05    20:14:29:20    20121004_001    MET    Final        59b_2_a_ns0082_v3003.s3d    MONOCULAR_RIGHT    Right
                 64k_1_a_ns0078_v3004_le.mov    V    11:33:02:01    11:33:04:10    20121004_001    MET    Final        64k_1_a_ns0078_v3004.s3d    MONOCULAR_LEFT    Right
                 64k_1_a_ns0078_v3004_re.mov    V    11:33:02:01    11:33:04:10    20121004_001    MET    Final        64k_1_a_ns0078_v3004.s3d    MONOCULAR_RIGHT    Right
                 65g_2_a_ns0086_v3003_le.mov    V    20:29:37:03    20:29:38:20    20121004_001    MET    Final        65g_2_a_ns0086_v3003.s3d    MONOCULAR_LEFT    Right
                 65g_2_a_ns0086_v3003_re.mov    V    20:29:37:03    20:29:38:20    20121004_001    MET    Final        65g_2_a_ns0086_v3003.s3d    MONOCULAR_RIGHT    Right
                 76_7_a_ns0094_v3003_le.mov    V    19:27:51:20    19:27:53:12    20121004_001    MET    Final        76_7_a_ns0094_v3003.s3d    MONOCULAR_LEFT    Right
                 76_7_a_ns0094_v3003_re.mov    V    19:27:51:20    19:27:53:12    20121004_001    MET    Final        76_7_a_ns0094_v3003.s3d    MONOCULAR_RIGHT    Right


                 Pretty straight forward--tab delimited information.   The last field is currently blank, but present.

                 Here is the header that I need appended to the file.


                 FIELD_DELIM    TABS
                 VIDEO_FORMAT    1080
                 FILM_FORMAT    35mm, 4 perf
                 AUDIO_FORMAT    48khz
                 FPS    23.976

                 Name    Track    Start    End    DeliveryID    Vendor    Submitted_For    Notes    S3D Group Name    S3D Channel    BEST_EYE



                 And then the tab delimited data begins on the very next line after "Data"

                 The issue is that while this is a text file, it's imported by an editing system as data and therefore there is NO tolerance for stray tabs or other formatting foofooraw.


                 So what is the best way in filemaker to achieve this, knowing that the only lines with tabs in the header is in the line with the field names (Name Track Start, etc.)?     Also, there are issues (on mac at least) of Filemaker exporting Line feeds rather than paragraph returns when you add paragraph returns in a formula.  This factors in as well, but is easier to deal with.


                 appreciate the help.

            • 3. Re: Applescript...a little help

                   And for the truly curious, Here's the apple script that appends the front of the file:

                   property myHeading : "Heading
                   FIELD_DELIM    TABS
                   VIDEO_FORMAT    1080
                   FILM_FORMAT    35mm, 4 perf
                   AUDIO_FORMAT    48khz
                   FPS    23.976

                   Name    Track    Start    End    DeliveryID    Vendor    Submitted_For    Notes    S3D Group Name    S3D Channel    BEST_EYE

                   on run
                       tell me to set theFiles to choose file "Bitte Datei(en) wählen:" with multiple selections allowed
                   end run

                   on open theFiles
                   end open

                   on fixHeading(theFiles)
                       repeat with myFile in theFiles
                           set myReferenceNumber to open for access myFile with write permission
                           set myText to read myReferenceNumber to eof
                           write myHeading & myText to myReferenceNumber starting at 1
                           close access myReferenceNumber
                       end repeat
                   end fixHeading



              • 4. Re: Applescript...a little help


                     Phil...have I stumped you?   I find that very hard to believe.


                     If you have the time, would still love your input/ solution.



                • 5. Re: Applescript...a little help

                       I don't own a mac and thus haven't touched an AppleScript in years. I've left this to others who DO work with AppleScript to suggest an answer.

                  • 6. Re: Applescript...a little help

                         Okay, Thanks Phil.   No one else has volunteered any solutions..   I had held out some hope you would find a way to do this strictly in filemaker.

                         Will muddle along.

                         Still very grateful for all the help you do give every day.



                    • 7. Re: Applescript...a little help

                           You might try posting this question in another FileMaker forum such as Technet (It's now possible to join for free) or an independent forum such as: http://fmforums.com

                      • 8. Re: Applescript...a little help

                             And to answer the obvious, it's easier to append the text to the file that Filemaker generates than it is to do it in filemaker because of highly specific formatting concerns.

                             The only formatting characters needed are returns and tabs from you posts?

                             Calculated PreText

                             FMP Generated Text

                             Calculated Final File

                             "Heading" & ¶ &
                             "FIELD_DELIM    TABS" & ¶ &
                             "VIDEO_FORMAT    1080" &  ¶ &
                             "FILM_FORMAT    35mm, 4 perf" &  ¶ &
                             "AUDIO_FORMAT    48khz" &  ¶ &
                             "FPS    23.976" &  ¶¶ &

                             "Column" &
                             "Name" & "pasted TAB" &  "Track "& "pasted TAB" & "Start" & "pasted TAB" &     End    DeliveryID    Vendor    Submitted_For    Notes    S3D Group Name  & "pasted TAB" &  "S3D Channel"  & "pasted TAB" &  "BEST_EYE" &  ¶¶ &


                        TABs in Calculations

                             1]  http://forums.filemaker.com/posts/126ce2f1a4?commentId=173826#173826
                             I've tried explaining this to others, and have tried finding an answer here, but for years have not found a solution. Thanks, Jeff for starting this thread, maybe now someone (from Filemaker perhaps?) can explain a solution or work-around that doesn't necessitate having to perform multiple searches and exports for something Filemaker does half-way. Why not just put a TAB (Char #9) button under the ¶ symbol in the equation editor?
                             POST  When I want a tab character inserted into literal text I just copy and paste it from another word processing document.  For example, when I want to build up a text field in a script (to make a tabular presentation in an email or text field, say) I set the field to have the appropriate tab settings and then just use the pasted tab character.  Yes, it would be handy to have a button to insert it, but copy-and-paste from Word is two seconds, anyway.

                             Pasted TAB in Calculation window returns this in Manage window

                             2] "Have you ever wanted to insert a tab into a block of text (so you can use tab stops to line up columns of text), or have you wanted to use the tab character in a calculation? If you try to just press the TAB key, the default action for FileMaker is to go to the next field... bummer.

                             However - there is a solution! Simply hold down the Option key (Mac OS) or Ctrl key (Windows) while typing the TAB key. This will insert a "soft" tab into your field. This works the same whether you're in a field in Browse mode - or whether you're in a calculation (in FileMaker 7+).

                             3] Field 1 & "(tab)" & Field 2 & "(tab)" & Field 3 & "(tab)" & Field 4 & "(tab)" Field 5 & "(tab)"
                             (where (tab) is a tab copied from a text editor)

                             4] One of the first things I often do when creating a new database is to define two Global Fields and paste a TAB into one and type a " into the other.  Saves a lot of frustration and messing about later."


                             Also found this in my search

                        Calculation Formatter: Submit a valid FileMaker Pro calculation expression or custom function below.

                        • 9. Re: Applescript...a little help

                               I'm not sure I understand.   Calculated pretext?   Can I have filemaker generate "header" text that doesn't simply inhabit the first field of an export?   Because when I do that then I get tabs for the other fields that throws off the automation.

                               A related issue is that paragraph returns thrown into calculations always come out of the mac version of filemaker as LINEFEEDS, which don't work with my automation.   If there's a way to toggle that I don't know it.

                               If pretext is possible then I can certainly try the tab solutions.


                          • 10. Re: Applescript...a little help

                                 A long time ago, I created a database that output an html file for a static database webpage.

                                 The header was a global calculation field

                                 The body was a calculation field containing fields from found set records.

                                 The footer was a global calculation field.

                                 The output was a global calculation field containing header, body, footer calculated fields.

                                 I think I outputed a CVS (could have been Tab Delimited, or maybe merge field)  worked very well.


                                                     Click the ¶ button (carriage return operator) to insert a line break.
                                 See Defining calculation fields for information about the dialog box.
                                                          Click OK.
                            Note  Type \¶ (backslash followed by a carriage return operator) to enter a carriage return (paragraph) symbol instead of an actual line break.


                                 A similar process was used to output a catalog using Pagemaker on Mac. Today, Indesign would be used  http://automator.us/examples-04.html

                                 Your output document is simple, I am almost positive it can be done natively in Filemaker.


                            http://macscripter.net/viewtopic.php?id=34897    Getting Applescript and Filemaker Pro interacting

                            • 11. Re: Applescript...a little help

                                   I appreciate you taking the time.

                                   However, there is one process that I have to take out of filemaker and that's turning line feeds into solid carriage returns.   Any carriage return in a calculation gets turned into a linefeed and my automation cannot accept it.

                                    Maybe XML is the way to go.

                                   Otherwise I need to learn applescript well enough that I can have filemaker tell applescript to run a specific "cleaning" script app on the file Filemaker has just generated.


                                   But even if I had master calculation fields like you are suggesting, this part of the process would stymie me.