Get names and versions of application files

As I knows quite nothing to shell, I treated the raw datas with good old Applescript.

set someFolder to path to applications folder

set liste to do shell script "/usr/bin/mdfind -0 -onlyin " & ¬
	quoted form of POSIX path of someFolder & ¬
	" \"kMDItemContentTypeTree == 'com.apple.application*'\"" & ¬
	" | /usr/bin/xargs -0 " & ¬
	" /usr/bin/mdls -name kMDItemDisplayName -name kMDItemVersion" & ¬
	" | /usr/bin/grep '^kMD.*[^-]$'"

set liste to my remplace(liste, quote, "")
set liste to my remplace(liste, "kMDItemDisplayName = ", "")
set liste to my remplace(liste, return & "kMDItemVersion     = ", tab & "<version> ")

set the clipboard to liste

on remplace(t, d1, d2)
	set AppleScript's text item delimiters to d1
	set l to text items of t
	set AppleScript's text item delimiters to d2
	set t to l as text
	set AppleScript's text item delimiters to ""
	return t
end remplace

Yvan, thanks for your help, as I did need this to work on Tiger too. Any way to make it print nothing rather than (null) when a short version was not found?

Here is a brute force response:

set someFolder to path to applications folder

set liste to do shell script "/usr/bin/mdfind -0 -onlyin " & ¬
	quoted form of POSIX path of someFolder & ¬
	" \"kMDItemContentTypeTree == 'com.apple.application*'\"" & ¬
	" | /usr/bin/xargs -0 " & ¬
	" /usr/bin/mdls -name kMDItemDisplayName -name kMDItemVersion" & ¬
	" | /usr/bin/grep '^kMD.*[^-]$'"

set liste to my remplace(liste, quote, "")
set liste to my remplace(liste, "kMDItemDisplayName = ", "")
set liste to my remplace(liste, return & "kMDItemVersion     = ", tab & "<version> ")
set liste to paragraphs of liste
repeat with i from 1 to count of liste
	if item i of liste does not contain tab then set item i of liste to (item i of liste) & tab & "<no version>"
end repeat
set AppleScript's text item delimiters to return
set liste to liste as text
set AppleScript's text item delimiters to ""
set the clipboard to liste

on remplace(t, d1, d2)
	set AppleScript's text item delimiters to d1
	set l to text items of t
	set AppleScript's text item delimiters to d2
	set t to l as text
	set AppleScript's text item delimiters to ""
	return t
end remplace

MERCI !

Yvan KOENIG

Nice work Jacques. :cool: