Then, simply make sure that at the top of the window it says: When you create a Service in Automator, you create a new Workflow of the type Service. Or, it's possible you can use an OS X Service, which you also asked about. If it is not a scriptable app, then you'll have to use the last method, calling System Events. If you need more specific help, post your code and indicate what app you are working with. tell application "System Events" to keystroke "c" using You can also script "System Events" to simulate the keystroke of command-c in order to copy text. Tell application "Microsoft Word" to set selectedText to content of text object of selection Tell application "System Events" to tell application process "TextEdit" to tell attribute "AXSelectedText" of text area 1 of scroll area 1 of window 1 to set selectedText to its value See these examples: tell application "Safari" to set selectedText to (do JavaScript "(''+getSelection())" in document 1) Many apps don't have a 'text selection' object in their scriptable dictionary, so you have to do all kinds of workarounds. For very scriptable, text document based apps, there is much similarity, looking something like: tell app "xyz" to get selection of document 1 To get the selected text of the front window in an app, Applescript has to use the language/syntax that this app understands/responds to. For Applescript, it works with other applications.
0 Comments
Leave a Reply. |