Cocoa - Insert text from one app to another

Discussion in 'Mac Programming' started by monsieurpaul, Feb 28, 2011.

  1. monsieurpaul macrumors regular

    Joined:
    Oct 8, 2009
    #1
    Hello,

    I am trying to create an app that will insert text wherever the cursor is (mostly in another app). Right now I am using the pasteboard and a cmd-v keystroke event. It works, but I find it rather crude and it wipes out everything that could have been in the pasteboard.

    Is there another way to achieve this ?

    Thanks,

    Paul
     
  2. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #2
    Can you edit the code of the first app? In that case, you can change it to send out notifications of text changes. You then capture these with the second app.
     
  3. monsieurpaul thread starter macrumors regular

    Joined:
    Oct 8, 2009
    #3
    - Can notifications work between 2 apps ?

    - If I understand correctly, I would need to add code in the receiver app also to react to the notification. Unless there are some kind of universal notifications that all apps are supposed to listen ?
     
  4. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #4
    I think they do.

    Something like that. But, if I remember correctly, it is not guaranteed that you will receive all notifications in time, in order, or even at all.

    Why not have app1 write the data to disk and read that file from app2? Do you need it realtime?
     

Share This Page