2 Replies Latest reply on Dec 15, 2011 4:11 PM by steveharley

    File Maker finds faults in an Applescript that both compiles and runs perfectly in Applescript...

    CamillaHarrysson

      Title

      File Maker finds faults in an Applescript that both compiles and runs perfectly in Applescript Editor

      Post

      Hi,
       
      I can´t get FileMaker to accept a script that runs perfectly in the Applescript editor. I don´t see the point of FileMaker editing/compiling the script at all or at least why it isn´t optional since as far as my understanding goes running the applescript later in application will not envolve FileMaker at all ofher than if the applescript addresses FileMaker.
       
      How can I get past this?
       
      Or is there any way I can change the applescript and get the same results? I´m quite new to applescript and have picked different ideas from the web.
       
      Before I added photo/img handling to the script it was accepted by FM and worked fine. Know the user really wants pictures in her Address Book and to be able to update with them over and over so I realy want to have them originate from containerfields in the FM databas. I store a reference file in the container field and convert the filepath to correkt applescript format (OSX:user:.....) in a calculation field inside FileMaker. Then I collect the filepath from that cell with the applescript.
       
      Below is the applescrip in full and the picture showing the FM error and marked spot were it stops.
       
      Greatful for answers!
       
       
      APPLESCRIPT IN FULL:

      -- get the data from the current record in FileMaker

      tellapplication "FileMaker Pro Advanced"

      tell current record

      setAddress_Book_IDtocell "Address Book ID"

      setAddress_Book_Grouptocell "Address Book Group"

      setPersonal_departmenttocell "FLAGGA_anställd_konsult"

      setPersonal_firstnametocell "f_Personal förnamn"

      setPersonal_lastnametocell "f_Personal Efternamn"

      setPersonal_IDphoto_filenametocell "cal_ID_photo fullpath"

      setPersonal_IDphoto_defaulttocell "cal_ID_photo default fullpath"

      setPersonal_Work_phonetocell "f_Tel internt"

      setPersonal_Mobile_phonetocell "f_Tel mob"

      setPersonal_Home_phonetocell "f_Tel hem"

      setPersonal_Anh1_namntocell "f_Personals anhörig att kontakta"

      setPersonal_Anh1_phonetocell "f_Personals anhörigs tel 1"

      setPersonal_Anh2_phonetocell "f_Personals anhörigs tel 2"

      setPersonal_Work_emailtocell "f_email"

      set Personal_Address_street to cell "f_adress"

      setPersonal_Address_ziptocell "f_Postnummer"

      setPersonal_Address_citytocell "f_Postadress"

      setPersonal_Notetocell "f_Note"

      endtell

      endtell

       

       

      ------------------------------------------------------------------------------------------------------------------------

       

       

      --get current date so it can be used to 'tag' the entry for future sorting

      tell current application

      setFM_updatetothecurrent date

      endtell

       

      --If IDphoto load the filepath or if not fill varible with default (to prevent undefined varible error). 

      --Set flag laddaimg if IDphoto in order to prevent default img to be read and put in Address Book

      if Personal_IDphoto_filename is not "" then

      tellapplication "System Events"

      set imgfile to Personal_IDphoto_filename

      setladdaimgto 1

      endtell

      else

      set imgfile to Personal_IDphoto_default

      setladdaimgto 0

      endif

       

      --If IDphoto make it accessable and set the reading in TIFF format

      ifladdaimgis 1 then

      set imgfd to open for accessimgfile

      setimgtoreadimgfdas "TIFF"

      endif

       

      --If Anhörigs namn is not filled put default text to prevent error when using this varible as label setting for phone number

      if Personal_Anh1_namn is "" then

      setPersonal_Anh1_namnto "Anhörig"

      endif

       

       

      ------------------------------------------------------------------------------------------------------------------------

       

       

      tellapplication "Address Book"

      -- look through every group to see if Bopec Kund exists and if not make group

      settheGrouptoeverygroup

      repeatwithaGroupintheGroup

      if name of aGroup is Address_Book_Group then

      setgrupp_finnsto "1"

      else

      setgrupp_finnsto ""

      endif

      endrepeat

      --

      ifgrupp_finns = "" then

      makenewgroupat end of groupswith properties {name:Address_Book_Group}

      endif

       

      -- If FileMaker have a previously collected Address Book ID - check for a pre-existing version of the contact

      ifAddress_Book_IDisnot "" then

      sethow_manytocount (peoplewhoseid = Address_Book_ID)

      ifhow_manyisequal to 1 then

      -- if only one is found =correct - select this entry and update it with the collected FileMaker data

      settheContactstoeverypersonwhoseid = Address_Book_ID

      set thePerson to item 1 of theContacts

      tell thePerson

      set first name of thePerson to Personal_firstname

      set last name of thePerson to Personal_lastname

      set organization of thePerson to Personal_department

      setcompanyofthePersontofalse

      ifladdaimgis 1 then

      setimageofthePersontoimg

      endif

      set note of thePerson to Personal_Note

      -- e-mails, phones, addresses and dates can be several per preson and have to be looped through

      repeatwiththeEmailinemailsofthePerson

      iflabelofcontentsoftheEmailis "Work" then

      set value of contents of theEmail to Personal_Work_email

      endif

      endrepeat

      repeatwiththePhoneinphonesofthePerson

      iflabelofcontentsofthePhoneis "Work" then

      set value of contents of thePhone to Personal_Work_phone

      endif

      iflabelofcontentsofthePhoneis "Mobile" then

      set value of contents of thePhone to Personal_Mobile_phone

      endif

      iflabelofcontentsofthePhoneis "Home" then

      set value of contents of thePhone to Personal_Home_phone

      endif

      if label of contents of thePhone is Personal_Anh1_namn then

      set value of contents of thePhone to Personal_Anh1_phone

      endif

      iflabelofcontentsofthePhoneis "Anhörig tel 2" then

      set value of contents of thePhone to Personal_Anh2_phone

      endif

       

      endrepeat

      repeatwiththeAddressinaddressesofthePerson

      iflabelofcontentsoftheAddressis "Work" then

      set properties of theAddress to {street:Personal_Address_street, city:Personal_Address_city, zip:Personal_Address_zip}

      endif

      endrepeat

      repeatwiththeCustomDateincustom datesofthePerson

      iflabelofcontentsoftheCustomDateis "Databas update" then

      setvalueofcontentsoftheCustomDatetoFM_update

      endif

      endrepeat

      endtell

      else

      -- else if ID can´t be found create a new

      set thePerson to makenewpersonwith properties {first name:Personal_firstname, last name:Personal_lastname, organization:Personal_department, company:false, note:Personal_Note}

      tell thePerson

      ifladdaimgis 1 then

      setimageofthePersontoimg

      endif

      makenewphoneat end of phoneswith properties {label:"Mobile", value:Personal_Mobile_phone}

      makenewphoneat end of phoneswith properties {label:"Work", value:Personal_Work_phone}

      makenewphoneat end of phoneswith properties {label:"Home", value:Personal_Home_phone}

      makenewphoneat end of phoneswith properties {label:Personal_Anh1_namn, value:Personal_Anh1_phone}

      makenewphoneatendofphoneswith properties {label:"Anhörig tel 2", value:Personal_Anh2_phone}

      makenewemailat end of emailswith properties {label:"Work", value:Personal_Work_email}

      makenewcustom dateat end of custom dateswith properties {label:"Databas update", value:FM_update}

      makenewaddressat end of addresseswith properties {label:"Work", street:Personal_Address_street, city:Personal_Address_city, zip:Personal_Address_zip}

      endtell

      -- put the person in by FileMaker defined group

      addthePersontogroupAddress_Book_Group

      endif

       

      -- else if no entry have occured previously create a new contact with the FileMaker data

      else

      set thePerson to makenewpersonwith properties {first name:Personal_firstname, last name:Personal_lastname, organization:Personal_department, company:false, note:Personal_Note}

      tell thePerson

      makenewphoneat end of phoneswith properties {label:"Mobile", value:Personal_Mobile_phone}

      makenewphoneat end of phoneswith properties {label:"Work", value:Personal_Work_phone}

      makenewphoneat end of phoneswith properties {label:"Home", value:Personal_Home_phone}

      makenewphoneat end of phoneswith properties {label:Personal_Anh1_namn, value:Personal_Anh1_phone}

      makenewphoneatendofphoneswith properties {label:"Anhörig tel 2", value:Personal_Anh2_phone}

      makenewemailat end of emailswith properties {label:"Work", value:Personal_Work_email}

      makenewcustom dateat end of custom dateswith properties {label:"Databas update", value:FM_update}

      makenewaddressat end of addresseswith properties {label:"Work", street:Personal_Address_street, city:Personal_Address_city, zip:Personal_Address_zip}

      ifladdaimgis 1 then

      setimageofthePersontoimg

      endif

      endtell

      -- put the person in by FileMaker defined group

      addthePersontogroupAddress_Book_Group

      endif

      -- collect data from entry to report back to FileMaker

      set Vilket_Address_Book_ID to id of thePerson

      set theModificationdate to modification date of thePerson as text

      set theCreationdate to creation date of thePerson as text

      save

      endtell

       

       

      ------------------------------------------------------------------------------------------------------------------------

       

       

      --If open for access have been used - close the file

      ifladdaimgis 1 then

      close accessimgfd

      endif

       

       

      ------------------------------------------------------------------------------------------------------------------------

       

       

      -- report back to the current record for error catching and statistics

      tellapplication "FileMaker Pro Advanced"

      tell current record

      setcell "Address Book ID" toVilket_Address_Book_ID

      setcell "Address Book Creation_date" totheCreationdate

      setcell "Address Book Modification_date" totheModificationdate

      endtell

      endtell


       
       

      error_view.png

        • 1. Re: File Maker finds faults in an Applescript that both compiles and runs perfectly in Applescript...
          CamillaHarrysson

          Hi, forgot to inform you about what FM version I have: FM Pro advanced 11 on Mac with Lion 10.7.2

          And to clearify - What I tried to do was copying the applescript code into the script step perform a nativ Applescript and FM seemed to think it to be it´s job to compile the applescript code differently then the Applescript editor.

          Very greatful for help:)

          • 2. Re: File Maker finds faults in an Applescript that both compiles and runs perfectly in Applescript...
            steveharley

            i noticed your query while looking for something else; in case you are still wondering ...

            when FileMaker runs AppleScript code, it is as if there is a tell application "Filemaker Pro Advanced" block around all of your code, so it does have to compile the code to take that context into consideration; if you put such a block around the whole script in Script Editor and you should get the same error (this is a helpful technique when developing scripts that you'll use in a Perform AppleScript step)

            the specific problem here is that the "read" keyword is in FileMaker's AppleScript dictionary, where it has a different syntax (and completely different meaning) from the general usage; beware of this because there are many keywords that mean something different to FileMaker, and often they won't give you a syntax error, they'll only cause trouble when the script runs

            so to make sure keywords like "read" are understood in the context you intend, do this:

             

            using terms from application "Finder"

                set imgfd to open for access imgfile

                setimg to read imgfd as "TIFF"

            end using terms from

             

            note that "Finder" is just a convenience, since it is an application that is always running; the keyword in question is really part of Standard Additions; there could be several places in the script where you'll need to do this