write text

I need help making a script that would write whatever I put in for a variable. then write it in an application such as Appleworks, or something. If you have a command that would let me do that I would greatly appreciate this. I do not know the command for it and every time i keep guessing the command it is always an error
display text

Some other times when it does not say error… it just shows the result as the text.

I don’t know what the command is. If you know or already have this script please post it here.

~Matt~ (Not THE “Matt Burch”)

Hi Matt;

Code Exchange is a forum for sharing working code; AppleScript | OS X is the place to be to ask a question where folks will be more likely to see it and respond.

I’ve moved your post there.

Two ways to go, if I understand the question. First, you can interact directly with the application where you want the text to appear (Appleworks, or something), and Second, an AppleScript can write to a text file itself and you can open that with any other application that can read text.

set myText to "Hello, there!" -- can be quite long.

set myPath to (path to desktop as text) -- or whatever folder you want it to go to
set myTxtFile to "This Is a Test" -- or whatever name you have in mind

set f to open for access myPath & myTxtFile with write permission -- creates the file if it doesn't exist, f is a reference to it.
write myText to f -- easy, huh?
close access f -- be sure to do this, or you'll have problems getting rid of the file

Hi Matt,

You can’t make up stuff and hope that it will work. You need to learn how to use dictionaries of scriptable applications and basic AppleScript.

Here’s a quicky how to put text in an AjppleWorks 6 new word processing document:

tell application “Safari” to set t to (text of front document) as string
tell application “AppleWorks 6”
make new document at front with properties ¬
{document kind:text document}
set text body of front document to t
end tell


ugh… yes i can. That is the best way to learn stuff, trial and error. It is what I have been doing my whole life. Works well. I know codes lots of codes.
TI-Basic (on my TI-83 plus calculator)
Learning Visual Basic
Learning ASM
Learning Applescript

Applescript I am learning to use now, is really easy. :slight_smile:
I know how to use commands, I just didnt know this one command and i was just asking for help. Thank you all for helping me with this i will see if it works now.

Sorry, I wasn’t using OS X at the time so I thought it was Code Exchange. It takes me a while to get used to new forums.

hmm… this is not really what I am looking for. What I would like to have is a script that would write stuff for me. Like…

tell application “Internet Explorer”

then go to a site, and login just using a script. it would type in my username, then my password, and hit enter.

~Matt~ (Not THE “Matt Burch”)

What makes AppleScript different, is that all applications don’t have the same scripting terminology. Learning to read the dictionary is essential. Otherwise, you’ll be trial and erroring above the trial and error you already have to do even if you know how to read dictionaries.


And to make matters worse, and reinforce kel’s point, the dictionaries sometimes have the same words in them so the way something responds will depend on what application you’ve “told” to do it. Can bite you on the bum, believe me.

Here’s an example of a script that works for me in Safari, Matt. It might help you to get started.

-- modify the following properties as appropriate:
property logon_address : "http://springfield.com/config/login?&.done=http%3a//springfield .com/%3f"
property logon_name : "homer.simpson@springfield.com"
property logon_password : "mmmdoughnuts" (* consider using keychain scripting once the script is working *)

tell application "Safari"
	open location logon_address
	tell document 1
		repeat until name starts with "Loading" or name starts with "Untitled"
			delay 0.2
		end repeat
		repeat while name starts with "Loading" or name starts with "Untitled"
			delay 0.2
		end repeat
	end tell
end tell

tell application "System Events"
	delay 1.5 (* modify delay as required *)
	keystroke logon_name & tab
	delay 1.5 (* modify delay as required *)
	keystroke logon_password & return
end tell