Oh to make an xml file

Applescript just doesn’t make sense to me. I’m trying to use Applescript (because i understand that better than Cocoa) to help me with a “program” I’m writing. I want to make customizable web galleries based off of a folder of images.

What i want Applescript to do is to take a selected folder and go through each image and examine the exif data embedded in it to get the filename, width, & height, and write that info into an XML file that will later be pulled into Flash.

Like i said, I just don’t know much Applescript, but anything anyone could contribute to help get me going in the right direction would help out so much.

There are numerous existing solutions for this type of project, from shareware to iLife apps. Alternately have you researched image file AppleScript and creating XML files using AppleScript?

Maybe using Automator would be a better solution than plain AppleScript?

Look at the application Image Events AppleScript dictionary. It can get the basics. As far as the xml, there are a couple of Scripting Additions that can do that. But, since xml is basically just a text file (usually utf-8 encoding), I wonder if you couldn’t just write it directly, adding an xml declaration at the top (must start at the 1st character),* then your tags, the data, the end tag. I haven’t actually tried this, but I don’t see why it wouldn’t work.

*I don’t know whether Flash even requires a declaration, but probably a good idea to do it.

Example, psuedo-code:

<?xml version='1.0' encoding='utf-8'?>

<file_name>Some file name</file_name>
<file_path>Big long file path</file_path>

Or you could do it with attributes, if that’s what Flash wants:

<?xml version='1.0' encoding='utf-8'?>

<image_file file_name=‘Some file name’ file_path=‘Big long file path’ file_size=‘121’ height=‘1110’ width=‘1200’ />

This script will process a folder of images using Image Events to create a list of filenames and dimensions:

set an_Folder to choose folder
set final_List to {}
tell application "Finder"
	set all_files to every file in an_Folder
	repeat with next_image in all_files
		set dummy to {next_image's name}
		set end of dummy to my GetDimensions(next_image)
		set end of final_List to dummy
	end repeat
end tell
-->{{"Beaver 3.jpg", {3456.0, 2304.0}}, {"Ferris Wheel 3.jpg", {3456.0, 2304.0}}, {"Ferris Wheel 4.jpg", {2304.0, 3456.0}}, {"Ferris Wheel 5.jpg", {3453.0, 2256.0}}, {"IMG_1669.JPG", {3456.0, 2304.0}}, {"IMG_1671.JPG", {3456.0, 2304.0}}}

to GetDimensions(a)
	tell application "Image Events"
		close images
		set b to open (a as alias)
		set c to dimensions of b --dimensions (list, r/o) : the width and height of the image, respectively, in pixels, as a pair of integers
		if c = {} then set c to {"Image Events cannot read dimensions of this file"}
		close b
		return c
	end tell
end GetDimensions

Good luck,

Thanks for your help. But I’ve changed my mind about using Applescript for it and instead i’m writing a script for Photoshop in Javascript to do the same thing. Thanks again.