Hello,
ive been doing some work with applescript and image events. I have a script that can resize my images, but i would like to simplify it and make it usable within an automator workflow. What im trying to do is to rewrite the script so its very simple and basic, but i cant figure out how to get it to work…
on open some_items
repeat with this_item in some_items
try
rescale_and_save(this_item)
end try
end repeat
end open
to rescale_and_save(this_item)
tell application "Image Events"
launch
tell application "Finder" to set the target_width to text returned of (display dialog "What width would you like to resize to? Must be a number:" default answer "")
-- open the image file
set this_image to open this_item
set typ to this_image's file type
copy dimensions of this_image to {current_width, current_height}
if current_width is greater than current_height then
scale this_image to size target_width
else
-- figure out new height
-- y2 = (y1 * x2) / x1
set the new_height to (current_height * target_width) / current_width
scale this_image to size new_height
end if
tell application "Finder"
set myDir to "Macintosh HD:Users:Nothinggrinder:Desktop:resized"
if exists myDir then
if exists (myDir & ":" & (name of this_item)) then
tell application "Finder" to set new_item to "Macintosh HD:Users:Nothinggrinder:Desktop:resized:" & "copy_" & (name of this_item)
save this_image in new_item as typ
else
tell application "Finder" to set new_item to "Macintosh HD:Users:Nothinggrinder:Desktop:resized:" & (name of this_item)
save this_image in new_item as typ
end if
else
set dp to myDir
tell application "Finder" to if not (exists folder dp) then do shell script "mkdir -p " & quoted form of POSIX path of dp
dp
if exists (dp) then
tell application "Finder" to set new_item to "Macintosh HD:Users:Nothinggrinder:Desktop:resized:" & (name of this_item)
save this_image in new_item as typ
end if
end if
end tell
tell application "Finder"
set myDir2 to "Macintosh HD:Users:Nothinggrinder:Desktop:image_original"
if exists myDir2 then
if exists (myDir2 & ":" & (name of this_item)) then
tell application "Finder" to move this_item to myDir2
end if
else
set dp to myDir2
tell application "Finder" to if not (exists folder dp) then do shell script "mkdir -p " & quoted form of POSIX path of dp
dp
if exists (dp) then
tell application "Finder" to move this_item to myDir2
end if
end if
end tell
end tell
end rescale_and_save
this is my original script, its designed as a droplet. I would like to set and create the folders in automator, then just resize the image using image events. This way i dont have to worry about paths. I do like that i can enter the size i would like to resize to. The rest should be changed im sure, but im not very clear on how applescript works with automator… any help would be appreciated. if any one has any examples that would be great too. thanks.