Determine the source application of the current cardboard content

Several OSX clipboard managers from the AppStore show the ability to determine the source application of the content that was copied to the clipboard.

I am writing some simple clipboard watcher and would like to show the icon of the source application next to the content stored in general in NSPasteboard. And I would like to know how this can be achieved.

As I understand it, NSPasteboard does not provide any additional information other than the data and data types themselves.

Perhaps there are any events or notifications to know that the copy command was called? Or some other ways?

+6
source share
2 answers

I believe that the way CopyLess and Alfred 2 (which also supports this) is that they have a timer that checks the clipboard for changes. When they see the changes in the clipboard, they receive the active application and associate this application with the change. This is probably not a reliable method, but should work in most cases.

+6
source

There is a new quasi-standard for this now (as of December 2016), see http://nspasteboard.org

It works as follows:

  • By default, a program that writes the contents of the clipboard should assume that the earliest application is the one that fills the clipboard (which admittedly only works if the program is already running when the clipboard content is installed).

  • But if there is a clipboard type (type) of type org.nspasteboard.source , then this taste content should be the identifier of the application package populating clipbard.

(This is a quasi-standard because it has been discussed and agreed upon by interested members of the mailing list managed by nspasteboard.org)

+2
source

Source: https://habr.com/ru/post/944071/


All Articles