hello, im trying to get my applescript to put the string “currentTrackText” into the top window of any application. how would i go about doing this? thanks alot, this site has been a great resource!
It isn’t possible to do what you describe because you can’t know in advance the capabilities of every application.
For example, what would you expect to happen if the frontmost application was the Finder? How do you propose putting ‘CurrentTrackText’ in a Finder window? or a Safari web page?
You need to more clearly define what it is you’re trying to achieve - the goal, not just the mechanics.
i want it to go into a text box on whatever the topmost window is when i launch it, like in an iChat conversation, maybe this text box in safari, mail
i dont know if im explaning this well.
As camelot said, there is no easy way to do this for “Any” application. The hitch is, that when you activate your app, it takes focus from whatever the previously active app is. For example, you have safari open and want to automatically fill in a form field. When you launch your app/script, IT is now the topmost window and active application and must be told explicitly what to do and which application to act upon. The script has no way to “remember” that safari is even open and that it should be the target of your text insertion.
One good method I’ve used successfully for many apps, because of the wide support for the standard “paste” command, is to use the clipboard and system events to tell a SPECIFIC app to insert text. For many apps, you should be able to get away with something like the following code. Make sure that the field you want text inserted into is focused when you run it, or nothing will happen.
tell application "Some App" to activate
try
tell application "System Events"
tell application process "Some App"
set the clipboard to "Test"
keystroke "v" using command down
end tell
end tell
on error
display dialog "It didn't work!"
end try
Another option would be to use the script to place the content into the clipboard, and then just use (cmd+v) to manually paste it into whatever your app is…
set the clipboard to "Test"
As camelot said, you need to be A LOT more specific with what your trying to accomplish. It is doubtful that you will be able to create a graceful script that will handle many different applications. Every app is a little different, and will likely have it’s own method of approach… making a separate application for each task appropriate. Unfortunately applescript doesn’t seem to have a solid method of finding out what the PREVIOUS active app was.
j