Re: Event to trigger writeSelectionToPasteboard

2011-01-06 Thread Gary L. Wade
Have you thought of changing your mouse's System Preferences settings to
execute a script that does what you want?  It appears you should be able
to use the side-buttons on a Mighty Mouse to do what you want.  Otherwise,
I'd contact the manufacturer of your three-button mouse and let them know
of your need.  Trying to do this in the manner you're describing sounds
rife with headaches.

On 01/06/2011 9:00 AM, "Peter Watkins"  wrote:

>Hi Graham,
>
>On Tue, Jan 4, 2011 at 2:43 PM, Graham Cox  wrote:
>
>>
>> On 05/01/2011, at 3:04 AM, Peter Watkins wrote:
>>
>> This is what I'm really trying to achieve, "I'm writing an app that lets
>> the user select text in one program and paste it into another by
>> middle-clicking the mouse button."
>>
>>
>>
>> But why?
>>
> A couple reasons:
>1) It's actually faster than Cmd-C, Cmd-V: You can do the entire
>copy-paste
>without using the keyboard.
>2) Most UNIX users are used to copying and pasting this way (using the
>selection buffer). The copy-paste buffer still exists on UNIX, but most
>users don't use it.
>
>There is a perfectly reasonable standard way to cut and paste in a way
>that
>> works in virtually all apps that users are well used to. This is
>> non-standard, non-intuitive and difficult to implement 'solution' to a
>> problem that doesn't appear to exist. That's why it's hard to implement,
>> because it's not (on the face of it) very sensible.
>>
>This is correct for almost every Mac user. However there's a small segment
>of Mac users that come from a Linux/Sun/BSD background, and they really
>like
>the middle-click paste. They like it so much, in fact, that I've heard of
>some users switching to a Mac and then switching back to *NIX because the
>Mac doesn't have middle-click paste.
>
>
>> Also, not all mouses (mice?) have a middle button. The standard current
>> Apple Wireless Mouse for example, does not.
>>
>True, and it drives me up the wall. I got an Apple Magic Mouse and used it
>for awhile, but I switched back to my old Mighty Mouse because the Magic
>Mouse doesn't have a middle-click. I use the middle-click paste all the
>time
>when I log into work (my company's software only runs on *NIX) from my
>Mac.
>
>So, I still think a separate program that provides a selection buffer with
>middle-click paste is just the thing for *NIX users switching to a Mac.
>
>-Peter
>___
>
>Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
>Please do not post admin requests or moderator comments to the list.
>Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
>Help/Unsubscribe/Update your Subscription:
>http://lists.apple.com/mailman/options/cocoa-dev/garywade%40desisoftsystem
>s.com
>
>This email sent to garyw...@desisoftsystems.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Event to trigger writeSelectionToPasteboard

2011-01-06 Thread Peter Watkins
Hi Graham,

On Tue, Jan 4, 2011 at 2:43 PM, Graham Cox  wrote:

>
> On 05/01/2011, at 3:04 AM, Peter Watkins wrote:
>
> This is what I'm really trying to achieve, "I'm writing an app that lets
> the user select text in one program and paste it into another by
> middle-clicking the mouse button."
>
>
>
> But why?
>
 A couple reasons:
1) It's actually faster than Cmd-C, Cmd-V: You can do the entire copy-paste
without using the keyboard.
2) Most UNIX users are used to copying and pasting this way (using the
selection buffer). The copy-paste buffer still exists on UNIX, but most
users don't use it.

There is a perfectly reasonable standard way to cut and paste in a way that
> works in virtually all apps that users are well used to. This is
> non-standard, non-intuitive and difficult to implement 'solution' to a
> problem that doesn't appear to exist. That's why it's hard to implement,
> because it's not (on the face of it) very sensible.
>
This is correct for almost every Mac user. However there's a small segment
of Mac users that come from a Linux/Sun/BSD background, and they really like
the middle-click paste. They like it so much, in fact, that I've heard of
some users switching to a Mac and then switching back to *NIX because the
Mac doesn't have middle-click paste.


