Put Image into TextEdit Doc

I would like to take a folder of images and put them into a text document, in a uniformed way for printing later. The code I have garnered so far almost works. The following gets an image to read, in the temp folder. Then it begins to write the data, where it fails. Code:

set filePath to (choose file) as string
set imagePath to read file filePath
set the temp_file to ((path to the temporary items folder) as string) & "tempimage.pct"
	set the open_target_file to open for access file temp_file with write permission
	set eof of the open_target_file to 0
	write imagePath to the open_target_file as picture
	close access the open_target_file
on error error_message
		close access file temp_file
	end try
	error "There was a problem writing the image data to file."
end try
tell application "TextEdit"
	make new attachment with properties {file name:(alias temp_file)} at after the last character of document 1
end tell

Hi Brandon, I think the solution is much easier then what you tried:

tell application "Finder"
	set f to choose file
	set p to POSIX path of f
	tell document 1 of application "TextEdit"
		make new attachment with properties {file name:p}
	end tell
end tell

Hope it helps & ciao

Hi Brandon, this is an even more simplified ver to what “chebfarid” wrote: -
–Open this script in a new Script Editor window.

telldocument1ofapplication "TextEdit" tomakenewattachmentwith properties {file name:frowning:POSIX pathof (choose file))}

[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Wow guys, you KISSed it very nicely!
So my next question would be, why do all the examples of such a thing use the difficult way of reading the file and writing the file? I got my idea from Sal’s example of getting an image out of iTunes and putting it in a text document. There were several other examples too, that did the same kind of thing, yet it seems these examples are, well programmatic. In this example, you gentlemen, simply applescripted it.

I want to do the opposite! I want to
put Text into an image document.

I have a photoshop document with a background layer, and a second layer that is text. If I save it to Photoshop PDF I can open it in TextEdit, but the code is arggggful. I can find the place in the code where the text fields are located, but I’ve corrupted every file trying to change the text so far.

:arrow: The photo is a template. Layer 2 is text that I want to be a variable, so that any text could be inserted into it from a dialog prompt.

set layerText to (display dialog "Enter some text: " default answer "" buttons {"Cancel", "Ok"} default button 2)
set someText to text returned of layerText

tell application "Adobe Photoshop CS"
	-- Create a new document and art layer.
	set docRef to make new document with properties {width:3 as inches, height:2 as inches}
	set artLayerRef to make new art layer in docRef
	-- Set the art layer's name.  This is not necessary
	-- but makes the layer more identifiable.
	set name of artLayerRef to "MyNewTextLayer"
	-- Tell the art layer that is a text layer.
	set kind of artLayerRef to text layer
	-- Get a reference to the text item and set its contents.
	set textItemRef to text object of artLayerRef
	set contents of contents of textItemRef to someText
end tell