choose file --> drag'n drop

Hi all,

How can I modify this script to have a drag’n drop one?


set this_file to choose file
try
	tell application "Image Events"
		launch
		
		set this_image to open this_file
		copy the dimensions of this_image to {xres, yres}
		
		close this_image
	end tell
	
	set px_cm to 0.026458333
	set x_cm to xres * px_cm
	set y_cm to yres * px_cm
	
	display dialog "Pixel: " & xres & " X " & yres & "
Cm: " & x_cm & " X " & y_cm

on error error_message
	display dialog error_message
end try

I’ve tried to change the first line with “on open this_file” but it doesn’t work. Where is the mistake?
Another thing… How can I hypen in the dialog box in another way?

Thanks

Model: macbook
AppleScript: 2.2
Browser: Safari 523.10
Operating System: Mac OS X (10.5)

Hi,

you need a run and an open handler


on run
	processFile(choose file)
end run

on open these_files
	processFile(item 1 of these_files)
end open

on processFile(this_file)
	try
		tell application "Image Events"
			launch
			
			set this_image to open this_file
			copy the dimensions of this_image to {xres, yres}
			
			close this_image
		end tell
		
		set px_cm to 0.00313
		set x_cm to xres * px_cm
		set y_cm to yres * px_cm
		
		display dialog "Pixel: " & xres & " X " & yres & "
Cm: " & x_cm & " X " & y_cm
		
	on error error_message
		display dialog error_message
	end try
end processFile

What do you mean : How can I hypen in the dialog box in another way?

Thanks a lot.


Sorry for my bad English. I’ll explain you:
I want to have the dialog box in this way:

Pixel: 640 X 479
Cm: 2 X 1,5

The only way I know is to write :

display dialog "Pixel: " & xres & " X " & yres & "
Cm: " & x_cm & " X " & y_cm

Is there another way to go to another line of text in the dialog box?

Thanks again

yes, use the return command (which is the equivalent of ASCII character 13

display dialog "Pixel: " & xres & " X " & yres & return & "Cm: " & x_cm & " X " & y_cm

This is useful as well with default answers:

display dialog "Box with returns" default answer "Line 1" & return & "Line 2"

Putting a bunch of returns in the default answer makes the box bigger:

display dialog "Box with 4 returns" default answer return & return & return & return

Using a return in a default answer has another useful effect (at least in Tiger – not running Leopard just now): whether there’s any text in the default answer or not, if there is a return (or several as above) in it the answer box will accept returns in the answer and the return key will not trigger the default button. For example:

set Ans to text returned of (display dialog "Enter your first name, last name separated by a return." & return & return & "Do not click on the text box below, just type your names." & return & return & "Use the return key to enter your answer, or click the \"Done\" button" default answer return & return buttons {"Done"} default button 1)
set {FN, LN} to paragraphs 1 thru 2 of Ans

Perhaps someone will confirm that this still works in Leopard.

Confirmed.

Nitpick: You mean the return constant, not the command. :wink:

exactly, thanks :slight_smile:

actually it is a global property :wink:

Sheesh, guys… a slip of the tongue (as it were)… :confused:

I actually did know that (believe it or not). :lol: