Ok I'm a newbie, can anyone help with dropped files

Hi I have made this very rough script that caluclates the total pixel dimensions of an image and then tells the user if it is high or low res.

At the moment you have to open the app then choose the image, I want to change it to drag and drop but I can’t figure it out!

set this_file to choose file
try
	tell application "Image Events"
		-- start the Image Events application
		launch
		set this_image to open this_file
		-- extract the properties record
		set the props_rec to the properties of this_image
		-- purge the open image data
		close this_image
		-- extract the property values from the record
		set the image_info to ""
		copy (dimensions of props_rec) to {x, y}
		set the image_info to the image_info & ¬
			(x * y)
	end tell
	if image_info is greater than 2000000 then
		display dialog "this is a high res image Move it to Raw Images so it can be processed and stored in Master Images"
		
		
	else if image_info is less than 1500000 then
		
		display dialog "this is a LOW RESOLUTION image, move it to Project Images and request a high res version "
		
	else if 15 ≤ image_info and image_info ≤ 20 then
		
		display dialog "this is a medium res image, move it to Raw Images but try and request a higher res images if possible"
		
		
	end if
end try
end open

Also I would like it to recognise a vector image and display a message for that as well

any help would be great!!


on open of theFiles
	--	Executed when files are dropped on the script

	-- your code goes here
end open

Add the above handler to your app!

Hello.

Is there any particular fileformat with extensions you use, when we are talking about vector images, I surmise we’ll bypass image events, and just go by the file extension?

Hi nitrokev. Welcome to MacScripter.

As mouramartins has hinted, you need a special kind of handler called an ‘open’ handler. The system passes it a list of whatever was dragged onto it and this list is picked up by the variable you put after ‘on open’. (The ‘of’ in mouramartins’s example is wrong but harmless.) Droplet scripts, of course, have to be saved as applications.

This is your script adapted as a droplet. I haven’t tested it.

on open theFiles
	-- start the Image Events application
	tell application "Image Events" to launch
	
	repeat with thisFile in theFiles
		tell application "Image Events"
			set this_image to open this_file -- This 'open' has nothing to do with the handler name!
			-- extract the image's name
			set image_name to name of this_image
			-- extract the dimensions
			set {x, y} to the dimensions of this_image
			-- purge the open image data
			close this_image
		end tell
		
		set the image_info to (x * y)
		if image_info is greater than 2000000 then
			display dialog image_name & " is a high res image Move it to Raw Images so it can be processed and stored in Master Images"
			
			
		else if image_info is less than 1500000 then
			
			display dialog image_name & " is a LOW RESOLUTION image, move it to Project Images and request a high res version "
			
		else -- if 15 ≤ image_info and image_info ≤ 20 then
			
			display dialog image_name & " is a medium res image, move it to Raw Images but try and request a higher res images if possible"
			
		end if
	end repeat
	
	-- Finished with Image Events.
	tell application "Image Events" to quit
end open

When you get a little more proficient, you should add checks to make sure the script doesn’t try to process dragged items which aren’t image files.

Hi the main issue I want to resolve is the fact that some file types can be either vector or bitmap, ie EPS or PDF, we are often sent logo which we need to be in a vector format, but just relying on the file type doesn’t guarantee that is it a vector file, for instance we could be send a logo in eps format, but on opening it we discover that it is a bitmap EPS, I was looking for a way to identify these files by people who don’t have Adobe CS installed

and thanks to the others for the info for open handlers, I’ve modified the script to now also calculate what the print size of the image will be if printed @ 300dpi, this works well with Jpgs and Tiffs but gives incorrect results with PNG files, but its pretty close to what I was after

Thanks!

Hello!

Try the script in post #12 in this post, and see if you can see something that distinguishes as vector graphics file from a bitmap graphichs file in the Spotlight Meta Data. MacScripter / Generic display of Spotlight Metadata for file(s)

Hello!

And should you ever whish to restrict the file types your droplet handles, I guess you can specify the CFBundleDocumentTypes in the info.plist file. You’ll have to google info.plist, and read up on the subject of info.plist files, (it resides one inside your droplet) but it is well worth it, because the operating system gives you so much, by you just specifying some properties. Information Property List Key Reference: Core Foundation Keys