Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Star! Options Dialogs?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Star! Options Dialogs?
Authored by: selasley on Sep 28, '04 05:28:26PM
Here's my attempt at a version that prompts for width and save location and keeps those values between runs.

-- save in Script Editor as Application
-- drag files to its icon in Finder

property target_width : 120
property save_folder : ""

on open some_items
    -- do some set up
    tell application "Finder"
        -- get the target width, the default answer is the property target_width
        set new_width to text returned of ¬
            (display dialog "Target width:" default answer target_width ¬
            buttons {"OK"} default button "OK")
        if new_width as integer > 0 then
            set target_width to new_width
        end if
        -- if the save_folder property has not been set, 
        -- set it to the folder containing the original image
        if save_folder is "" then
            set save_folder to ¬
            (container of file (item 1 of some_items) as string)
        end if
        -- get the folder to save the scaled images in, 
        -- default folder is the property save_folder
        set temp_folder to ¬
            choose folder with prompt "Save scaled images in:" ¬
            default location alias save_folder
        set save_folder to temp_folder as string
    end tell
    -- loop through the images, scale them and save them 
    repeat with this_item in some_items
        try
            rescale_and_save(this_item)
        end try
    end repeat
    
    tell application "Image Events" to quit
end open


on rescale_and_save(this_item)
    tell application "Finder"
        set new_item to save_folder & "scaled." & (name of this_item)
    end tell
    
    tell application "Image Events"
        launch
        -- 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}
        scale this_image by factor (target_width / current_width)
        save this_image in new_item as typ
    end tell
end rescale_and_save


[ Reply to This | # ]
Star! Options Dialogs?
Authored by: willbank on Sep 29, '04 12:20:59PM
Brilliant, brilliant, brilliant selasley. Thanks so much.

---
No, really. This is a healthy obsession.

[ Reply to This | # ]

Star! Options Dialogs?
Authored by: Bepe on Oct 01, '04 08:25:39AM
Hello, great job this script !! I love this site :-) I had a prompt for prefix (scaled.) and translate into french. Here it is :

-- Redimensionne les images
-- par drag & drop
----

-- propriétés par défaut
-- Largeur 120 pixels
-- pas de dossier d'enregistrement
-- prefix des images : redim.nom_image.jpg
property target_width : 120
property save_folder : ""
property prefix : "redim"

-- handler du drag & drop
-- appelle la boucle principale : rescale_and_save
-- pour le ou les items glissés
on open some_items
	-- Réglages
	tell application "Finder"
		-- Obtenir la largeur souhaitée, la réponse par défaut est la  propriété de  target_width
		set new_width to text returned of ¬
			(display dialog "Largeur souhaitée:" default answer target_width ¬
				buttons {"OK"} default button "OK")
		if new_width as integer > 0 then
			set target_width to new_width
		end if
		-- Réglage du préfixe
		set prefix to text returned of ¬
			(display dialog "Préfixe des images redim :" default answer prefix ¬
				buttons {"OK"} default button "OK")
		
		-- Si la propriété save_folder n'est pas renseignée 
		-- la fixer au dossier contenant l'image originale
		if save_folder is "" then
			set save_folder to ¬
				(container of file (item 1 of some_items) as string)
		end if
		-- obtenir le nom du dossier dans lequel enregistrer les images redimenssionnées, 
		-- par défaut la propriété est dans save_folder
		set temp_folder to ¬
			choose folder with prompt ¬
				"Enregistrer les images dans:" default location alias save_folder
		set save_folder to temp_folder as string
	end tell
	-- boucler pour toutes les images, les redimensionner et les enregistrer 
	repeat with this_item in some_items
		try
			rescale_and_save(this_item)
		end try
	end repeat
	
	tell application "Image Events" to quit
end open


on rescale_and_save(this_item)
	tell application "Finder"
		set new_item to save_folder & prefix & "." & (name of this_item)
	end tell
	
	tell application "Image Events"
		launch
		-- Ouvir le fichier image
		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}
		scale this_image by factor (target_width / current_width)
		save this_image in new_item as typ
	end tell
end rescale_and_save



[ Reply to This | # ]