Hello,
i’ve a bit trouble with this script snipped here:
--Copies contents of selection
tell application "System Events" to keystroke "c" using command down
in fact, this command isn’t able to put the actual selection (of a text-string) into the clipboard. I got instead the last - not the actual entry of the clipboard- in order to get the actual selection into the board, you have to activate this snippet again.
…because the UI -scripting is for me the last solution which i integrate into a script, (they are soo a rough commands, without elegance)
--Copies contents of selection
tell application "TextEdit" to activate
tell application "System Events" to tell process "TextEdit" to keystroke "c" using {command down}
Tom
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)
Thanks Tom_X,
but in my case i can’t know which application to call. My script -snippet should be useful in every circumstances, like for use with text editors , preview -apps and browsers…
Perhaps i must call (activate) first the front application, and then execute my snipped…
not to give you contra, but this snippet runs in the first paragraph of a longer script, which i activate via keystroke -trigger.(i need not an application)
The option to catch selected text directly with the UI -scripting system is only a “bridge” to shorten obvious passages.
i cannot understand why these snipped will request a repeat- loop. What prevents the snippet, to not catch data already the first time??
Stefan,
it sounds strange for me to activate the frontmost application, if this one is already in front of! here we go.
Let’s assume that we:
.have selected an text-string in a open web-site of “Safari”
.activate my UI-script (snippet) from the script -menu (in the right corner of our main toolbar)
what happens in the second instance? Which application will answer
i) “System events”
ii) “Safari”
on call ?
i’ve added too:
--Copy contents of selection
repeat 3 times
tell application "System Events" to keystroke "c" using command down
end repeat
because 2 times returns are not enough to get the right output.
What is going on with this snippet ?