Dexxterr
Dexxterr

Reputation: 61

How do I listen to a specific text string on Mac OS X in a livecode application

I want to create a Mac app similar to Textexpander or Atext. Both these applications allow the user to define snippets along with their respective trigger words. Typing the trigger words in any app, replaces that trigger word with the actual snippet defined.

I presume that the app listens to all strings being typed in any app and when it detects a string matching one of the trigger words defined, it replaces it with the snippet.

Is that how it actually works, or is there some other way?

Upvotes: 0

Views: 69

Answers (1)

dunbarx
dunbarx

Reputation: 756

Make two fields. In field 2 put something like:

  time xyz
  come ABC

In the script of field 1:

 on textChanged
  if the last char of me = space then
   put the last word of me into temp
   if temp is in fld 2 then
     repeat for each word tWord in fld 2
        put  the last word of line lineOffset(temp,fld 2) of fld 2 into the last word of me
        exit repeat
     end repeat
   end if
  select after text of me
  end if
end textChanged

Now type into fld 1, you know, "Now is the time for all good men to come to the aid of their country". This can be better done with an array, but the concept may be more accessible here.

This is a better handler, since it will not react to the trigger word:

  on textChanged
   if the last char of me = space then
   put the last word of me into stringOfInterest
   put fld 2 into dataToSearch
   if stringOfInterest is in dataToSearch then
     repeat for each line tLine in dataToSearch
        if word 1 of tLine = stringOfInterest then
           put word 2 of tLine into the last word of me
           exit repeat
        end if
     end repeat
   end if
  select after text of me
 end if
end textChanged

Upvotes: 0

Related Questions