• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to get the text selection in an applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to get the text selection in an applescript


  • Subject: Re: how to get the text selection in an applescript
  • From: Michael Grant <email@hidden>
  • Date: Mon, 19 Jan 2004 10:13:01 -0600

On Jan 18, 2004, at 9:47 PM, leo wrote:

i want to write a little script which retrieves an url incorporating the
selected text. (dict.leo.org offers great english-german translation on url
basis.) so, how do i find out the selected text in the current application?

Big Cat will do the trick for apps that support contextual menus.
<http://ranchero.com/software/bigcat/>
Other than that, you can either check the individual application dictionary to see if it includes a selection object, use GUI scripting to send a Copy command, or just copy manually and have your script work on the clipboard text.

If you're interested in searching LEO, you may also be interested in EuroDicAutom. Here's a script I wrote for searching EuroDicAutom for German expressions via the contextual menu using Big Cat (watch the line breaks):

on main(s)
set the_URL to "http://europa.eu.int/eurodicautom/Controller? CURRENTSCREEN=EXPERT2&query=" & s & "&source=DE&target=EN&display_term=HITALL"
try
open location the_URL
on error
if the button returned of (display dialog ("Unable to open URL " & the_URL & return & return & "Copy to clipboard?") buttons {"Cancel", "Copy"} default button "Copy") is "Copy" then
set the clipboard to the_URL
end if
end try
end main

You should be able to adapt that to search LEO by editing the URL structure.


and furthermore: is there a way to modify the text in a selection? i'd like
to give back a "result" (the translated word) in the same selection.

Your best bet is probably going to be using the clipboard and pasting manually, unless you're only going to be using the script for particular apps that implement a selection object in their AS dictionaries.

Why hasn't someone come up with a way to run scripts from the Services menu in Cocoa apps?

Michael

--
As they say in the Brazilian state of Sergipe, no punishment is harsh enough for those who believe in the monkeys.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: 
 >how to get the text selection in an applescript (From: "leo" <email@hidden>)

  • Prev by Date: Re: Possible Bug: AppleScript Size Limit?
  • Next by Date: Re: Standard Additions 'read' command - basic questions
  • Previous by thread: Re: more details (was Re: how to get the text selection in an applescript)
  • Next by thread: How to get remote location out of choose application
  • Index(es):
    • Date
    • Thread