Skip to main content
Participant
May 21, 2008
Question

applescript photoshop open file delay

  • May 21, 2008
  • 2 replies
  • 2205 views
Hi,

I have a problem with photoshop and applescript. When I run the following simple applescript which opens a document and saves it in a location:

tell application "Adobe Photoshop CS3"
open picpathalias
-- delay 10 -- quite a long delay is needed

save current document in file regpicpath as JPEG
end tell

I often receive the following error:

Adobe Photoshop CS3 got an error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- The object current document is not currently available.

It seems there is a race between the open cmd and the save cmd. This most often happens when photoshop is not yet an open application. It almost never happens when photoshop is already open. Is there a programmatic way to make open block until the document is available?

Thanks.

-yang
This topic has been closed for replies.

2 replies

Known Participant
May 22, 2008
As well as Carl's suggestion you could also try this.
--*********
set picpathalias to choose file
set regpicpath to (path to desktop as Unicode text) & "Testing.jpg"
--
tell application "Adobe Photoshop CS2"
activate
with timeout of 180 seconds
open picpathalias
repeat until exists current document
delay 3
end repeat
end timeout
save current document in file regpicpath as JPEG with options ¬
{class:JPEG save options, embed color profile:true, format options:optimized, matte:background color matte, quality:9}
close current document without saving
end tell
--*********
Participating Frequently
May 21, 2008
>It seems there is a race between the open cmd and the save cmd.

You can put the save command a repeat loop that tries to save, but waits and repeats when there's an error.



tell application "Adobe Photoshop CS3"
open picpathalias

repeat 100 times -- Give some limit
try
save current document in file regpicpath as JPEG
exit repeat -- The save was successful
on error errorMessage
if errorMessage does not contain "The object \"current document\" is not currently available" then
-- There was some other error than the one you were expecting
-- that should be dealt with accordingly.
end if
delay 1 -- Delay a second to give PS a chance to catch up (optional)
end try
end repeat

end tell


Carl.