0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Dexxterr
  • 59
  • 8
  • The current feature set of LiveCode doesn't let you do this. You'd need to have access to other apps. While in the past GUI scripting or OSA extensions would make this possible, the current level of security measures built into Mac OS X makes this more difficult. You'd need to write an app that hooks directly into eh the Mac OS X API to listen to anything that was written in any app and replace it if required. If you are willing to limit this functionality to your own LiveCode app, then it is possible and Dunbar gives an idea of how to get started. – Mark Feb 14 '20 at 13:28

1 Answers1

0

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
dunbarx
  • 756
  • 5
  • 4