I have a chat app that isn’t scriptable. I need to have the last line copyed and pasted in a different version of the same thing. is this possable. I was told that I might have to do it in OS 9. Can someone help me out. Thanks
Hi!
Most probably it is possible, but very difficult to say without knowing what are the related apps, your scripting experience, etc. Take a look here:
http://macscripter.net/faq/applications.php?id=P92
http://macscripter.net/faq/applications.php?id=P27
I have skimed over most of these things before but the thing that I dont know how to do is copy and paste the last line of text. I am new to appleScript but I have been programing for a while. I can figure the details out if I am pointed in the right direction.
Then, just visit the mentioned links and you’ll find tools to:
a) find the reference to the related text fields
b) lots of sample code to target them
there is one thing that seems really simple but I cant find it. I need to just type. I can open the app, paste things, all that but I need the equivalent of me typing in messages and then pushing return.
You’re going to have use GUI scripting (available by default in 10.3, a seperate download in 10.2). Make sureit’s enabled by going to System Preferences → Universal Access and clicking the checkbox toward the bottom labeled “Enable access for assistive devices” Now for an example, using TextEdit
tell application "TextEdit"
activate
tell application "System Events"
tell process "TextEdit"
keystroke "n" using command down
--This opens a new window in TextEdit
tell window 1
keystroke "whatever you type in the quotes will be typed in the app."
keystroke return
end tell
end tell
end tell
end tell
As you can see in the example, just use the “keystroke” command. Any characters which follow the command and are in quotes will be “typed”. If you need to use a modifier key use. “keystroke “whatever” using COMMAND down” where COMMAND is the name of one of the modifier keys (which are command, option, control, and shift.) Hope this helps.
Tyler,
You can use uiscripting to do these sorts of things, but it may be easier if you get iKey.
You can check it out here: iKey
It costs $US20
Thank you all for the help I have my thing almost working but while I am asking questions. the output of the app I am using looks like this.
…
user one blaa blaa (this is me)
user two blaa (this is them) I need to copy this line to the clipboard.
how do I call the second to last line. I have found some things on the lines by numbers but I dont know what line it is. is there a way to find out how many lines there are. or can I call the second to last line.
thank you
This might work.
set source_text to "user one blaa blaa (this is me)
user two blaa (this is them)
this is the last line"
set the clipboard to paragraph -2 of source_text
The negative index starts counting from the end, with the last item being -1, the second to last item being -2 and so on.
– Rob
keystroke left arrow key & left arrow key & left arrow key using command & shift down
keystroke "c" using command down
keystroke right arrow key using command & shift down
keystroke "v" using command down
I was thinking something like this but is isn’t working. Can I not do this. is there a better way.
thank you
This is difficult since I don’t have the app to test with. Here’s my last attempt, based on tests using TextEdit, OS X 10.2.8 and the beta release of System Events for Jaguar [d/l]. This also assumes that you have gone to the Universal Access pref pane to “Enable access for assistive devices”. It’s required for GUI scripting.
tell application "System Events"
keystroke "a" with command down
keystroke "c" with command down
set clip_ to my AsText(get the clipboard)
end tell
set temp_ to paragraph -2 of clip_
my sleep_()
set the clipboard to temp_
set arrow_ to ASCII character 31
set return_ to ASCII character 13
tell application "System Events"
keystroke arrow_
keystroke return_
keystroke "v" with command down
end tell
on sleep_()
do shell script "sleep 1"
end sleep_
on AsText(str)
try
return (text of ((str as string) as record)) as string
on error
return str
end try
end AsText
Good luck!
– Rob