How to get the word under the mouse pointer?

  • Hi all,
    I'd like to do something like "Look up in Dictionary" (crtl + cmd + D by
    default), which will display a dictionary panel according to the word under
    the mouse.
    Does anyone know how to do it?
    Any idea will be very appreciated!
    Thanks.
    Best Regards,
    James Chen
    Presentation Product Division
    TEL: +886 2 22263630 ext 8538
    FAX: +886 2 22267241
    Mailto: <Jam.Chen...>
    http://www.avermedia.com
    AVerMedia Technologies, Inc.

    ²³ø²£«~¨Æ·~³æ¦ì: ³¯»Ê±]
    ¶ê­è¬ì§Þ(ªÑ)¤½¥q
    This message contains information that may be confidential and privileged.
    Unless you are the addressee (or authorized to receive messages for the
    addressee), you cannot use, copy or disclose to any third party or any
    information contained in the message. If you have received the message in
    error, please advise the sender by reply e-mail and delete the message.
    Nothing in this message should be interpreted as a digital or electronic
    signature that can be used to authenticate a contract or to other legal
    document. Thank you very much.
  • On 7 dec 2007, at 03.16, James Chen wrote:

    > Hi all,
    > I'd like to do something like "Look up in Dictionary" (crtl + cmd +
    > D by
    > default), which will display a dictionary panel according to the
    > word under
    > the mouse.
    > Does anyone know how to do it?
    > Any idea will be very appreciated!
    > Thanks.
    > Best Regards,
    > James Chen
    > Presentation Product Division
    > TEL: +886 2 22263630 ext 8538
    > FAX: +886 2 22267241
    > Mailto: <Jam.Chen...>
    > http://www.avermedia.com
    > AVerMedia Technologies, Inc.
    Call the following NSTextView method:
    characterIndexForInsertionAtPoint:
    Then scan scan backwards and forwards in the text for word boundaries.
    -------------------------------------
    This sig is dedicated to the advancement of Nuclear Power
    Tommy Nordgren
    <tommy.nordgren...>
  • Hello,
    Thanks but what if the front most application is not mine.

    Sorry that I didn't describe my question well.
    I'd like to write a faceless application that provides a service similar to
    "Look up in Dictionary" which is invoked by global hot key and is related to
    the text/word under mouse pointer. So I don't think I'm able to get the
    NSTextView instance of active app.

    Best Regards,
    James Chen
    Presentation Product Division
    TEL: +886 2 22263630 ext 8538
    FAX: +886 2 22267241
    Mailto: <Jam.Chen...>
    http://www.avermedia.com
    AVerMedia Technologies, Inc.

    ²³ø²£«~¨Æ·~³æ¦ì: ³¯»Ê±]
    ¶ê­è¬ì§Þ(ªÑ)¤½¥q
    This message contains information that may be confidential and privileged.
    Unless you are the addressee (or authorized to receive messages for the
    addressee), you cannot use, copy or disclose to any third party or any
    information contained in the message. If you have received the message in
    error, please advise the sender by reply e-mail and delete the message.
    Nothing in this message should be interpreted as a digital or electronic
    signature that can be used to authenticate a contract or to other legal
    document. Thank you very much.

    > From: Tommy Nordgren <tommy.nordgren...>
    > Date: Fri, 7 Dec 2007 04:14:49 +0100
    > To: James Chen <jam.chen...>
    > Cc: Cocoa <cocoa-dev...>
    > Subject: Re: How to get the word under the mouse pointer?
    >
    >
    > On 7 dec 2007, at 03.16, James Chen wrote:
    >
    >> Hi all,
    >> I'd like to do something like "Look up in Dictionary" (crtl + cmd +
    >> D by
    >> default), which will display a dictionary panel according to the
    >> word under
    >> the mouse.
    >> Does anyone know how to do it?
    >> Any idea will be very appreciated!
    >> Thanks.
    >> Best Regards,
    >> James Chen
    >> Presentation Product Division
    >> TEL: +886 2 22263630 ext 8538
    >> FAX: +886 2 22267241
    >> Mailto: <Jam.Chen...>
    >> http://www.avermedia.com
    >> AVerMedia Technologies, Inc.
    > Call the following NSTextView method:
    > characterIndexForInsertionAtPoint:
    > Then scan scan backwards and forwards in the text for word boundaries.
    > -------------------------------------
    > This sig is dedicated to the advancement of Nuclear Power
    > Tommy Nordgren
    > <tommy.nordgren...>
    >
    >
    >
  • I think you can do things like this with a Service (not a faceless app).

    James Chen wrote:
    > Hello,
    > Thanks but what if the front most application is not mine.
    >
    > Sorry that I didn't describe my question well.
    > I'd like to write a faceless application that provides a service similar to
    > "Look up in Dictionary" which is invoked by global hot key and is related to
    > the text/word under mouse pointer. So I don't think I'm able to get the
    > NSTextView instance of active app.
    >
    >
    > Best Regards,
    > James Chen
    > Presentation Product Division
    > TEL: +886 2 22263630 ext 8538
    > FAX: +886 2 22267241
    > Mailto: <Jam.Chen...>
    > http://www.avermedia.com
    > AVerMedia Technologies, Inc.
    >
    > 簡報產�事業單�: 陳銘崧
    > 圓剛科技(股)公�
    > This message contains information that may be confidential and privileged.
    > Unless you are the addressee (or authorized to receive messages for the
    > addressee), you cannot use, copy or disclose to any third party or any
    > information contained in the message. If you have received the message in
    > error, please advise the sender by reply e-mail and delete the message.
    > Nothing in this message should be interpreted as a digital or electronic
    > signature that can be used to authenticate a contract or to other legal
    > document. Thank you very much.
    >
    >
    >
    >> From: Tommy Nordgren <tommy.nordgren...>
    >> Date: Fri, 7 Dec 2007 04:14:49 +0100
    >> To: James Chen <jam.chen...>
    >> Cc: Cocoa <cocoa-dev...>
    >> Subject: Re: How to get the word under the mouse pointer?
    >>
    >>
    >> On 7 dec 2007, at 03.16, James Chen wrote:
    >>
    >>
    >>> Hi all,
    >>> I'd like to do something like "Look up in Dictionary" (crtl + cmd +
    >>> D by
    >>> default), which will display a dictionary panel according to the
    >>> word under
    >>> the mouse.
    >>> Does anyone know how to do it?
    >>> Any idea will be very appreciated!
    >>> Thanks.
    >>> Best Regards,
    >>> James Chen
    >>> Presentation Product Division
    >>> TEL: +886 2 22263630 ext 8538
    >>> FAX: +886 2 22267241
    >>> Mailto: <Jam.Chen...>
    >>> http://www.avermedia.com
    >>> AVerMedia Technologies, Inc.
    >>>
    >> Call the following NSTextView method:
    >> characterIndexForInsertionAtPoint:
    >> Then scan scan backwards and forwards in the text for word boundaries.
    >> -------------------------------------
    >> This sig is dedicated to the advancement of Nuclear Power
    >> Tommy Nordgren
    >> <tommy.nordgren...>
    >>
    >>
    >>
    >>

    >
  • On 7 dec 2007, at 04.32, James Chen wrote:

    > Hello,
    > Thanks but what if the front most application is not mine.
    >
    > Sorry that I didn't describe my question well.
    > I'd like to write a faceless application that provides a service
    > similar to
    > "Look up in Dictionary" which is invoked by global hot key and is
    > related to
    > the text/word under mouse pointer. So I don't think I'm able to get
    > the
    > NSTextView instance of active app.
    >
    >
    Then you need to create a Cocoa Service that operates on currently
    selected text.
    For info on writing a Cocoa Service, see Anguish - Buck - Yachtman :
    Cocoa Programming
    (Look out for API changes - the book was completed at about the time
    when Jaguar was new.)
    Writing a Cocoa Service allows the user to use your tool by just
    selecting the word,
    and choosing a submenu item of the Services menu.
    > Best Regards,
    > James Chen
    > Presentation Product Division
    > TEL: +886 2 22263630 ext 8538
    > FAX: +886 2 22267241
    > Mailto: <Jam.Chen...>
    > http://www.avermedia.com
    > AVerMedia Technologies, Inc.
    >
    > ²³ø²£«~¨Æ·~³æ¦ì: ³¯»Ê±]
    > ¶ê­è¬ì§Þ(ªÑ)¤½¥q
    > This message contains information that may be confidential and
    > privileged.
    > Unless you are the addressee (or authorized to receive messages for
    > the
    > addressee), you cannot use, copy or disclose to any third party or any
    > information contained in the message. If you have received the
    > message in
    > error, please advise the sender by reply e-mail and delete the
    > message.
    > Nothing in this message should be interpreted as a digital or
    > electronic
    > signature that can be used to authenticate a contract or to other
    > legal
    > document. Thank you very much.
    >
    >
    >> From: Tommy Nordgren <tommy.nordgren...>
    >> Date: Fri, 7 Dec 2007 04:14:49 +0100
    >> To: James Chen <jam.chen...>
    >> Cc: Cocoa <cocoa-dev...>
    >> Subject: Re: How to get the word under the mouse pointer?
    >>
    >>
    >> On 7 dec 2007, at 03.16, James Chen wrote:
    >>
    >>> Hi all,
    >>> I'd like to do something like "Look up in Dictionary" (crtl + cmd +
    >>> D by
    >>> default), which will display a dictionary panel according to the
    >>> word under
    >>> the mouse.
    >>> Does anyone know how to do it?
    >>> Any idea will be very appreciated!
    >>> Thanks.
    >>> Best Regards,
    >>> James Chen
    >>> Presentation Product Division
    >>> TEL: +886 2 22263630 ext 8538
    >>> FAX: +886 2 22267241
    >>> Mailto: <Jam.Chen...>
    >>> http://www.avermedia.com
    >>> AVerMedia Technologies, Inc.
    >> Call the following NSTextView method:
    >> characterIndexForInsertionAtPoint:
    >> Then scan scan backwards and forwards in the text for word
    >> boundaries.
    >> -------------------------------------
    >> This sig is dedicated to the advancement of Nuclear Power
    >> Tommy Nordgren
    >> <tommy.nordgren...>
    >>
    >>
    >>
    >

    -------------------------------------
    This sig is dedicated to the advancement of Nuclear Power
    Tommy Nordgren
    <tommy.nordgren...>
  • Hello, James.

    I don't actually know how the "Look up in Dictionary" works, but you
    couldn't get it using a Cocoa Service. As far as I can tell, Services
    operate on the selection and work via a pasteboard; they are disabled
    (greyed out) if there is no selection.

    My guess is that you could use Carbon calls to define a global hot
    key to start your faceless app, then, perhaps also using Carbon, find
    out where the mouse pointer is.  (Unfortunately, I don't know enough
    Carbon to give you an answer to that off the top of my head.) That
    would be a start.  And that's probably the easy part.  As for getting
    the word under the mouse pointer of whatever app is frontmost...
    you'd have to ask an expert or read lots of documentation.

    Having said that, though, a Service would be able to get *selected*
    text and that may be adequate in your case.

    Ron

    On 07/12/2007, at 2:32 PM, James Chen wrote:

    > Hello,
    > Thanks but what if the front most application is not mine.
    >
    > Sorry that I didn't describe my question well.
    > I'd like to write a faceless application that provides a service
    > similar to
    > "Look up in Dictionary" which is invoked by global hot key and is
    > related to
    > the text/word under mouse pointer. So I don't think I'm able to get
    > the
    > NSTextView instance of active app.
    >
    >
    > Best Regards,
    > James Chen

    >> From: Tommy Nordgren <tommy.nordgren...>
    >> Date: Fri, 7 Dec 2007 04:14:49 +0100
    >> To: James Chen <jam.chen...>
    >> Cc: Cocoa <cocoa-dev...>
    >> Subject: Re: How to get the word under the mouse pointer?
    >>
    >>
    >> On 7 dec 2007, at 03.16, James Chen wrote:
    >>
    >>> Hi all,
    >>> I'd like to do something like "Look up in Dictionary" (crtl + cmd +
    >>> D by
    >>> default), which will display a dictionary panel according to the
    >>> word under
    >>> the mouse.
    >>> Does anyone know how to do it?
    >>> Any idea will be very appreciated!
    >>> Thanks.
    >>> Best Regards,
    >>> James Chen
    >>> Presentation Product Division
    >>> TEL: +886 2 22263630 ext 8538
    >>> FAX: +886 2 22267241
    >>> Mailto: <Jam.Chen...>
    >>> http://www.avermedia.com
    >>> AVerMedia Technologies, Inc.
    >> Call the following NSTextView method:
    >> characterIndexForInsertionAtPoint:
    >> Then scan scan backwards and forwards in the text for word
    >> boundaries.
    >> -------------------------------------
    >> This sig is dedicated to the advancement of Nuclear Power
    >> Tommy Nordgren
    >> <tommy.nordgren...>
    >>
    >>
    >>

  • on 2007-12-07 2:31 AM, Ron Fleckner at <ronfleckner...> wrote:

    > My guess is that you could use Carbon calls to define a global hot
    > key to start your faceless app, then, perhaps also using Carbon, find
    > out where the mouse pointer is.

    Carrying this to the next step: You could then use the Accessibility API to
    obtain the word under the mouse pointer.

    Unfortunately, in Leopard Apple has removed the only document that ever
    existed that explains how to use the Accessibility API in an "assistive"
    application like this. If you still have Tiger, look for the "Preliminary
    Release Note" on using the Accessibility API to write assistive
    applications.

    Otherwise, look for the header files prefixed with "AX" in the HIServices
    subframework of the ApplicationServices framework. Also, Apple's
    UIElementInspector (Accessibility Inspector) sample code shows how to use
    it.

    --

    Bill Cheeseman - <bill...>
    Quechee Software, Quechee, Vermont, USA
    www.quecheesoftware.com

    PreFab Software - www.prefabsoftware.com
  • Dear Bill,
    Thanks a lot!
    I think that's the approach and I'll try it.

    And thanks all of you who ever contributed the idea, thanks.

    Best Regards,
    James Chen
    Presentation Product Division
    TEL: +886 2 22263630 ext 8538
    FAX: +886 2 22267241
    Mailto: <Jam.Chen...>
    http://www.avermedia.com
    AVerMedia Technologies, Inc.

    ²³ø²£«~¨Æ·~³æ¦ì: ³¯»Ê±]
    ¶ê­è¬ì§Þ(ªÑ)¤½¥q
    This message contains information that may be confidential and privileged.
    Unless you are the addressee (or authorized to receive messages for the
    addressee), you cannot use, copy or disclose to any third party or any
    information contained in the message. If you have received the message in
    error, please advise the sender by reply e-mail and delete the message.
    Nothing in this message should be interpreted as a digital or electronic
    signature that can be used to authenticate a contract or to other legal
    document. Thank you very much.

    > From: Bill Cheeseman <bill...>
    > Date: Fri, 07 Dec 2007 06:04:36 -0500
    > To: Cocoa-Dev Mail <cocoa-dev...>
    > Conversation: How to get the word under the mouse pointer?
    > Subject: Re: How to get the word under the mouse pointer?
    >
    > on 2007-12-07 2:31 AM, Ron Fleckner at <ronfleckner...> wrote:
    >
    >> My guess is that you could use Carbon calls to define a global hot
    >> key to start your faceless app, then, perhaps also using Carbon, find
    >> out where the mouse pointer is.
    >
    > Carrying this to the next step: You could then use the Accessibility API to
    > obtain the word under the mouse pointer.
    >
    > Unfortunately, in Leopard Apple has removed the only document that ever
    > existed that explains how to use the Accessibility API in an "assistive"
    > application like this. If you still have Tiger, look for the "Preliminary
    > Release Note" on using the Accessibility API to write assistive
    > applications.
    >
    > Otherwise, look for the header files prefixed with "AX" in the HIServices
    > subframework of the ApplicationServices framework. Also, Apple's
    > UIElementInspector (Accessibility Inspector) sample code shows how to use
    > it.
    >
    > --
    >
    > Bill Cheeseman - <bill...>
    > Quechee Software, Quechee, Vermont, USA
    > www.quecheesoftware.com
    >
    > PreFab Software - www.prefabsoftware.com
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today