Copy action doesn't work well

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)

Joy, this works for me…

--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…

Hi Joy, If you are launching your script from the Dock or the Script menu, make it a background app and it will copy from the front application.

Tom

Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)

Hey, Tom

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??

Of course you have to. Keyboard shortcuts affect always the frontmost application

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 ?

From the System Events dictionary:

keystroke (verb)cause the target process to behave as if keystrokes were entered (from Processes Suite)

consider the target process:

tell application "System Events" to tell process "Safari" to keystroke "c" using command down