Another newbie question

How do you take a variable and copy it to a text file? I’m sure this is very simple, but I haven’t got the hang of the syntax.

For example, I’ve created a bunch of variables from within Photoshop 7. The height, the width, etc. I want to put each of these values into a TextEdit document.

Here’s what I’ve got so far:

tell application “TextEdit”
open (file as alias) --using Applescript in a Nutshell example
write (theWidth & tab & theHeight & tab & theRes & return as string)
end tell

theWidth, theHeight, theRes are all variables defined as integers from Photoshop 7. They are global at the top of my script, so that hopefully, they will pass out to this handler for TextEdit. (I’ve left off the “on handler()…end handler” lines.)

So, anybody have a suggestion for the syntax for TextEdit (not Photoshop 7 - I think I’ve got that covered)?


-Derek :?

Do you have to use the text editor? I ask because many newbies (including myself) are unaware that you can create a text file using the standard additions. Meaning that you don’t even need to use the text editor.

You can see how to do this if you open the dictionary for the standard additions.

indeed, it’s far easier to just write your data directly to the file in question:

set outputFile to open for access file "path:to:filename" with write permission
write "your data here" to outputFile
close access outputFile

There are things you might need to check if you’re overwriting an existing file, such as setting the EOF (end of file) marker appropriately so that you overwrite the existing data instead of appending)

Hi -
Thank you for the advice on the scripting additions. Until this point, I hadn’t really run into using them, so this was a great step for me.

I’m still having some trouble with this script. Here’s what I’ve got:

repeat with thisFile in fileList
              set filePath to sourcefolder & thisFile as string
              tell application "Photoshop 7.0"
                     open thisFile
                          set theWidth to the width of current document as integer
                          set theHeight to the height of current document as integer
                          set realWidth to theWidth as alias
                          set outputFile to open for access file "disk1:Desktop:filename" with write permission
                          write (realWidth & return) to outputFile
                          close access outputFile
                          close current document
                    end try
              end tell
end repeat

When I open the resulting file in TextEdit, I only see one line with the items “list long %TEXT”. I’m confused about the line “write “your data here” to output file” in Camelot’s post.

Can anybody explain this to me, and how to better generate a list of values from the above script?

Thanks again,


Try this:


Hi Jon -

Tried the code above, but I got a series of class errors. “Can’t make “image.tif”… into a list, record, or text.”

Any suggestions? I used your code verbatim, and defined my sourcefolder and fileList before the actual repeat block began.


Your problem is this part:

Note that the variable ‘realWidth’ is an alias record (or, at least, I assume it is since 'theWidth would be an integer object, so I’m not sure how you’re coercing an integer to an alias, but I’ll skip that for now), so when you ‘write (realWidth & return)’ to the file, you’re writing the raw data that represents the alias object.

Instead, what I assume you’re trying to do is write the variable as a string/text object, in which case you need to tell AppleScript that:

 write ((realWidth & return) as string) to output file

this will coerce ‘realWidth’ to a string object and is what I’m guessing you’re really after.

I suspect you were having problems with your file list. Here is a complete script that does what you want:


Thank you Camelot and Jon -

Both your solutions started to work for me, and now I’m getting the data that I wanted. This is so cool…! I appreciate all the help.

-Derek 8)