> Also, not all mouses (mice?) have a middle button. The standard current
> Apple Wireless Mouse for example, does not.
>
True, and it drives me up the wall. I got an Apple Magic Mouse and used it
for awhile, but I switched back to my old Mighty Mouse because the Magic
Mouse doesn't have a middle-click. I use the middle-click paste all the time
when I log into work (my company's software only runs on *NIX) from my Mac.

So, I still think a separate program that provides a selection buffer with
middle-click paste is just the thing for *NIX users switching to a Mac.

-Peter
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Event to trigger writeSelectionToPasteboard

2011-01-04 Thread Graham Cox

On 05/01/2011, at 3:04 AM, Peter Watkins wrote:

> This is what I'm really trying to achieve, "I'm writing an app that lets the 
> user select text in one program and paste it into another by middle-clicking 
> the mouse button."


But why? There is a perfectly reasonable standard way to cut and paste in a way 
that works in virtually all apps that users are well used to. This is 
non-standard, non-intuitive and difficult to implement 'solution' to a problem 
that doesn't appear to exist. That's why it's hard to implement, because it's 
not (on the face of it) very sensible.

Also, not all mouses (mice?) have a middle button. The standard current Apple 
Wireless Mouse for example, does not.

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Event to trigger writeSelectionToPasteboard

2011-01-04 Thread Peter Watkins
Hi Mark,

You used to be able to get around this stuff by using one of the
> plugins available (AppleScript Addition or Contextual Menu). But it
> seems with each new OS release, Apple has been isolating apps more and
> more. No plugins, no way to directly perform common actions like
> copy/paste or perform a service.
>
Being able to perform a service would be nice. I can see the reasoning
behind isolating apps. If my app can run in the background and collect text
from other apps, it stands to reason that I could send that text to some
remote server (unless the user has an outgoing-connection firewall). Now,
many apps, (Pages, etc.) allow access to their open documents through
AppleScript--so this wouldn't be an additional security risk for these apps.


The Accessibility way seems to be the best approach right now,
> although it's a much messier way to solve the problem as you are
> effectively mimicking mouse/keyboard selections.
>
As long as the user can't tell that the service is being run, I'm OK. The
reason is, I perform the service on every mouse drag and middle-click. If a
menu highlights each time, the user is going to get very annoyed.

You should also write up a bug/enhancement request for Apple. If
> enough folks keep requesting this type of functionality, perhaps
> they'll eventually add it.
>
Well, the proper fix is for Apple to support a separate selection buffer in
the OS itself. Then none of this would be necessary. They also wouldn't have
to compromise on security. However from a marketing perspective, I don't
really see this happening:
1) The majority of users switching to a Mac are switching from Windows (no
middle-click paste, there)
2) Two ways to copy-paste kinda goes against the Mac philosophy of one
simple way to do a task

Thanks,

Peter W
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Event to trigger writeSelectionToPasteboard

2011-01-04 Thread Peter Watkins
Hi Peter,

You can copy a selection using the Accessibility API:
> First get the UIElement for the application's "Copy" menu item.
> Then invoke "AXPress" on it.
> Drawback is that you will have to ask the user to enable Accessibility if
> it is not enabled.
>
> To get an idea about Accessibility, look at Apple's "Accessibility
> Inspector" app, which also contains a bunch of interesting code samples.
>

I'll take a look at the inspector.

Thanks,

Peter W
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Event to trigger writeSelectionToPasteboard

2011-01-04 Thread Peter Watkins
Hi Graham,


Read the Services Implementation Guide:
>
>
> http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/introduction.html
>
> The app needs to be written to be services aware, and implement the
> protocols specified in the guide. If not, you can't do what you're doing for
> any arbitrary app. Between the Cut or Copy menu command and data being put
> on the pasteboard, the app can do whatever it wants, there is no 'standard'
> method that gets called and the method names are arbitrary (even the action
> method that responds to the Copy command might not be called -copy:)
>
> There's no 'Copy' or 'Paste' event. Some apps might expose these through
> applescript - again, there's no guarantee.
>
Good to know.


>
> What are you really trying to achieve?
>
This is what I'm really trying to achieve, "I'm writing an app that lets the
user select text in one program and paste it into another by middle-clicking
the mouse button."

If you implement your service in a standard way, apps that are services
> aware will be able to use it. If not, they won't,  and you have to live with
> it. You can't force an app to become services aware if it wasn't written to
> be.
>
Hmm... Would this be a better method:
1) Store the contents of the global pasteboard in a temporary variable
2) Send the the Command and "c" CGEvents
3) Retrieve the new contents of the global pasteboard
4) Replace the contents of the global pasteboard with the temporary variable
in step #1

 Thanks,

Peter
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Event to trigger writeSelectionToPasteboard

2011-01-01 Thread Peter Lübke

You can copy a selection using the Accessibility API:
First get the UIElement for the application's "Copy" menu item.
Then invoke "AXPress" on it.
Drawback is that you will have to ask the user to enable  
Accessibility if it is not enabled.


