Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Some additions...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Some additions...
Authored by: anandman on Mar 04, '03 10:38:15PM
Following your suggestions, I've come up with this script. For some reason, I can't overwrite the the temporary file so I had to insert the 'rm' command before trying to open it. This works well for me though.
property beginTag : "BEGIN:VCALENDAR"
property endTag : "END:VCALENDAR"

on perform_mail_action(info)
  tell application "Mail"
    set selectedMessages to |SelectedMessages| of info
    set theRule to |Rule| of info
    repeat with eachMessage in selectedMessages
      set theSubject to subject of eachMessage
      set theRuleName to name of theRule
      set theContent to content of eachMessage

      if (theContent contains beginTag) ¬
        and (theContent contains endTag) then
        -- extract vcalendar from message
        set theCal to ¬
          text from character (offset of beginTag in theContent) ¬
            to character ((offset of endTag in theContent) ¬
            + (length of endTag)) of theContent

        -- save vcalendar to file
        set theFileName to ¬
          (path to temporary items folder type string) ¬
            & "Mail2iCal.ics"
        set theFileNamePOSIX to POSIX path of theFileName
        try
          set theCommand to "rm -f '" & theFileNamePOSIX & "'"
          do shell script theCommand
        on error
          display dialog "ERROR: Can't delete file " & theFileNamePOSIX
        end try
        try
          set theFile to (open for access theFileName with write permission)
        on error
          display dialog "ERROR: Can't open file " & theFileName
          try
            close access theFileName -- use the file name rather than the ref
          end try
        end try
        try
          set eof of theFile to 0
          write theCal as string to theFile starting at eof
          close access theFile
        on error
          display dialog "ERROR: Can't write or close file " & theFileName
          try
            close access theFile
          end try
        end try

        -- open vCalendar file with iCal
        set theCommand to "open -a '/Applications/iCal.app' '" & theFileNamePOSIX & "'"
        do shell script theCommand
      end if
    end repeat
  end tell
end perform_mail_action
-anand

[ Reply to This | # ]
Some additions...
Authored by: anandman on Mar 04, '03 10:44:41PM
Oops. I forgot to change one thing. For some reason, Script Editor's check syntax changes and "as" to "type" and lets me compile it and save it the first time but when you try to check syntax or save it again it fails. Anyone know why?

Anyway, just change the following line:

  (path to temporary items folder type string)
to
  (path to temporary items folder as string)

-anand

[ Reply to This | # ]