open iTunes dialog causes script to crash Entourage X

Forgive me if this is elementary, but I can’t find the answer after an hour of searching…

I have a simple little script to open Photoshop, copy the caption info from a file, open TextEdit, paste it in a new document and close the document.

It works great, but after running it, I realized it would be nice if after I hit “Save” or “Don’t Save” in TextEdit’s dialog box, the script switched back to Photoshop, but if I hit “Cancel” the script ends (with TextEdit still active).

I tried putting this at the end:
tell application “Adobe Photoshop CS”
activate
But quickly realized that it won’t wait for the interaction and I can’t quite figure out how to get it to wait for the dialog.

Thanks!

-Ryan

If all you’re doing is saving the caption in a text file, you don’t need to use TextEdit at all, which resolves the problem of activating photoshop afterwards:

set outputFile to open for access "path:to:file.txt" with write permission
set eof outputFile to 0 -- clear out the current contents, if any
write captionText to outputFile
close access outputFile

This writes the text directly to the file and doesn’t need TextEdit to open, and doesn’t display any dialog boxes.

That’s great, but we’re always saving the files in different places with different names that must correspond with the photos they belong to.

Any way to specify that each time the script runs?

Thanks for help Camelot –

After a little more messing around I got this to work…


tell application "Adobe Photoshop CS"
	activate
	set outputFile to open for access (choose file name with prompt "Provide a name for the caption and select the location **make sure you add .txt to the end**") with write permission
	set eof outputFile to 0 -- clear out the current contents, if any 
	set the clipboard to caption of info of current document as text
	write {text:the clipboard} to outputFile
	close access outputFile
end tell

It may be a bit of a waste to go to the clipboard and back, but I couldn’t get it to write the contents of the caption any other way.

Thanks again!