Get Info Help

Hi all,

I’m new to Applescript - I’ve mainly programmed on Windows platforms. I’m trying to create a quick homebrew app to keep me up to date on the software installed on my Intel iMac at home. I’d like to be able to go through my “Applications” folder, run a loop on each object and pull the ‘version’ info for each item and spit these out to a text file. I’m assuming I’d have to use Get Info - does anyone have a syntax for this? Thanks!

Authors are not very good about including their version number in the info for a file. Try this to get that information for those that do, and modify it to suit your purposes:

tell application "Finder" to set f to items of (choose folder)
set vf to {}
repeat with k from 1 to count of f
	set m to item k of f as alias
	set n to name of (info for m)
	try
		set v to short version of (info for m)
	on error
		set v to "N/A"
	end try
	set end of vf to {n, v}
end repeat
vf

This digs around in a few likely folders and uses Finder, rather than Standard Additions’ info for command, to extract data. Where available, the version info reflects that shown in Finder’s info windows. Results should be returned relatively quickly.

to get_version_list from l
	script o
		property d : {}
		property v : {}
	end script
	repeat with f in l
		tell application "Finder" to if exists folder f then tell application files of ¬
			entire contents of folder f to if (count) > 0 then set {o's d, o's v} to {o's d & name, o's v & version}
	end repeat
	set r to return & tab
	repeat with i from 1 to count o's d
		tell o's v's item i to if (count) is 0 then
			set v to "N/A"
		else
			set v to it
		end if
		set o's d's item i to o's d's item i & r & v
	end repeat
	o's d
end get_version_list

to sort_items from i
	script o
		property l : i
	end script
	considering case
		repeat with i from 2 to count o's l
			set v to o's l's item i
			repeat with i from (i - 1) to 1 by -1
				tell o's l's item i to if v < it then
					set o's l's item (i + 1) to it
				else
					set o's l's item (i + 1) to v
					exit repeat
				end if
			end repeat
			if i is 1 and v < o's l's beginning then set o's l's item 1 to v
		end repeat
	end considering
end sort_items

to write_to_file from l
	set f to (path to desktop as Unicode text) & "Application Versions " & (current date)'s short date string & ".txt"
	set o to open for access file f with write permission
	set eof o to 0
	repeat with i in l
		write i & return to o
	end repeat
	set eof o to (get eof o) - 1
	close access o
	tell application "Finder" to open f
end write_to_file

set l to get_version_list from {path to applications folder, path to applications folder from user domain, ¬
	path to "csrv", (path to startup disk as Unicode text) & "Developer:Applications:"} (* modify list as required *)
sort_items from l
write_to_file from l

Much better than “info for”, and amazingly brisk (substantially under a minute) on on my G5, given that the two App. folders (I skipped Developer fearing an unreasonably long run) together produce a 1200 line document.

Too bad the guy/gal who asked has been banned (probably for refusing to give a valid name, which, though it never shows, is a must for membership).