To get an idea about Accessibility, look at Apple's "Accessibility  
Inspector" app, which also contains a bunch of interesting code samples.


Peter


Am 01.01.2011 um 10:32 schrieb Graham Cox:



On 01/01/2011, at 6:43 AM, Peter Watkins wrote:

I know that each Cocoa app implements writeSelectionToPasteboard 
(), and I'm
guessing this is how services interact with running apps. Each  
service is a
separate short-running process. Sothere must be some sort of IPC  
to get the
selection from the running app into the service's pasteboard. If I  
can
figure out what that IPC is, I can send a message to a running  
application,

and this would avoid flashing the menu bar.

Any ideas on getting another app to run its  
writeSelectionToPasteboard()

method?



Read the Services Implementation Guide:

http://developer.apple.com/library/mac/#documentation/Cocoa/ 
Conceptual/SysServices/introduction.html


The app needs to be written to be services aware, and implement the  
protocols specified in the guide. If not, you can't do what you're  
doing for any arbitrary app. Between the Cut or Copy menu command  
and data being put on the pasteboard, the app can do whatever it  
wants, there is no 'standard' method that gets called and the  
method names are arbitrary (even the action method that responds to  
the Copy command might not be called -copy:)


There's no 'Copy' or 'Paste' event. Some apps might expose these  
through applescript - again, there's no guarantee.


What are you really trying to achieve? If you implement your  
service in a standard way, apps that are services aware will be  
able to use it. If not, they won't,  and you have to live with it.  
You can't force an app to become services aware if it wasn't  
written to be.


--Graham




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Event to trigger writeSelectionToPasteboard

2011-01-01 Thread Graham Cox

On 01/01/2011, at 6:43 AM, Peter Watkins wrote:

> I know that each Cocoa app implements writeSelectionToPasteboard(), and I'm
> guessing this is how services interact with running apps. Each service is a
> separate short-running process. Sothere must be some sort of IPC to get the
> selection from the running app into the service's pasteboard. If I can
> figure out what that IPC is, I can send a message to a running application,
> and this would avoid flashing the menu bar.
> 
> Any ideas on getting another app to run its writeSelectionToPasteboard()
> method?


Read the Services Implementation Guide:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/introduction.html

The app needs to be written to be services aware, and implement the protocols 
specified in the guide. If not, you can't do what you're doing for any 
arbitrary app. Between the Cut or Copy menu command and data being put on the 
pasteboard, the app can do whatever it wants, there is no 'standard' method 
that gets called and the method names are arbitrary (even the action method 
that responds to the Copy command might not be called -copy:)

There's no 'Copy' or 'Paste' event. Some apps might expose these through 
applescript - again, there's no guarantee.

What are you really trying to achieve? If you implement your service in a 
standard way, apps that are services aware will be able to use it. If not, they 
won't,  and you have to live with it. You can't force an app to become services 
aware if it wasn't written to be.

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Event to trigger writeSelectionToPasteboard

2011-01-01 Thread Peter Watkins
I'm writing an app that lets the user select text in one program and paste
it into another by middle-clicking the mouse button. This roughly emulates
the X11 selection buffer.

The first version I wrote used event taps to detect when the user dragged a
selection (doesn't work for a double-click select or shift-arrow select). It
then compiled and ran an apple script to "get the contents of the selection"
in the frontmost app. When the user middle-clicked, the app would retype
(using CGEvents) everything it got from the apple script.

This worked OK except:
1) Only a few apps support "get the contents of the selection"
2) It's slow to send events for every keystroke (and undo-buffers get
confused)

The next version called two services I made, "Copy Selection" and "Paste
Selection". This works with all Cocoa apps (fixes #1), is fast (fixes #2),
but I haven't found a way to programmatically invoke a service (in another
app). The best I could come up with was setting command-key equivalents for
the services and sending those command-keys through UI scripting. The nasty
side effect of this is that every time you drag a selection, the app's app
menu gets selected. This is unacceptable-I don't want my menu bar flashing
each time I drag the mouse.

I know that each Cocoa app implements writeSelectionToPasteboard(), and I'm
guessing this is how services interact with running apps. Each service is a
separate short-running process. Sothere must be some sort of IPC to get the
selection from the running app into the service's pasteboard. If I can
figure out what that IPC is, I can send a message to a running application,
and this would avoid flashing the menu bar.

Any ideas on getting another app to run its writeSelectionToPasteboard()
method?

Thanks,

Peter
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com