Hi,
I am trying to scipt photoshop. I have had problems with the reliability of automating actions in Photoshop so I am looking to script a whole package.
Unfortunately I am stumbling at the first hurdle! The first thing I want to do is create a contact sheet from the files in a specific folder.
This is how the photoshop script help file describes the syntax but I’m afraid I don’t understand the “from files list of alias” bit. I’m sure this is a stupid question but does anyone know how I tell it to create a contact sheet from the files in a specific folder? Do I have to set an alias first?
[Tell application “adobe photoshop cs2”
create contact sheet from files list of alias
end tell]
alias is a class in AppleScript, which is a bit different from an alias file in the Finder.
For example
choose file
returns an alias
try this
set theFolder to choose folder
tell application "Finder"
try
set theFiles to files of theFolder as alias list
on error
set theFiles to files of theFolder as alias as list
end try
end tell
tell application "Adobe Photoshop CS2"
create contact sheet from files theFiles
end tell
That certainly works very well but is there a way to set the folder to a specific folder (for example “macintosh HD:users:jean:desktop:test:” ) so it runs automatically with no user input?
If you used the “path to” method then you could do this like this:
set theFolder to (path to desktop folder as Unicode text) & "test:" as text
tell application "Finder"
try
set theFiles to files of folder theFolder as alias list
on error
set theFiles to files of folder theFolder as alias as list
end try
end tell
tell application "Adobe Photoshop CS2"
create contact sheet from files theFiles
end tell
note that I have now told finder the variable “theFolder” is reference to a folder
set theFolder to “Macintosh HD:Users:jean:Desktop:test:”
tell application “Finder”
try
set theFiles to files of folder theFolder as alias list
on error
set theFiles to files of folder theFolder as alias as list
end try
end tell
tell application “Adobe Photoshop CS2”
create contact sheet from files theFiles
end tell
When I run this i get "Can’t make every file of “Macintosh HD:Users:jean:Desktop:test:” into type alias.
in Leopard this is sufficient, the alias list bug has been fixed
tell application "Finder"
set theFiles to files of folder "test" as alias list
end tell
tell application "Adobe Photoshop CS2"
create contact sheet from files theFiles
end tell
Note: If the folder is on the desktop of the current user, no further path specification is necessary
Hi Stefan,
Thanks so much for your help, that works well.
Just to really throw a spanner in the works I was wondering if there was a way to set the files list to a variable named folder that has just been created in the script?
Here is the script which is setting the date and time and then creating a new folder based on this info.
tell application "Finder"
activate
set theDate to (current date)
copy theDate to b
set the month of b to January
set monthNum to (1 + (theDate - b + 1314864) div 2629728)
if (monthNum < 10) then
set monthNum to "0" & (monthNum as string)
end if
set yearNum to the year of theDate
set dateNum to the day of theDate
if (dateNum < 10) then
set dateNum to "0" & dateNum
end if
set hourNum to the hours of theDate
if (hourNum < 10) then
set hourNum to "0" & hourNum
end if
set minuteNum to the minutes of theDate
if (minuteNum < 10) then
set minuteNum to "0" & minuteNum
end if
set secondNum to the seconds of theDate
if (secondNum < 10) then
set secondNum to "0" & secondNum
end if
set theFileName to (yearNum as string) & "-" & (monthNum as string) & "-" & (dateNum as string) & "-" & (hourNum as string) & "-" & (minuteNum as string) & "-" & (secondNum as string) & ".psd"
set theFolderName to (yearNum as string) & "-" & (monthNum as string) & "-" & (dateNum as string) & "-" & (hourNum as string) & "-" & (minuteNum as string) & "-" & (secondNum as string)
make new folder at alias "Macintosh HD:Users:jean:Desktop:backup:" with properties {name:theFolderName}
end tell
I would like to point photoshop to look for the files in this new folder but can’t work out the syntax. Maybe it’s not possible.
your code to create a timestamp is quite complicated.
the UNIX command date can do this in one line.
This does the same as your script:
set TimeStamp to do shell script "date +%Y-%m-%d-%H-%M-%S"
set theFileName to TimeStamp & ".psd"
tell application "Finder"
set newFolder to make new folder at folder "backup:" with properties {name:TimeStamp}
end tell
the variable newFolder refers to the new created folder.
But I don’t understand to look for files in a just new created folder
Hi Stefan,
Wow that is much simpler! Thanks so much for your help.
Sorry, I really should explain what I’m trying to do.
Firstly here is my script
on adding folder items to this_folder after receiving added_items
tell application "Finder"
if (count files in folder "photo" of desktop) = 4 then
tell application "Finder"
activate
set timestamp to do shell script "date +%Y-%m-%d%H-%M-%S"
set theFileName to timestamp & ".psd"
set theFolderName to timestamp
make new folder at alias "Macintosh HD:Users:jean:Desktop:backup:" with properties {name:theFolderName}
end tell
tell application "Finder"
activate
set theFiles to files of folder "photo" as alias list
end tell
tell application "Adobe Photoshop CS2"
activate
create contact sheet from files theFiles with options {resolution:346, width:1281, height:1904, column count:2, row count:2, auto spacing:false, caption:false, horizontal offset:23, vertical offset:36}
resize image current document width 9.404 height 13.9777
do action "mikesnewidea" from "Default Actions.atn"
purge all caches
set myFile to "Macintosh HD:Users:jean:desktop:backup:" & (theFileName)
set myOptions to {class:Photoshop save options, embed color profile:true, save spot colors:true, save alpha channels:true, save annotations:true, save layers:true}
save current document in file myFile as Photoshop format with options myOptions appending no extension without copying
close current document saving no
end tell
tell application "Finder"
move (every item of folder "Macintosh HD:Users:jean:Desktop:photo:") to folder theFolderName of folder "backup" of desktop
move file myFile to folder (theFolderName) of folder "backup"
end tell
end if
end tell
end adding folder items to
It’s basically for a photography shoot.
The idea is that as soon as the photo folder has received 4 photos from the the camera the script will kick in. Firstly it creates the timestamp and makes a new folder in an encompassing folder (called backup) with the timestamp as its name. It then starts photoshop and creates a contact sheet and runs through some actions. It then saves the resulting photoshop file named with the timestamp in the backup folder which is then moved along with the original 4 files from the photo folder to the newly created timestamped folder. This leaves the photo folder empty and ready to receive the next 4 files and start again.
This does work but for general housekeeping and piece of mind I would like to move the files from the photo folder to the newly created timestamped folder first and tell photoshop to look there for the files to create the contact sheet. I would also like photoshop to save the file directly to the newly created folder. I’m afraid that I can’t work out the syntax for applescipt to do this.
try this,
it moves first the files to the new location and executes then the PS actions
on adding folder items to this_folder after receiving added_items
tell application "Finder" to count (get files of this_folder)
if result = 4 then
set timestamp to do shell script "date +%Y-%m-%d-%H-%M-%S"
set theFileName to timestamp & ".psd"
tell application "Finder"
set backupFolder to make new folder at folder "backup:" with properties {name:timestamp}
move files of this_folder to backupFolder
set theFiles to files of backupFolder as alias list
end tell
tell application "Adobe Photoshop CS2"
activate
create contact sheet from files theFiles with options {resolution:346, width:1281, height:1904, column count:2, row count:2, auto spacing:false, caption:false, horizontal offset:23, vertical offset:36}
resize image current document width 9.404 height 13.9777
do action "mikesnewidea" from "Default Actions.atn"
purge all caches
set myFile to (backupFolder as text) & theFileName
set myOptions to {class:Photoshop save options, embed color profile:true, save spot colors:true, save alpha channels:true, save annotations:true, save layers:true}
save current document in file myFile as Photoshop format with options myOptions appending no extension without copying
close current document saving no
end tell
end if
end adding folder items to
I tested the script with PS CS3 commenting out the do action and purge lines,
because of not having the particular action. So I guess the action causes the problem