Re: Need help scripting Photoshop...
Re: Need help scripting Photoshop...
- Subject: Re: Need help scripting Photoshop...
- From: Brennan <email@hidden>
- Date: Fri, 28 Mar 2003 10:09:20 +0100
On Thu, 27 Mar 2003 15:52:09 -0500, "CS Carl Stawicki (4211)"
<email@hidden> wrote:
>
Hi all,
>
>
This is my first post here. I consider myself an intermediate beginner in
>
Applescripting, I guess. I'm working on a script that does the following:
>
>
1. Stays open and idles while it monitors a drop folder. The drop folder is
>
a folder on a server that users would keep an alias of on their desktops to
>
drop tiffs onto.
>
>
2. Once a tiff is dropped, the script opens it in Photoshop and runs an
>
action. The action does it's thing and resaves the file as a jpeg to another
>
specified destination and closes the file. The script then deletes the
>
original dropped tiff.
>
>
What I came up with works very well, but I need few enhancements that I
>
don't know how to do. A stripped-down version of what I have so far is this:
>
--
>
on idle
>
tell application "Finder"
>
with timeout of 3600 seconds
>
set new_file_count to count files of folder "Server:Drop Folder"
>
repeat until new_file_count < 1
>
set new_files to every file of folder "Server:Drop Folder"
>
if new_files exists then tell application "Finder" to open new_files using
>
application file id "8BIM"
>
repeat
>
tell application "Adobe Photoshop 7.0"
>
if first document exists then
>
do action "My Action" from "My Action.atn"
>
else
>
exit repeat
>
end if
>
end tell
>
end repeat
>
if new_files exists then delete new_files
>
end repeat
>
end timeout
>
end tell
>
return 1
>
end idle
>
--
>
What I am stuck on is this:
>
>
1. I'd like the script to limit the number of files it opens into Photoshop
>
at one time. Right now, the script will open all the files in the drop
>
folder, which is fine, but I don't want it to open too many at once. If
>
there are, say 10 files open and processing through the action, and I drop 5
>
more in the drop folder, it will stop processing the original 10 and open
>
the new 5 before it continues. I don't know what Photoshop's limit is, but
>
there is the possibility we may drop 100's of tiffs in this folder at once.
The way I would do this would be to create some kind of 'queue' - which in
Applescript would probably be implemented as a property containing a list of
all the files which need to be processed. It needs to be a property so that
its contents are remembered from one idle to the next. This will allow you to
pace the various tasks more freely.
Your idle handler should add any 'new' files to this list/queue, and another
part of the idle handler should process EXACTLY ONE file in photoshop. (You
could break the photoshop process into individual steps or states, and have
the idle handler advance from one state to the next when it knows that the
state is completed, but that adds a lot of extra complexity).
Here's a script which will process one file at a time, regardless of how many
files you add to the watched folder (and how often you do it). It will break
down if you add a file to the folder which has the same name as one which
already exists (opting to replace in the Finder). This could be more or less
disastrous if the file is open in Photoshop at the same time. :)
The script currently only does ONE thing, which is to delete any files dropped
into the folder. You will need to insert your own Photoshop code before the
delete for it to be useful.
property watchedFolder : alias "Server:Folder:"
property filesToProcess : {}
on idle
tell application "Finder"
set newFiles to files of folder watchedFolder whose it is not in
filesToProcess
if (count newFiles) > 0 then -- there are some new files
set filesToProcess to filesToProcess & newFiles
--set newFiles to {}
end if
end tell
if (count filesToProcess) = 0 then -- there are no files to process
return 1
end if
set currentFileToProcess to (item 1 of filesToProcess)
-- insert code to process the file here
deleteFile currentFileToProcess with unlocking without safety net -- Jon's
Commands
if (count filesToProcess) = 1 then
set filesToProcess to {}
else
set filesToProcess to (items 2 thru end of filesToProcess)
end if
return 1
end run
Strictly speaking you could do this with a folder action, but then I think you
need to have the folder open for it to work.
>
2. I'd like Photoshop to delete any alpha channels, if there are any, before
>
it runs the action.
Sorry, I don't have Photoshop 7 around, but when I played with it the other
day, the scripting support was quite impressive. They'd taken some care to
follow a clean design.
If photoshop understands the 'delete' command (check the dictionary), and if
you are targeting the right document, then I should think that the syntax
would be something like
repeat while (count alpha channels) > 0
delete alpha channel 1
end repeat
... or even :
delete every alpha channel
>
3. I would like to delete the original tiff from the drop folder without
>
moving it to the trash, just delete it all together (I don't even know if
>
this is possible).
In my script above, I've used 'Jon's Commands' which has a 'deleteFile'
command. The trash is never involved. I think this is available for OSX, but
if you are using OS9, it will certainly work.
Good luck, and tell us how you get on. I'd certainly like to see more intrepid
Photoshoppers getting into Applescript. Maybe Adobe will extend scriptability
to all their apps if there is enough interest. Tell your friends.
Brennan
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.