• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie needs help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie needs help


  • Subject: Re: Newbie needs help
  • From: Brian Christmas <email@hidden>
  • Date: Sun, 15 Mar 2009 20:55:39 +1100

Omar, on refection of your text, I think you're trying to save each size in it's own folder, correct?

If so, this script works much better. You've got too many repeat loops. Only one is required.

property theFolder : "Web Images"
global PathToDesktop

set PathToDesktop to path to desktop
tell application "Finder"
activate
try
make new folder with properties {name:theFolder} at desktop
on error
display dialog "There is already a folder named “" & theFolder & "” on your desktop. Would it be okay to use it?"
end try
set folder_names to {"Large", "Medium", "Small", "Icon"}
repeat with folder_name in folder_names
try
make new folder with properties {name:folder_name} at folder "Web Images"
on error
display dialog "There is already a folder named " & folder_name & " in the folder “" & theFolder & "” on your desktop. Would it be okay to use it? All images with the same name will be replaced."
end try
end repeat
end tell


tell application "Finder"
activate
set these_files to choose file without invisibles
end tell
set the target_lengths to {400, 250, 120, 79}
set thecounter to 0
repeat with target_length in target_lengths
set thecounter to thecounter + 1
set folder_name to item thecounter of {"Large", "Medium", "Small", "Icon"}
set jpeg_size to item thecounter of {"_Large", "_Medium", "_Small", "_Icon"}
try
tell application "Finder"
set the new_name to my add_extension(these_files, "jpg", jpeg_size)
if (exists file new_name of folder folder_name of folder theFolder) then
display dialog "A file named \"" & new_name & "\" already exists."
end if
set thePath to (PathToDesktop & theFolder & ":" & folder_name & ":" & new_name) as text
end tell
tell application "Image Events"
launch
set this_image to open these_files
copy dimensions of this_image to {w, h}
scale this_image to size target_length
set new_image to save this_image as JPEG in file thePath with icon
close this_image
end tell
on error error_message
display dialog error_message
end try


end repeat

on add_extension(these_files, new_extension, jpeg_size)
set this_info to the info for these_files
set this_name to the name of this_info
set this_extension to the name extension of this_info
if this_extension is missing value then
set the default_name to this_name
else
set the default_name to text 1 thru -((length of this_extension) + 2) of this_name
end if
return (the default_name & jpeg_size & "." & the new_extension)


end add_extension

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Newbie needs help (From: Omar Khatib <email@hidden>)

  • Prev by Date: Re: Newbie needs help
  • Next by Date: Re: Can someone explain this?
  • Previous by thread: Re: Newbie needs help
  • Next by thread: Working SOAP currency exchange rate server?
  • Index(es):
    • Date
    • Thread