1 2 Previous Next 18 Replies Latest reply on May 26, 2012 1:05 PM by sporobolus

    Problem with native applescript running in Filemaker 12

    tschultz

      I've used a particular native script running under various versions of Filemaker. When I upgraded to v. 12, I started experiencing a curious problem.

       

      I developed a FM script that runs in a file hosted on a network. I run FM Pro Advanced and the other users have Filemaker Pro. The Applescript script says "tell application Filemaker Pro" when they are the users and "tell application Filemaker Pro Advanced" when I am the user.

       

      I recently tried to alter the script for a Filemaker Pro user and kept getting an error message saying "Expected end of line but found class name." The highlight stopped on the word "record" at the end of this line--tell current record. I could not click on OK without receiving the error message.

       

      If I change the "tell application..." line to "tell application Filemaker Pro Advanced," I can click OK and save the FM script. The problem is that when the script is triggered on a machine that only has FMP it tries to find that app and I get an error. As soon as I remove "Advanced" from the Applescript, I get the error.

       

      Again, everything worked fine under Filemaker 10 and 11. I'm not an expert with Applescript. Any help would be appreciated.

       

      Thanks much.

        • 1. Re: Problem with native applescript running in Filemaker 12
          jml

          Do you have both FMP v12 and FMP Advanced v12 installed on your development Mac?

          • 2. Re: Problem with native applescript running in Filemaker 12
            tschultz

            Thanks for your response. No, I only have FMPA 12

            • 3. Re: Problem with native applescript running in Filemaker 12
              jml

              I suspect that it is looking for the applescript dictionary of the application referrenced in the tell statement and cannot find FileMaker Pro.

              • 4. Re: Problem with native applescript running in Filemaker 12
                tschultz

                That's interesting, but why did this work before when I was using Filemaker 10 and 11? I didn't have the Applescript dictionary on my machine then either.

                 

                I don't know why I was able to save scripts copied in from Applescript in those versions and now suddenly FM is recognizing all sorts of errors that prevent me from saving any changes. Again, this is only on a script that references Filemaker Pro, not FMPA.

                • 5. Re: Problem with native applescript running in Filemaker 12
                  ch0c0halic

                  tschultz may be too specific,

                   

                  Remove the "Tell FMP/end tell" lines. They aren't needed when run from within FMP. This issue has always caused the problems your encountering. It is not new to FMP12.

                   

                  Since this AppleScript is running from within FMP, not the AppleScript Editor, you don't need to "Tell FMP". Since FMP is the application running the AppleScript it is automatically addressed when no other application "Tell" is used.

                   

                  An Applications AppleScript Dictionary is imbedded in the App and is not installed in the OS. When the application is installed the OS reads the Apps AS Dictionary when needed.

                   

                   

                  To all posters,

                  When asking about an AppleScript or Calculation or script it is very useful to include the actual values so other's know what you are talking about.

                  • 6. Re: Problem with native applescript running in Filemaker 12
                    tschultz

                    Thanks. I am trusting that you're right. And I get the point about showing the script next time--chalk one up to a novice poster. Sorry about that.

                     

                    You've probably already figured out that I'm not a real developer. As you can see, the script in question was one I had adapted from someone esle.

                     

                    In any case, I am still curious as to why the problem surfaced in the upgrade. As I said, I could always adjust that particular script with no problem until the upgrade. Something had to change.

                     

                    To test that, I gave the FMP user privileges to modify scripts (this was before I got your post). I went to his machine and changed "tell Filemaker Pro Advanced" to "tell Filemaker Pro" and I was able to save the script with no problem. I never had to do that before.

                     

                    Oh well, problem solved and I learned some important things. Thanks again.

                     

                     

                     

                    For what it's worth, I did find that I could make changes to the script by changing privileges

                    • 7. Re: Problem with native applescript running in Filemaker 12
                      sporobolus

                      on 2012-05-03 12:30 tschultz wrote

                      In any case, I am still curious as to why the problem surfaced in the upgrade. As I said, I could always adjust that particular script with no problem until the upgrade. Something had to change.

                       

                      To test that, I gave the FMP user privileges to modify scripts (this was before I got your post). I went to his machine and changed "tell Filemaker Pro Advanced" to "tell Filemaker Pro" and I was able to save the script with no problem. I never had to do that before.

                       

                       

                      the point is you should avoid 'tell app "Filemaker ..."' in AppleScripts within

                      FileMaker; even though it worked for a while, it was always a potential source

                      of error, and that finally caught up with you ...

                       

                      but i'm curious what version did you upgrade from? and what version(s) of Mac

                      OS X? starting with FileMaker 11 there is some pretty weird stuff with Apple

                      Events (the underlying technology of AppleScript) due, apparently, to the

                      conversion to Cocoa, and knowing what versions you are talking about might help

                      paint a bigger picture ...

                      1 of 1 people found this helpful
                      • 8. Re: Problem with native applescript running in Filemaker 12
                        tschultz

                        Sorry for the late response. I just pulled your email from my spam folder today.

                         

                        Since you were nice enough to answer, let me reply here:

                         

                        I upgraded from Filemaker Pro 11 to Filemaker Pro 12 (I use the advanced version, the other machines on the network use Filemaker Pro).

                         

                        I recently went from an old iBook to a MacBook Pro, so I went through a change from Leopard on that machine, to working with Filemaker on the Lion platform.

                         

                        Here is a copy of the applescript I am using now. As you can see, it goes back a ways and I fear that this may be a part of the problem. I checked the script with Applescript and it doesn't note any problems.

                         

                        So for whatever it's worth…

                         

                        Thanks again for your interest and assistance.

                         

                        Tim

                         

                        (*

                        Create ToDo

                         

                        Copyright © 2007 Jonathan Stark

                         

                        This script automates the process of creating iCal calendar ToDo from FileMaker records.

                         

                        You may incorporate this sample code into your program(s) without

                        restriction.  This sample code has been provided "AS IS" and the

                        responsibility for its operation is yours.  You are not permitted to

                        redistribute this sample code as "Jonathan Stark sample code" after having

                        made changes.  If you're going to redistribute the code, I would appreciate it

                        if you make it clear that the code was descended from Jonathan Stark's sample

                        code, but that you've made changes.

                         

                        Have fun!

                         

                        Visit www.jonathanstark.com for

                        more fun with PHP, FileMaker,

                        AppleScript, iCal, and more...

                         

                        *)

                         

                        -- grab the data from Filemaker

                         

                        tell current record

                                set theCalendar to "New Business"

                                if cellValue of cell "Contact History Follow Up Method" is not "Email" or "Call" then

                                    set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name"

                                end if

                                if cellValue of cell "Contact History Follow Up Method" is "Call" then

                                    set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Office Phone"

                                end if

                                if cellValue of cell "Contact History Follow Up Method" is "Email" then

                                    set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Email from Masterfile"

                                end if

                                set theDescription to cellValue of cell "Contact History Reason for Follow Up" & " - " & cellValue of cell "Contact History Notes"

                                set theCallDate to cellValue of cell "Contact History Target Follow Up Date"

                        end tell

                         

                         

                        -- convert text to dates

                        set theCallDate to date theCallDate

                         

                        -- create the ToDo in iCal

                        tell application "iCal"

                        -- make new calendar if need be

                            set allCalendars to the title of every calendar

                            if allCalendars contains theCalendar then

                                set theCalendarNumber to (first calendar whose title is theCalendar)

                            else

                                set theCalendarNumber to (make calendar at end of calendars with properties {title:theCalendar})

                            end if

                           

                            -- set the ToDo properties

                            tell calendar theCalendar

                                activate

                               

                                -- make ToDo

                                set theToDo to make todo at end

                               

                                -- set the ToDo properties

                                tell theToDo

                                    set the priority to high priority

                                    set the summary to thePerson

                                    set the description to theDescription

                        set the due date to theCallDate

                                   

                                    -- send email alarm two days before to the logged in user

                                    make new mail alarm at end with properties {trigger interval:-2880}

                                end tell

                               

                                -- get the unique identifier of the new ToDo

                                set theUID to the uid of theToDo

                               

                            end tell

                        end tell

                         

                        -- send the ToDo UID to Filemaker, if the field is on the current layout

                         

                            tell current record

                                try

                                    set the cellValue of cell "iCal UID Contact History" to theUID

                                end try

                            end tell

                         

                         

                        quit application "iCal"

                        • 9. Re: Problem with native applescript running in Filemaker 12
                          digitel

                          tschultz >

                           

                          I am also still curious about your issue.

                          Can you describe how you run this applescript from within FM?

                           

                          --

                          ForNow

                          DigitEL

                          • 10. Re: Problem with native applescript running in Filemaker 12
                            tschultz

                            Here's a screenshot of the script from Filemaker. You can see the command to perform the Applescript.

                             

                            FileMaker Pro AdvancedScreenSnapz001.png

                            • 11. Re: Problem with native applescript running in Filemaker 12
                              digitel

                              tschultz >

                               

                              Can you show the code from your original where you say, 'The Applescript script says "tell application Filemaker Pro" when they are the users and "tell application Filemaker Pro Advanced" when I am the user.'? It is important to understand where you are seeing this.

                               

                              EL

                              • 12. Re: Problem with native applescript running in Filemaker 12
                                tschultz

                                Here's the whole script that houses the sub-script I sent you.

                                 

                                 

                                Send This Date as ToDo to iCal (from Contact History)

                                If [ IsEmpty(Contact History::Contact History Follow Up Method) ]
                                Show Custom Dialog [ Message: "The Follow-Up Method field is empty. You must fill that in before proceeding."; Default Button: “OK”, Commit: “Yes” ] Exit Script [ ]

                                End If
                                If
                                [ IsEmpty(Contact History::Contact History Target Follow Up Date) ]

                                Show Custom Dialog [ Message: "The Follow-Up Date field is empty. You must fill that in before proceeding."; Default Button: “OK”, Commit: “Yes” ]

                                Exit Script [ ] End If

                                Set Error Capture [ On ]
                                If [ Get ( AccountName ) = "Gary" ]

                                Commit Records/Requests

                                [ No dialog ]

                                Perform AppleScript [ Native AppleScript: -- grab the data from Filemaker tell application "FileMaker Pro"

                                tell current record
                                set theCalendar to "Gary"

                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Office Phone" & " - " & cellValue of cell "Contact History Email from Masterfile"

                                set theDescription to cellValue of cell "Contact History Reason for Follow Up" & " - " & cellValue of cell "Contact History Notes"

                                set theCallDate to cellValue of cell "Contact History Target Follow Up Date" end tell

                                end tell

                                -- convert text to dates
                                set theCallDate to date theCallDate

                                -- create the ToDo in iCal tell application "iCal"

                                -- make new calendar if need be
                                set allCalendars to the title of every calendar if allCalendars contains theCalendar then

                                set theCalendarNumber to (first calendar whose title is theCalendar) end if

                                -- set the ToDo properties tell calendar theCalendar activate

                                 

                                 

                                 

                                May 22, 2012 8:05e:n2d6 tell end tell

                                -- get the unique identifier of the new ToDo set theUID to the uid of theToDo

                                show theToDo

                                ParadigmDBase.fmp12 - Send This Date as ToDo to iCal (from Contact History) -1-

                                 

                                 

                                -- make ToDo
                                set theToDo to make todo at end

                                -- set the ToDo properties tell theToDo

                                set the priority to high priority
                                set the summary to thePerson
                                set the description to theDescription set the due date to theCallDate

                                -- send email alarm two days before to the logged in user

                                make new mail alarm at end with properties {trigger interval:-2880} end tell

                                 

                                 

                                -- send the ToDo UID to Filemaker, if the field is on the current layout tell application "FileMaker Pro"

                                tell current record try

                                 

                                 

                                end tell end tell

                                 

                                 

                                quit application "iCal" ]

                                 

                                 

                                set the cellValue of cell "iCal UID Contact History" to theUID end try

                                 

                                 

                                -- make ToDo
                                set theToDo to make todo at end

                                -- set the ToDo properties tell theToDo

                                set the priority to high priority
                                set the summary to thePerson
                                set the description to theDescription set the due date to theCallDate

                                -- send email alarm two days before to the logged in user

                                make new mail alarm at end with properties {trigger interval:-2880} end tell

                                 

                                 

                                -- get the unique identifier of the new ToDo

                                 

                                 

                                Send This Date as ToDo to iCal (from Contact History)

                                 

                                 

                                set theUID to the uid of theToDo

                                 

                                 

                                 

                                show theToDo end tell

                                 

                                 

                                end tell

                                -- send the ToDo UID to Filemaker, if the field is on the current layout tell application "FileMaker Pro"

                                tell current record try

                                set the cellValue of cell "iCal UID Contact History" to theUID end try

                                end tell end tell

                                quit application "iCal" ]
                                Set Variable [ $_Error; Value:Get ( LastError ) ] If [ $_Error <> 0 ]

                                Show Custom Dialog [ Title: "Error"; Message: "Sorry, there was an error in the applescript. It is most likely due to the renaming of an object (a field or the file itself). "; Default Button: “OK”, Commit: “No” ] End If

                                Exit Script [ Result: $_Error ] End If

                                If [ Get ( AccountName )="Admin" ] Commit Records/Requests

                                [ No dialog ]

                                Perform AppleScript [ Native AppleScript: (* Create ToDo

                                Copyright © 2007 Jonathan Stark
                                This script automates the process of creating iCal calendar ToDo from FileMaker records.

                                You may incorporate this sample code into your program(s) without
                                restriction. This sample code has been provided "AS IS" and the
                                responsibility for its operation is yours. You are not permitted to
                                redistribute this sample code as "Jonathan Stark sample code" after having made changes. If you're going to redistribute the code, I would appreciate it
                                if you make it clear that the code was descended from Jonathan Stark's sample code, but that you've made changes.

                                Have fun!

                                Visit www.jonathanstark.com for more fun with PHP, FileMaker, AppleScript, iCal, and more...

                                *)
                                -- grab the data from Filemaker tell current record

                                 

                                 

                                May 22, 2012 8:05:26

                                end tell

                                end if
                                if cellValue of cell "Contact History Follow Up Method" is "Email" then

                                 

                                 

                                set theCalendar to "New Business"
                                if cellValue of cell "Contact History Follow Up Method" is not "Email" or "Call" then

                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" end if

                                if cellValue of cell "Contact History Follow Up Method" is "Call" then
                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Office Phone"

                                 

                                 

                                ParadigmDBase.fmp12 - Send This Date as ToDo to iCal (from Contact History) -2- set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Email from Masterfile"

                                 

                                 

                                end if
                                set theDescription to cellValue of cell "Contact History Reason for Follow Up" & " - " & cellValue of cell "Contact History Notes" set theCallDate to cellValue of cell "Contact History Target Follow Up Date"

                                 

                                 

                                -- convert text to dates
                                set theCallDate to date theCallDate

                                -- create the ToDo in iCal tell application "iCal"

                                 

                                 

                                Have fun!

                                 

                                 

                                Visit www.jonathanstark.com for more fun with PHP, FileMaker, AppleScript, iCal, and more...

                                *)
                                -- grab the data from Filemaker tell current record

                                set theCalendar to "New Business"
                                if cellValue of cell "Contact History Follow Up Method" is not "Email" or "Call" then

                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name"

                                 

                                 

                                end if

                                 

                                 

                                Send This Date as ToDo to iCal (from Contact History)

                                 

                                 

                                if cellValue of cell "Contact History Follow Up Method" is "Call" then
                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Office Phone"

                                end if
                                if cellValue of cell "Contact History Follow Up Method" is "Email" then

                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Email from Masterfile" end if

                                set theDescription to cellValue of cell "Contact History Reason for Follow Up" & " - " & cellValue of cell "Contact History Notes" set theCallDate to cellValue of cell "Contact History Target Follow Up Date"

                                 

                                 

                                 

                                end tell

                                 

                                 

                                -- convert text to dates
                                set theCallDate to date theCallDate

                                -- create the ToDo in iCal
                                tell application "iCal"
                                -- make new calendar if need be

                                set allCalendars to the title of every calendar if allCalendars contains theCalendar then

                                 

                                 

                                set theCalendarNumber to (first calendar whose title is theCalendar)

                                set theCalendarNumber to (make calendar at end of calendars with properties {title:theCalendar})

                                end if

                                -- set the ToDo properties

                                tell calendar theCalendar activate

                                -- make ToDo
                                set theToDo to make todo at end

                                -- set the ToDo properties tell theToDo

                                set the priority to high priority
                                set the summary to thePerson
                                set the description to theDescription

                                set the due date to theCallDate

                                 

                                 

                                end tell end tell

                                 

                                 

                                else

                                 

                                 

                                -- send email alarm two days before to the logged in user

                                make new mail alarm at end with properties {trigger interval:-2880} end tell

                                -- get the unique identifier of the new ToDo set theUID to the uid of theToDo

                                 

                                 

                                -- send the ToDo UID to Filemaker, if the field is on the current layout

                                tell current record try

                                set the cellValue of cell "iCal UID Contact History" to theUID end try

                                 

                                 

                                end tell

                                quit application "iCal" ]

                                May 22, 2012 8:05:26

                                ParadigmDBase.fmp12 - Send This Date as ToDo to iCal (from Contact History) -3-

                                 

                                 

                                Send This Date as ToDo to iCal (from Contact History)

                                Set Variable [ $_Error; Value:Get ( LastError ) ] If [ $_Error <> 0 ]

                                Show Custom Dialog [ Title: "Error"; Message: "Sorry, there was an error in the applescript. It is most likely due to the renaming of an object (a field or the file itself). "; Default Button: “OK”, Commit: “No” ] End If

                                Exit Script [ Result: $_Error ] End If

                                If [ Get ( AccountName )="Dennis" ] Commit Records/Requests

                                [ No dialog ]

                                Perform AppleScript [ Native AppleScript: (* Create ToDo

                                Copyright © 2007 Jonathan Stark
                                This script automates the process of creating iCal calendar ToDo from FileMaker records.

                                You may incorporate this sample code into your program(s) without
                                restriction. This sample code has been provided "AS IS" and the
                                responsibility for its operation is yours. You are not permitted to
                                redistribute this sample code as "Jonathan Stark sample code" after having made changes. If you're going to redistribute the code, I would appreciate it
                                if you make it clear that the code was descended from Jonathan Stark's sample code, but that you've made changes.

                                Have fun!

                                Visit www.jonathanstark.com for more fun with PHP, FileMaker, AppleScript, iCal, and more...

                                *)

                                -- grab the data from Filemaker tell application "Filemaker Pro"

                                tell current record
                                set theCalendar to "New Business"

                                 

                                 

                                 

                                if cellValue of cell "Contact History Follow Up Method" is not "Email" or "Call" then
                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name"

                                end if
                                if cellValue of cell "Contact History Follow Up Method" is "Call" then

                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Office Phone" end if

                                if cellValue of cell "Contact History Follow Up Method" is "Email" then
                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Email from Masterfile"

                                end if
                                set theDescription to cellValue of cell "Contact History Reason for Follow Up" & " - " & cellValue of cell "Contact History Notes" set theCallDate to cellValue of cell "Contact History Target Follow Up Date"

                                 

                                 

                                end tell end tell

                                 

                                 

                                -- convert text to dates
                                set theCallDate to date theCallDate

                                -- create the ToDo in iCal tell application "iCal"

                                -- make new calendar if need be
                                set allCalendars to the title of every calendar if allCalendars contains theCalendar then

                                else

                                set theCalendarNumber to (make calendar at end of calendars with properties {title:theCalendar})

                                end if

                                -- set the ToDo properties

                                tell calendar theCalendar activate

                                -- make ToDo
                                set theToDo to make todo at end

                                 

                                 

                                May 22, 2012 8:05:26 ParadigmDBase.fmp12 - Send This Date as ToDo to iCal (from Contact History) -4- set theCalendarNumber to (first calendar whose title is theCalendar)

                                 

                                 

                                -- set the ToDo properties

                                 

                                 

                                if cellValue of cell "Contact History Follow Up Method" is "Call" then
                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Office Phone"

                                end if
                                if cellValue of cell "Contact History Follow Up Method" is "Email" then

                                set thePerson to cellValue of cell "Contact History Follow Up Method" & " - " & cellValue of cell "Contact History Name" & " - " & cellValue of cell "Contact History Email from Masterfile" end if

                                set theDescription to cellValue of cell "Contact History Reason for Follow Up" & " - " & cellValue of cell "Contact History Notes"

                                set theCallDate to cellValue of cell "Contact History Target Follow Up Date" end tell

                                end tell

                                -- convert text to dates
                                set theCallDate to date theCallDate

                                 

                                 

                                -- create the ToDo in iCal

                                 

                                 

                                Send This Date as ToDo to iCal (from Contact History)

                                 

                                 

                                tell application "iCal"
                                -- make new calendar if need be
                                set allCalendars to the title of every calendar if allCalendars contains theCalendar then

                                 

                                 

                                 

                                set theCalendarNumber to (first calendar whose title is theCalendar)

                                set theCalendarNumber to (make calendar at end of calendars with properties {title:theCalendar})

                                end if

                                -- set the ToDo properties

                                tell calendar theCalendar activate

                                -- make ToDo
                                set theToDo to make todo at end

                                -- set the ToDo properties tell theToDo

                                set the priority to high priority
                                set the summary to thePerson
                                set the description to theDescription

                                set the due date to theCallDate

                                -- send email alarm two days before to the logged in user

                                make new mail alarm at end with properties {trigger interval:-2880} end tell

                                -- get the unique identifier of the new ToDo set theUID to the uid of theToDo

                                show theToDo end tell

                                end tell

                                -- send the ToDo UID to Filemaker, if the field is on the current layout tell application "Filemaker Pro"

                                tell current record try

                                set the cellValue of cell "iCal UID Contact History" to theUID end try

                                end tell end tell

                                quit application "iCal" ]

                                Set Variable [ $_Error; Value:Get ( LastError ) ] If [ $_Error <> 0 ]

                                Show Custom Dialog [ Title: "Error"; Message: "Sorry, there was an error in the applescript. It is most likely due to the renaming of an object (a field or the file itself). "; Default Button: “OK”, Commit: “No” ] End If

                                Exit Script [ Result: $_Error ] End If

                                 

                                • 13. Re: Problem with native applescript running in Filemaker 12
                                  Mike Duncan

                                  The first applescript step in this long sequence looks like it still may be trying to call filemaker by name. If that's the case, this is probably where it's failing, instead of the script to create the todo in ical...

                                   

                                  Perform AppleScript [ Native AppleScript: -- grab the data from Filemaker tell application "FileMaker Pro"

                                  • 14. Re: Problem with native applescript running in Filemaker 12
                                    tschultz

                                    I think that's on the --line that's part of the description. I believe the actual script now starts with "tell current record"--at least I thought I got rid of all of the "tell Filemaker Pro" lines that were part of the script. I'll double check. Thanks.

                                    1 2 Previous Next