Hi all,
First off, apologies if what I’m struggling with is really basic. I’m new to Applescript but keen to learn. So far I’ve managed to achieve everything I’ve set out to do but today I hit a wall. I’ve been trawling the forums and watching all the tutorial videos I can find but I’m stumped. I’m sure I’m going to kick myself.
All I’m looking to do is to copy a bunch of files to a folder on the desktop and name them according to their dimensions. Creating the folder and duplicating the files is simple enough, and I’ve managed to come up with a script that will achieve the renaming by dimension for a single file:
set this_file to choose file
try
tell application "Image Events"
-- start the Image Events application
launch
-- open the image file
set this_image to open this_file
-- extract the properties record
set the props_rec to the properties of this_image
-- purge the open image data
close this_image
-- extract the property values from the record
set the image_info to ""
copy (dimensions of props_rec) to {x, y}
set the image_info to the image_info & ¬
"" & x & "x" & y
end tell
on error error_message
display dialog error_message
end try
tell application "Finder"
set ext to name extension of this_file
set the name of file this_file to image_info & "." & ext
end tell
It all falls apart when I try to get the script to loop and rename all of the inputted files according to their dimensions. This is what I’ve currently got
--Creates a root folder on the desktop called WorkPresentRoot. Asks for work files. Copies them to folder.
tell application "Finder"
set p to path to desktop
make new folder at p with properties {name:"WorkPresentRoot"}
set workFilesLocation to ((path to desktop folder) & "WorkPresentRoot") as string as alias
set theImages to choose file with prompt "Please select work files:" with multiple selections allowed
duplicate theImages to workFilesLocation
end tell
tell application "Finder"
set filelist to every file of the workFilesLocation
repeat with currentFile in filelist
set currentFileName to (the name of currentFile)
copy currentFileName to the end of listOfNames
try
tell application "Image Events"
-- start the Image Events application
launch
-- open the image file
set this_image to currentFile
-- extract the properties record
set the props_rec to the properties of this_image
-- purge the open image data
-- extract the property values from the record
set the image_info to ""
copy (dimensions of props_rec) to {x, y}
set the image_info to the image_info & ¬
"" & x & "x" & y
end tell
on error error_message
display dialog error_message
end try
tell application "Finder"
set ext to name extension of currentFile
set the name of currentFile to image_info & "." & ext
end tell
end repeat
end tell
Again, I’m sure this is simple stuff but, at this point, any amount of help would be GREATLY appreciated. I’ve been tearing my hair out over this fir the best part of a day! Thanks.