Is it possible to add an image to a text view like this:
set contents of text view "text" of window "main" to "this is the text before the image /folder/image.jpg this text goes after the image"
--where /folder/image.jpg is the path to a jpeg image
While you can put an image in a text view, I don’t think you can do it by embedding a link like that. I imagine that you need to do something like:
set contents of text view "text" of window "main" to {"this is the text before the image",anImage,"this text goes after the image"}
--where anImage is a variable that contains an image
If that (or something similar) doesn’t work, I doubt you can do it in code.
@end[/code]
add the above file to your project, then you can call it like this:
set imgPath to (POSIX path of (choose file))
set insertAtIndex to 5
set succeeded to (call method "insertImageFromPath:atIndex:" of myTextView with parameters {imgPath, insertAtIndex})
set img to load image (POSIX path of (choose file))
set insertAtIndex to 5
set succeeded to (call method "insertImage:atIndex:" of myTextView with parameters {img, insertAtIndex})
Very good Dominik, it worked perfectly. I added your code and a button to the plain text editor example and it work. Except that when I try to reopen the document after having saved it, a question mark appears where the picture was. Any ideas on how to save the image?
as far as I remember ‘Plain Text Editor’ writes and reads only plain text documents (the text view’s content is saved as string??). You will have to modify the document’s reading and writing to handle rtfd. It might again be necessary to use some call methods. NSText has two convenient methods for this: “writeRTFDToFile:atomically:” and “readRTFDFromFile:” …