Get current file of Photoshop.
All I want to do is from with in photoshop (the user applescript folder) is run this script but rather than select a file, use the open file on photoshop and process (there maybe others open so it would need to get the current document and file name)
Many Thanks
Matt
property type_list : {"8BPS"}
property extension_list : {"psd"}
script o
property theseNames : {}
end script
set thefile to (choose file) as text--> the file path
tell application "Finder" to set TheName to (name of file thefile) --> the name
set the1stLetter to the first character of TheName --> the first letter
set the2ndLetter to the second character of TheName --> the first letter
set brandInitial to {the1stLetter, the2ndLetter} as text
if brandInitial is equal to "BH" then ¬
set brandName to "BRAND"
if brandInitial is equal to "AL" then ¬
set brandName to "BRand"
set weekNumber to ""
display dialog "Please enter the week number:" default answer weekNumber
set weekNumber to text returned of result
try
if weekNumber = "" then error
set theWeekNumber to theWeekNumber as number
on error
set thePrefix to "INVALID ENTRY! "
end try
--Folder location Setup
set this_local_folder to "Images:2012-2013"
set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", localBrandFolder)
set localBrandFolder_PSD to my getFolderPath(brandName & "_WK" & weekNumber & "_PSD", localBrandFolder)
set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2013:"
set networkWeekFolder to my getFolderPath("Week" & weekNumber, this_Network_folder)
set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkWeekFolder)
--all files for website
set website_images to "DCKGEN:Website_Images:"
--set up names to destination folders and create over Network for FTP collection (based on a mounted drive)
set this_ftp_folder to "Impulse:"
set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", ftpBrandFolder)
--set theFolder to eachItem as string -- I think this is the line that could be causing the problem.
--taking the folder identify which process it must follow.
if brandName is equal to "BRAND" then
tell application "Adobe Photoshop CS5.1"
-- I remove the command activate, Photoshop stay in background
set ruler units of settings to pixel units
try
open (aliasthefile) showing dialogsnever
set origName to name of current document
set myOptions to {class:JPEG save options, quality:12}
set myPSDOptions to {class:Photoshop save options, embed color profile:true, save layers:true}
tell current document
--If the quick mask mode has been left on then delete the channel Quick Mask
if (quick mask mode) then delete channel ¬
"Quick Mask"
--If the Layer is incorrectly labeled with Original Layer it needs renaming to original Image
if (exists layer "Original Layer") then ¬
tell layer "Original Layer" to set name to "Original Image"
savein (localBrandFolder_PSD & origName) asPhotoshop formatwith optionsmyPSDOptions without copying
(delete layer "Original Image") flatten
resize imageresolution 300 resample methodnone
--sharpen image
filtercurrent layerusingunsharp maskwith options {amount:80, radius:3.2, threshold:0}
savein (localBrandFolder_High_Res & name) asJPEGwith optionsmyOptions without copying
--get file path, return path of the JPEG file, work with (without copying)
-- (with copying) : it return path of PSD file
set newFile to file path--( return path of type alias )
-- duplicate file using the Finder -->on duplicateFile(..)
my duplicateFile(newFile, {ftpBrandFolder_High_Res})
--Prepare for Low RES by resetting image history
set current history state to history state 3
flatten
resize imagewidth 1348
resize imageresolution 300 resample methodnone
filtercurrent layerusingunsharp maskwith options {amount:80, radius:3.2, threshold:0}
--add save to lowResFolder with same options
savein (localBrandFolder_Low_Res & name) asJPEGwith optionsmyOptions without copying
set newFile to file path
set newFile2 to newFile as string-- for testing end of name
if newFile2 ends with "_2.jpg" or newFile2 ends with "_3.jpg" then -- exclude website_images
my duplicateFile(newFile, {networkBrandFolder_Low_Res, ftpBrandFolder_Low_Res})
else
my duplicateFile(newFile, {networkBrandFolder_Low_Res, ftpBrandFolder_Low_Res, website_images})
end if
closesavingno
end tell
end try
end tell
--End BH
end if
--then the next etc.
on duplicateFile(tFile, foldersPath) -- tFile is an alias, foldersPath is a list of folder
tell application "Finder" to repeat with folderPath in foldersPath
with timeout of 200 seconds-- adjust it, error if the copy is longer that 200 seconds
duplicatetFiletofolderfolderPath with replacing
end timeout
end repeat
end duplicateFile
on getFolderPath(tName, folderPath)
tell application "Finder" to tell folder folderPath
if not (exists folder tName) then
return (makenewfolderat it with properties {name:tName}) as string
else
return (folder tName) as string
end if
end tell
end getFolderPath
iMac, Mac OS X (10.6.8)