1 2 Previous Next 19 Replies Latest reply on Nov 15, 2015 2:48 PM by jrenfrew

    Create Reminders From FMP via AppleScrips - How to pass Variables?

    sailmtry

      Hi All,

       

      Really hoping someone can help me with this scripting challenge that I'm having. We are on FileMaker Pro 13 (recently updated) and I simply want to click a button on our layout which will create a New Reminder in the Apple Reminder.APP which will include the contact name, the date for which I want to be reminded, and a short body of text. I've created an AppleScript (see below) which does this, although it's currently hardcoded. However, I have not yet figured out how to pass parameters/variables from FileMaker Pro 13 such as contact name, date, reminder text which are in a pop-up menu (in FMP) to the AppleScript to perform the actual creation of the New Reminder. If anybody out there can help me I'd be most grateful. Thanks in advance

       

      In the AppleScript below, the variables than trying to manipulate from FileMaker Pro are:

       

      mytitle, mydate, mybody, mylist

       

      tell application "Reminders"

      set mytitle to "Name of Contact"

      set mydate to date "Thursday, March 27, 2014 10:30:00 AM"

      set mybody to "Activity - call"

      set mylist to list "Today's Tasks"

      tell mylist

      make new reminder with properties {name:mytitle, body:mybody, due date:mydate}

      end tell

      end tell

       

      Example of the AppleScript run outside of FMP.

        • 1. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
          Malcolm

          You construct the applescript in the calculation dialog box.

           

          List(

          "tell application “& quote(“Reminders”);

          "set mytitle to ” & quote(contact::name);

          “set mydate to date “ & quote( get(currenttimestamp));

          "set mybody to “& quote(reminder);

          “set mylist to list “& quote("Today's Tasks”);

          "tell mylist”;

          "make new reminder with properties ”;

          " end tell”;

          "end tell"

          )

           

           

          malcolm

          • 2. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
            sailmtry

            Hi Malcom,

             

            Thanks for the help!  I see where you are going although I'm still having some challenges.  When I press the "OK" button from the Specify Calculation window, FMP says " the specified table cannot be found and highlights "Set mytitle".  I tried a few variations but couldn't get it to work .

             

            Below is my code thus far.

             

            List(

            "tell application " & " (Reminders.app);

            "set mytitle to " & " (Contact Management::First Name);

            "set mydate to date " & "(Contact Management::Followup Date);

            "set  mylist to list " &" ("Today's Tasks");

            "tell mylist"

            "make new reminder with properties";

            "end tell";

            "end tell")

            • 3. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
              ch0c0halic

              The error indicates too many or not enough quotes. In this case its both. You need a quote before and after each value. The one before doesn’t work as its in the wrong place.

               

               

              List(

               

              "tell application \"“ & Reminders.app & “\”";

               

              "set mytitle to \"" & Contact Management::First Name & “\”";

               

              "set mydate to date \"" & Contact Management::Followup Date & “\”";

               

              "set  mylist to list \"" &" "Today's Tasks" & “\”";

               

              "tell mylist"

               

              "make new reminder with properties properties ";

               

              "end tell";

               

              "end tell")

              • 4. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                sailmtry

                Thanks for your help.  But now it stops at "Reminders.app".  Same error as before. I tried taking of the ".app". but now luck

                • 5. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                  erolst

                  You didn't use Quote() properly:

                   

                  List (

                  "tell application " & Quote ( "Reminders.app" ) ;

                    "set mytitle to " & Quote ( Contact Management::First Name ) ;

                    "set mydate to date " & Quote ( Contact Management::Followup Date ) ;

                    "set mylist to list " & Quote ( "Today's Tasks" ) ;

                    "tell mylist" ;

                      "make new reminder with properties properties " ;

                    "end tell";

                  "end tell"

                  )

                   

                  Make sure that each line except the last one ends with a semicolon ( "tell mylist" …). And probably it's just "Reminder", not "Reminder.app".

                  • 6. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                    ch0c0halic

                    Or just replace the first line with this.

                     

                     

                    "tell application \"Reminders.app\”";

                    • 7. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                      sailmtry

                      Thanks! I managed to get FMP to accept the code but now I'm getting and unknown token error.  I'm sure has something to do with these dang quotes but darn if I can find it.  I check to be sure that  "Use smart quotes" is turned off, and  it is.

                       

                      The Error Message:

                      Expected end of line but found unknown token.  Unknown Error: -2741

                       

                      The Code:

                      List( 

                      "tell application " & "Reminders.app";

                      "set mytitle to " & "(Contact Management::First Name)";

                      "set mydate to date " & "(Contact Management::Followup Date)";

                      "set  mylist to list " & "Today's Tasks";

                      "tell mylist make new reminder with properties ";

                      "end tell";

                      "end tell")

                      • 8. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                        steve_ssh

                        Hello Sailmtry,

                         

                        If you take another close look at some of the code that erolst and ch0c0halic have posted, paying close attention to detail with respect to the techniques used for quoting the values being set, I believe you will see some differences their code and your code that should tip you off to what is going wrong with the code you posted above:

                         

                          - erolst has used the Quote() function to make sure that the values are properly quoted and escaped.

                         

                          - ch0c has taken an approach which inserts quotes into the output string (note that the inserted quotes must be escaped with the backslash char).

                         

                          - the most recent code that you posted will not result in any of the target values being properly quoted when AppleScript evaluates your code.

                         

                         

                        Barring other issues which none of us can see, I believe erolst's solution should serve you well.  If you haven't tried it, I suggest doing so.

                         

                        If you have FMP Advanced, I suggest using the Data Viewer to actually see what these calculations are returning.  I believe that seeing the output will help you understand what is going on.   If you don't have FMP Advanced, you might consider temporarily building a calc field to show you the output (or show the output in the body of a script dialog) so that you can see the resut of your calc.  I believe that doing so will make things much clearer.

                         

                        HTH & best,

                         

                        -steve

                        • 9. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                          sailmtry

                          Steve,

                           

                          My thanks for your insights.  I didn't make the connection that Quote () was a function.  I see what Erolst's was pointing out now.

                           

                          The code (Erolst's) seems to work now.  No errors, but no results either. 

                           

                          I don't have FMP Advanced.  Perhaps I should. 

                           

                          Now I'll need to figure out how to create calc field to show the output temporarily as you suggest.

                           

                          Clearly I'm new to scripting.  My old COBAL days of coding don't seem to be helping me much here!

                           

                          Dan

                          • 10. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                            steve_ssh

                            Hi Dan,

                             

                            I think that you are probably only a few short steps away from figuring this out.

                             

                            It is much tougher to sort these things out if you can't see the result of your calculation.  In this regard, having FMP Advanced certainly can help a lot.

                             

                            Without FMP Advanced, my suggestion would be:

                             

                              Create a temporary field in your "Contact Management" table:

                             

                                 - Give the field some name that you can easily identify

                                 - Set the field type to "calculation"

                                 - In the define calculation dialog box for the field, paste in the code that erolst has supplied

                                 - Save the field

                                 - Add the field to a layout based on the Contact Management layout, and give it large enough dimensions so that you can see all of its value

                             

                              Having done the above:

                             

                                 - Go into Browse mode in FMP, and visually inspect the result in the newly added field

                                 - If the field looks reasonable, copy the entire field contents (i.e. the value displayed in the field), and paste it into AppleScript's ScriptEditor

                                 - See if your script compiles properly in the ScriptEditor, and, if so, try running it to see what happens.

                                 - Hopefully, doing the above will help pinpoint the problem.

                             

                             

                              When you are finished debugging:

                             

                                - Delete your temporary field that you added (in steps above)

                             

                             

                            HTH & best -- You will get this!

                             

                            -steve

                            • 11. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                              BruceRobertson

                              The script won't work as written because it left off the properties.

                               

                              List (

                              "tell application " & Quote ( "Reminders.app" ) ;

                                "set mytitle to " & Quote ( Contact Management::First Name ) ;

                                "set mydate to date " & Quote ( Contact Management::Followup Date ) ;

                                "set mylist to list " & Quote ( "Today's Tasks" ) ;

                                "tell mylist" ;

                                  "make new reminder with properties {name:mytitle, body:mybody, due date:mydate}" ;

                                "end tell";

                              "end tell"

                              )

                              • 12. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                                sailmtry

                                It works!!!!! Thanks Steve!!!!

                                 

                                Your suggestion of creating a field with the calculation of the results of the code so that I can see what's really going on  was a big help. Turns out the the variable mybody was not being set and the script was stopping there.

                                 

                                Now of course I've go one more step and that is to add a "time" to the reminder.  It's currently defaulting to 12am of whatever date is set.  I think is is because  when the script sends a date of say... 03/29/14 it rewrites it in the Date variable as "Saturday, March 29, 1014 12:00:00 AM"

                                 

                                Script below.

                                tell application "Reminders"

                                     set mytitle to "Daniel"

                                     set mydate to date "Saturday, March 29, 2014 12:00:00 AM"

                                     set mylist to list "Today's Tasks"

                                     tell mylist

                                          make new reminder with properties

                                     end tell

                                end tell

                                • 13. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                                  jrenfrew

                                  if you change the end to:

                                   

                                  "set result to make new reminder with properties ...." ;

                                  "end tell" ;

                                  "return the id of result" ;

                                  "end tell"

                                   

                                  you get back just the id in the form

                                  "x-apple-reminder://A72EF967-B536-4B81-A760-40C7798664AE"

                                  so you can more easily parse this into you database

                                   

                                  you can also set the priority 1 = high 5 = medium 9 = low -

                                            set thePriority to 1

                                   

                                   

                                  john

                                  • 14. Re: Create Reminders From FMP via AppleScrips - How to pass Variables?
                                    sailmtry

                                    Great tip, John!  I'll give that a try.

                                     

                                    Thanks,

                                    Dan

                                    1 2 Previous Next