How do I access Terminal's selected text using AppleScript?
I've read through Terminal.app's dictionary and h开发者_高级运维aven't seen a way to access just the selected text. Is this possible?
There doesn't seem to be a less hacky way to do this besides using GUI scripting and the clipboard.
tell application "Terminal" to activate
tell application "System Events"
tell process "Terminal"
tell menu bar 1
click menu item "Copy" of menu "Edit"
set _selection to the clipboard
end tell
end tell
end tell
The usual method is to use a "set myVariable to do shell script..." structure and then parse the answer out of myVariable which will be whatever stdout returned from the shell.
Brian you would run the script provided within a Service script. You would highlight the word, right click and select the service which in turn would tell terminal to copy the word and then make the word a variable which in this example script is being called _selection
精彩评论