Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

joppze

macrumors newbie
Original poster
Jun 30, 2010
3
0
Hello,

Im trying to write a applescript that will take arguments (in my case a string of words) and them print them out in the desired application as keystrokes.

Right now the code looks like this:

PHP:
on run searchbar
	set test to (item 1 of searchbar)
	tell application "System Events"
		tell application "myapp" to activate
		keystroke test
	end tell
end run

I don't know if this is the right way to code it, but I found this pretty much by searching on google. Anyhow, it doesn't work..

So my question is how I should do? I simply want the applescript to take one param that contains a string of words. Then print the entered string out in my app.

Thanks in advance!

/Joppze.
 
..

Hi,
plase check this thread (last post).

It works for me:
Code:
on doit(withThisText)
	tell application "TextEdit" to activate
	tell application "TextEdit" to make new document
	tell application "System Events" to keystroke withThisText
end doit

doit("Hello World!")

all best
Les
 
Hi,
plase check this thread <https://forums.macrumors.com/threads/602163/> (last post).

It works for me:
Code:
on doit(withThisText)
	tell application "TextEdit" to activate
	tell application "TextEdit" to make new document
	tell application "System Events" to keystroke withThisText
end doit

doit("Hello World!")

all best
Les

Thanks for the answer!

But it wasn't exactly what I was looking for.

PHP:
on run searchbar
	tell application "System Events"
		tell application "myapp" to activate
		key code 37 using command down
		keystroke searchbar
		delay (1)
		keystroke return
		keystroke tab
		delay (1)
		keystroke tab
		keystroke return
		key code 4 using command down
	end tell
end run

As you can see I want the script to take an argument and then print it out in the desired area using keystroke. But I cannot seem to get it to work..

Any idéas?
 
I'm sorry if I do not fully understand your request. From where your argument comes from? Commandline? Another script? User input?
 
I'm sorry if I do not fully understand your request. From where your argument comes from? Commandline? Another script? User input?

I wanna give the script an argument from the commandline and the output the given string (from the command line) with keystroke command (or output it on any other way) into my application.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.