monitor the clipboard?
-
Is there a good way to monitor the clipboard from a background
application? I'd just like to keep track of when the general
pasteboard is changed.
I've come up with a couple of ideas, which I don't really like.
1) have the app looping and constantly polling the clipboard to see if
its changed. This would consume CPU. Probably not a lot, but I'd like
as little as possible.
2) insert a global hotkey to intercept copy and paste and stick it on
the clipboard myself. This seems like I'd be asking for trouble.
Ideally, I'd like the equivalent of the Pasteboard pasting a
"NSPasteBoardDidChange" notification (or something like it) that I
could just monitor and react to. But I don't believe there's anything
actually like that.
I saw something in one of the archives about a carbon function to
intercept these things, but I didn't see a reference as to what it is.
There are apps that do this, so I know it's possible, but I don't know
the best approach.
Any suggestions?
-Jim.... -
Your looking for the functions RegisterEventHotKey and RegisterEventHotKey.
SD
______________________________________________________________________
Previous message from Jim Thomason on 12/11/04 at 3:00 PM -0600
**********************************************************************
> Is there a good way to monitor the clipboard from a background
> application? I'd just like to keep track of when the general
> pasteboard is changed.
>
> I've come up with a couple of ideas, which I don't really like.
>
> 1) have the app looping and constantly polling the clipboard to see if
> its changed. This would consume CPU. Probably not a lot, but I'd like
> as little as possible.
> 2) insert a global hotkey to intercept copy and paste and stick it on
> the clipboard myself. This seems like I'd be asking for trouble.
>
> Ideally, I'd like the equivalent of the Pasteboard pasting a
> "NSPasteBoardDidChange" notification (or something like it) that I
> could just monitor and react to. But I don't believe there's anything
> actually like that.
>
> I saw something in one of the archives about a carbon function to
> intercept these things, but I didn't see a reference as to what it is.
>
> There are apps that do this, so I know it's possible, but I don't know
> the best approach.
>
> Any suggestions?
>
> -Jim....
> _______________________________________________
> MacOSX-dev mailing list
> <MacOSX-dev...>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
-
On Sun, 12 Dec 2004 18:14:00 -0800, SD <appledevlists...> wrote:
> Your looking for the functions RegisterEventHotKey and RegisterEventHotKey.
>
> SD
I'm aware of the carbon functions for creating global hotkeys. I know
how to do that. I still don't think this is the best approach.
Besides, it breaks if the user chooses "copy" from the Edit menu
instead of hitting command-C.
That was just one of the suggestions I threw out for monitoring the
clipboard. All I want is for my background application to know what's
on the clipboard as it changes so I can keep track. I can do it by
constantly polling, but that seems really inefficient and I'm hoping
for suggestions for a better way.
-Jim.... -
Hi Jim,
I've been looking into this subject myself. After some research, the
only thing I could come up with was the message 'changeCount' you can
send to pasteboards. Indeed: polling. IIRC, I read somewhere that
there used to be a notification from the pasteboard you could use for
that, but that has been removed (performance impact?).
Anyway, I don't think that polling should be too much a problem. I
polled every .5 seconds. It was enough for my application and it
didn't have a noticeable impact on my (400MHz) system.
HTH,
Stefan
On Sat, 11 Dec 2004 15:00:43 -0600, Jim Thomason <thomasoniii...> wrote:
> Is there a good way to monitor the clipboard from a background
> application? I'd just like to keep track of when the general
> pasteboard is changed.
>
> I've come up with a couple of ideas, which I don't really like.
>
> 1) have the app looping and constantly polling the clipboard to see if
> its changed. This would consume CPU. Probably not a lot, but I'd like
> as little as possible.
> 2) insert a global hotkey to intercept copy and paste and stick it on
> the clipboard myself. This seems like I'd be asking for trouble.
>
> Ideally, I'd like the equivalent of the Pasteboard pasting a
> "NSPasteBoardDidChange" notification (or something like it) that I
> could just monitor and react to. But I don't believe there's anything
> actually like that.
>
> I saw something in one of the archives about a carbon function to
> intercept these things, but I didn't see a reference as to what it is.
>
> There are apps that do this, so I know it's possible, but I don't know
> the best approach.
>
> Any suggestions?
>
> -Jim....
> _______________________________________________
> MacOSX-dev mailing list
> <MacOSX-dev...>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
-
On 11 Dec 2004, at 13:00, Jim Thomason wrote:
> Ideally, I'd like the equivalent of the Pasteboard pasting a
> "NSPasteBoardDidChange" notification (or something like it) that I
> could just monitor and react to. But I don't believe there's anything
> actually like that.
I think someone already hinted at this:
On 22 Apr 2001, at 09:20, Chris Kane wrote:
> Functionality (private) like this used to exist. It turned out to be
> a bad idea for system/app performance.
>
> What happened was that eventually, essentially every app was
> interested in some aspect or other of the general pasteboard (and
> others to a lesser extent), so every time the user did a cmd-C, in
> addition to the normal work that goes on, the pasteboard server had to
> send every "observer" app for that pasteboard a message noting the
> change, and every app received it, woke up, swapped in a bunch of code
> and data to process the message, etc.
>
> Chris Kane
> Cocoa Frameworks, Apple, Inc.
David Dunham A Sharp <david...>
Voice/Fax: 206 783 7404 http://a-sharp.com
"People seem to misinterpret complexity as sophistication" -- Niklaus
Wirth



