5 Replies Latest reply on Dec 31, 2009 6:19 AM by MSpsi

    Apple Script problem.

    MSpsi

      Title

      Apple Script problem.

      Post

      Hello

       

      I am having a problem with a Apple Script I wrote.  (Attached at end).  I am using it to send my scheduled appointments to iCal.  It works completely except iCal is not recognizing the time.  It places the appointment at 12am for the day.  ??  

       

      I suspect the problem is that the original iCal time stamp is parsed when it enters FM Pro.  Then I paste it back together to send it back to iCal.  I see two potential solutions:

       

      I find a way to get iCal to read time or (ironic for a calendar) 

       

      OR

       

      I get a timestamp to display in a portal (This is why I parsed the incoming time stamp from iCal, it would not display in a portal nor table view in a layout)

       

      Any suggestion?

       

      FM Pro: 10.0v1

      iCal: 4.0.1 (1374)

      MacBook OS X 10.6.2 2.26 Ghz Intel Core Duo with 2GB 1067 MHz DDR3 Ram

      User level: New

      Past experience with Databases

       

      Not currently shared or published but plan to do both when solution is complete 

       

      --set terms as defined in FM

      set theDescription to {}

      set theEventTitle to {}

      set theCalOld to {}

      set theCalNew to {}

      set theUID to {}

      set theStart to {}

      set theEnd to {}

      set theStamp to {}

      --Get FM Information

      tell application "FileMaker Pro"

      tell current record

      set theDescription to cellValue of cell "__Event ID"

      set theEventTitle to cellValue of cell "Event Type"

      set theUID to cellValue of cell "UID"

      set theCalOld to cellValue of cell "Therapist" & " " & "Open"

      set theCalNew to cellValue of cell "Therapist"

      set theStart to cellValue of cell "Event Day" & ", " & cellValue of the cell "Event Date" & " " & cellValue of cell "Event sTime"

      set theEnd to cellValue of cell "Event Day" & ", " & cellValue of the cell "Event Date" & " " & cellValue of the cell "Event eTime"

      end tell

      end tell

       

      set theStartDateAsText to theStart as text

      set theEndDateAsText to theEnd as text

       

      -- convert text to dates

      set theStart to date theStartDateAsText

      set theEnd to date theEndDateAsText

       

      --Connect to iCal and Delete old event (apparently you cannot change calendar from within event)

      tell application "iCal"

      tell calendar theCalOld

      delete (the first event whose uid = theUID)

      end tell

      --Make Event

      tell calendar theCalNew

      set theEvent to make new event at end of events

      tell theEvent

      set start date to theStart

      set description to theDescription

      set summary to theEventTitle

      set end date to theEnd

      end tell

      set theUID to uid of theEvent

      show theEvent

      end tell

      end tell

      --Send new UID to FM Event::UID for current record

      tell application "FileMaker Pro"

      tell current record

      set the field "UID" to theUID

      end tell

      end tell 

        • 1. Re: Apple Script problem.
          RickWhitelaw
             I can't offer any help directly. However, I suggest you post this on the Applescript Forum as well. There are undoubtedly many users of Applescript who are also FM users.
          • 2. Re: Apple Script problem.
            MSpsi
               App;e script forum???  I do not see it listed?
            • 3. Re: Apple Script problem.
              FentonJones
                

              http://www.macscripter.net

               

              Though you will not find a lot of people who are both FileMaker and AppleScript experts. I consider myself to be a FileMaker semi-expert (loosely interpreted :-), and intermediate AppleScript user. 

               

              I used to mess with this (iCal <-> FileMaker), but have not for a while. But from what I remember, you can pass a FileMaker Timestamp to AppleScript fine, without further coercion, but you cannot pass an AppleScript date to FileMaker without first coercing it to a FileMaker syntax timestamp. 

               

              (For those who have not tried to pass dates/timestamps between FileMaker & AppleScript, an AppleScript "date" is a timestamp, ie., it has both the data & time. It appears with the full day name, date & time, but is likely a number internally.) 

               

              AppleScript example of a subroutine to coerce an AppleScript date (timestamp) to FileMaker syntax, using the current date, but any AppleScript date would work:

               

               

              set FM_Today to my make_FM_date(current date)

               

              on make_FM_date(dateStamp)

              setyrtoyearofdateStamp

              setMntomonthofdateStampasnumber

              setDytodayofdateStamp

              setdateTxtto (Mn & "/" & Dy & "/" & yr) asstring

              set timeTxt to (time string of dateStamp)

              set dateTimeTxt to (dateTxt & " " & timeTxt)

              return dateTimeTxt

              end make_FM_date

               

               

               

              In your FileMaker file, you want to enter the Date & Time separately, for data entry. So I would create a calculation field to coerce your FileMaker Date & Time to a FileMaker Timestamp, via the Timestamp (Date; Time) function. Then use the above AppleScript subroutine in your AppleScript to get the iCal date back into FileMaker. 

              • 4. Re: Apple Script problem.
                RickWhitelaw
                  

                Sorry, I should have mentioned it's on the Apple support site under Mac OS X Technologies. However, Fenton could be correct in that there are few folks who use both Applescript and FM.

                 

                RW 

                • 5. Re: Apple Script problem.
                  MSpsi
                    

                  Thanks folks

                   

                  I will play with your suggestion this evening.  Thanks for the suggestions and the web reference.

                   

                  Marcus