Hello to all,
I am a scripting newbie, and I am in need of some help. I wrote a script (droplet) to take any number of images that are dropped onto the icon, duplicate them into a new folder (so there are originals that are untouched), scale the images using ImageEvents, then upload the web-friendly sized pics to an afp mounted share point.
The script works many times, but often it fails! I cannot figure out a rhyme or reason to why it fails. I used a bunch of on error commands to help me determine WHERE the script breaks down (it is notated in the script), but I cannot figure out WHY it fails sometimes and other times it works like a charm.
Any help would be appreciated.
Thank you,
Dave Huber
(script below)
--if they double-click it, gently chastise them
on run
display dialog "No no no, silly! Don't double-click me...drag pictures on top of me!" buttons {"DOH!"} default button 1
end run
on open draggedItems
try
--mount the share point
mount volume "afp://server/sharepoint" as user name "user" with password "password"
on error
display dialog "couldn't mount the share point"
end try
try
--define the upload folder
set upload_folder to "sharepoint:images"
--get ready to make a folder...
--get time into text format
set current_week_day to weekday of (current date) as text
set current_day to day of (current date) as text
set current_month to month of (current date) as text
set current_year to year of (current date) as text
set current_time to (time of (current date)) as text
--put all of the date info into one term called "current_date"
set current_date to current_week_day & " " & current_day & " " & current_month & " " & current_year & " " & current_time as text
--make a folder called 'Originals B4 upload' plus current date
set foldername to "Originals B4 upload " & current_date
tell application "Finder" to make new folder at desktop
set localfolder to the result as alias
tell application "Finder" to set the name of localfolder to foldername
on error
display dialog "couln't make a folder with the current date in the name."
end try
--repeat these steps for each item dropped on the icon
repeat with currentFile in draggedItems
try --make a copy of the pic in the folder we just created
tell application "Finder"
duplicate (currentFile as alias) to localfolder
end tell
on error
display dialog "error duplicating the scaled image to joomla folder."
end try
--scale the image to a web-friendly size
try
tell application "Image Events"
set openedFile to open (currentFile as alias)
end tell
on error
display dialog "couldn't set openedFile to currentFile as alias...whatever that means."
end try
delay 2
--NOTE - THIS IS WHERE THE SCRIPT FAILS!!!!!!
try
tell application "Image Events"
scale openedFile to size 180
end tell
on error
display dialog "couldn't scale the image"
end try
--NOTE - THE ABOVE IS THE ERROR MESSAGE I GET ABOUT 50% OF THE TIME!!!
try
tell application "Image Events"
save openedFile
end tell
on error
display dialog "couldn't save the scaled image"
end try
try
tell application "Image Events"
close openedFile
end tell
on error
display dialog "couldn't close the image"
end try
--upload the scaled image & move the local one to the trash
try
tell application "Finder"
duplicate (currentFile as alias) to upload_folder
end tell
on error
display dialog "error trying to upload the image to joomla"
end try
try
tell application "Finder"
delete (currentFile as alias)
end tell
on error
display dialog "couldn't move current file to the trash."
end try
--we are done batch processing now...
end repeat
--eject the joomla disk
try
tell application "Finder"
eject disk "joomla"
end tell
on error
display dialog "couldn't eject the joomla disk."
end try
--notify the user
tell application "SystemUIServer"
activate
display dialog "The image(s) you dragged onto the icon have been scaled and uploaded and can now be used in any story you'd like to publish.
Furthermore, the scaled images have been moved to your trash and your originals have been moved to a new folder on the desktop called " & foldername buttons {"Groovy"} default button 1
end tell
end open
Model: PowerBook G4
AppleScript: 1.10.7
Browser: Firefox 1.5.0.8
Operating System: Mac OS X (10.4)