Test whether file has a default application?

I’m working on an AppleScript that will perform an action on a file only if that file does not have any application associated with it - in other words, if “Open With…” in the context menu only has “Other…” listed as an option, and no actual application.

Is there a simple way in AppleScript to test for this condition?

Thank you for any advice.

Hello!

I don’t remember if the creator type of such a file is empty, or consists of four zero’s, but you would check for such a creator type, also have a look at the uti, as maybe a default app will kick in.

This script here, might help you see the differences, and what conditions to test for.


--http://macscripter.net/post.php?tid=39265
-- INFO FOR SELECTED ITEMS
-- ©1998 Sal Soghoian, Apple Computer
(*
	Tinkered By McUsr 2010-04-02 :
	Changed it to take a selcection of files to display info of instead of the usual selection.
	McUsr 2010-07-23 
	Changed it to display a Report in TextEdit
	McUsr 2010-07-25 
	Changed it to have options of both report and dialog, and added the locked and comment property
	to the report.
		McUsr 2010-07-28 
	Added the default application property.
	to the report.

	Pastes all reports to the clipboard silently.
	If selcount > 0 gives info for selected items, else lets you choose.

	changed to return the location of the frontmost finder window.
	added nice icon 
*)
property scriptTitle : "Info for Selected Items"
property genericIcon : a reference to file ((path to library folder from system domain as Unicode text) & "CoreServices:CoreTypes.bundle:Contents:Resources:GenericEditionFileIcon.icns")

set infoIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")

set idOfFrontApp to getfrontAppId()
set ReportText to ""
set failed to false
try
	
	tell application "Finder"
		activate
		set selected_items_list to (get selection) as alias list
		
		set selCount to count selected_items_list
		
		if selCount ≠ 0 then set last_item to the last item of the selected_items_list as text
		--  det er alltid et finder window og det er desktop
		try
			set startPath to target of its Finder window 1 as alias
		on error
			set starpath to path to desktop folder
		end try
	end tell
	
	
	if selCount = 0 then
		tell application "System Events"
			activate
			try
				set the selected_items_list to (choose file with prompt "Choose the files or folders you want to see info for for" default location startPath with multiple selections allowed)
			on error
				set failed to true
			end try
		end tell
		if ((count of the selected_items_list) = 0) or failed then
			alertDialog({aTextMessage:"No files or applications are selected.", aTextTitle:my scriptTitle, timeInSecs:300, btnAsList:{"Ok"}, iconAsFileRef:infoIcon, bundleIdOfFrontApp:idOfFrontApp})
			abortNicely({bundleIdFrontApp:idOfFrontApp})
		end if
		set last_item to the last item of the selected_items_list as text
	end if
	
	tell application "SystemUIServer"
		activate
		try
			set outputType to button returned of (display dialog "Please choose form of output" with title scriptTitle buttons {"Cancel", "Report", "Dialogs"} cancel button 1 default button 3 with icon genericIcon)
		on error
			set failed to true
		end try
	end tell
	if failed then abortNicely({bundleIdFrontApp:idOfFrontApp})
	
	repeat with this_item in the selected_items_list
		if outputType is "Dialogs" then
			set ReportText to ""
		end if
		tell application "Finder"
			
			set this_item to this_item as text
			-- get the information for the item
			
			set item_info to info for alias this_item
			set item_kind to kind of alias this_item
			set item_comment to comment of alias this_item
			if locked of alias this_item is true then
				set locked_indicator to "True"
			else
				set locked_indicator to "False"
			end if
			set duti to type identifier of item_info
			-- extract the various properties from the stored list
			set item_name to name of item_info
			set file_type to file type of item_info
			set item_creator to file creator of item_info
			set item_size to size of item_info
			set item_creation_date to the creation date of item_info
			set item_modification_date to the modification date of item_info
			set item_version to short version of item_info
			set item_owner to owner of item this_item
			set item_ownerP to owner privileges of item this_item
			set item_group to group of item this_item
			set item_groupP to group privileges of item this_item
			set item_everyonesP to everyones privileges of item this_item
			-- convert the true or false value to text
			set alias_indicator to alias of item_info
			if alias_indicator is true then
				set alias_indicator to "True"
			else
				set alias_indicator to "False"
			end if
		end tell
		tell application "System Events"
			set finfo to properties of item this_item
			
			set ftype to type identifier of finfo
			set defApp to name of default application of finfo
		end tell
		if outputType is "Report" then
			set ReportText to ReportText & return & "==================================" & return & "Name: " & item_name & return
		else
			set ReportText to ReportText & return & "Name: " & item_name & return
		end if
		set ReportText to ReportText & "Pathname: " & POSIX path of (this_item as alias) & return
		set ReportText to ReportText & "Kind: " & item_kind & return
		set ReportText to ReportText & "Comment: " & item_comment & return
		set ReportText to ReportText & "File Type: " & file_type & return
		set ReportText to ReportText & "Creator Code: " & item_creator & return
		set ReportText to ReportText & "UTI: " & ftype & return
		set ReportText to ReportText & "Default Application: " & defApp & return
		
		set ReportText to ReportText & "Size: " & item_size & return
		set ReportText to ReportText & "Version: " & item_version & return
		set ReportText to ReportText & "Alias: " & alias_indicator & return
		set ReportText to ReportText & "Cdate: " & item_creation_date & return
		set ReportText to ReportText & "Mdate: " & item_modification_date & return
		set ReportText to ReportText & "Owner: " & item_owner & return
		set ReportText to ReportText & "Owner Privileges: " & item_ownerP & return
		set ReportText to ReportText & "Group: " & item_group & return
		set ReportText to ReportText & "Group Privileges: " & item_groupP & return
		set ReportText to ReportText & "Everybodys Privileges: " & item_everyonesP & return
		set ReportText to ReportText & "Locked: " & locked_indicator & return
		if outputType is "Dialogs" then
			set the clipboard to ReportText
			if this_item is the last_item then
				set the button_list to {"Done"}
			else
				set the button_list to {"Cancel", "Next"}
			end if
			-- display the information
			with timeout of 900 seconds
				tell application "SystemUIServer"
					activate
					display dialog ReportText with title scriptTitle buttons the button_list default button (the last item of the button_list)
				end tell
			end timeout
		end if
	end repeat
	if outputType is "Report" then
		
		tell application "TextEdit"
			activate
			make new document at the front
			set text of front document to "F i l e   i n f o r m a t i o n " & return & ReportText
		end tell
	end if
	
on error e number n
	if not failed then
		alertDialog({aTextMessage:e & " " & n, aTextTitle:my scriptTitle, timeInSecs:300, btnAsList:{"Ok"}, iconAsFileRef:infoIcon, bundleIdOfFrontApp:idOfFrontApp})
		abortNicely({bundleIdFrontApp:idOfFrontApp})
	end if
end try

on getfrontAppId() -- Returns bundleid of active app
	local frontappId
	set frontappId to ""
	tell application "System Events"
		set frontappId to bundle identifier of first application process whose frontmost is true
	end tell
	return frontappId
end getfrontAppId

on abortNicely(r) -- Returns Nothing
	
	tell application "System Events" to tell application process id (bundleIdFrontApp of r)
		key down control
		key code 118
		key up control
	end tell
	error number -128
end abortNicely

on alertDialog(r) -- Returns Nothing
	-- R : {aTextMessage:theMessage,aTextTitle:thetitle,timeInSecs:lenToTimeout,btnAsList:theButton,iconAsFileRef:theIcon,bundleIdOfFrontApp:frontappId}
	local res, failed, e, n
	set failed to false
	tell application "SystemUIServer"
		activate
		try
			if (iconAsFileRef of r) is null then
				set res to button returned of (display dialog (aTextMessage of r) with title (aTextTitle of r) giving up after (timeInSecs of r) buttons (btnAsList of r) default button 1)
			else
				set res to button returned of (display dialog (aTextMessage of r) with title (aTextTitle of r) giving up after (timeInSecs of r) buttons (btnAsList of r) default button 1 with icon (iconAsFileRef of r))
			end if
			if res = "" then set failed to true
		on error e number n
			set failed to true
			
		end try
	end tell
	if failed is true then
		abortNicely({bundleIdFrontApp:(bundleIdOfFrontApp of r)}) -- Returns Nothing
	end if
	return
end alertDialog

If you test for the condition, when you have figured it out on a per file basis, then you might maybe be better off using mdls command, as I believe those attributes to be in there!

Thank you! That told me exactly what I needed to know:

set testFile to choose file
tell application "System Events"
	set finfo to properties of testFile
	try
		set defApp to name of default application of finfo
		display dialog defApp
	on error
		display dialog "No default application"
	end try
end tell

This one would be neater :


set testFile to choose file
tell application "System Events"
	set finfo to properties of testFile
end tell
try
	set defApp to name of default application of finfo
	display dialog defApp
on error
	display dialog "No default application"
end try


set testFile to choose file
tell application "System Events"
	properties of testFile
end tell
try
	set defApp to name of default application of result
	display dialog defApp
on error
	display dialog "No default application"
end try

No need to encapsulate instructions in a tell block if it’s not required.

Yvan KOENIG (VALLAURIS, France) jeudi 9 août 2012 15:09:13

Glad I could help!

There is an article about this at daring.fireball.net, the caveat is when you want to remove stuff, especially the creator type, as the uti is set by an algorithm, usingthe file extension and file creator type. As far as I can recall you have to set a creator type with four 0’s, in order to delete it.

There is also a long article at ArsTechnica about this.

Setting File Creator Type, can be accomplished with the command line tool SetFile, that is delivered with Xcode.

But I guess, if there is no default app in the info for the file, then no default app will be launched! :slight_smile:

On my machine (10.7.4) System Events doesn’t provide default application information,
if an alias is passed. This is more reliable


set testFile to ((choose file) as text)
try
	tell application "System Events" to set defaultApplication to name of default application of file testFile
	display dialog defaultApplication
on error
	display dialog "No default application"
end try

Thanks again to everyone for these solutions. I’ve now got a related question, but will raise it in a different thread.

Thanks Stephan

I dropped 10.7.4 and just ran under 10.8.

Yvan KOENIG (VALLAURIS, France) jeudi 9 août 2012 16:08:30

By the way, here is a script that shows the metadata, but not all possible metadata for a file, but not the default app! I guess the default app, is nothing found to be usable from within Spotlight meta data. :frowning:



-- http://macscripter.net/viewtopic.php?id=39265
--  SPOTLIGHT INFO FOR SELECTED ITEMS
-- PARTS ©1998 Sal Soghoian, Apple Computer
-- Parts © 2012 McUsr I'd rather have you referring to this post at Macscripter.net http://macscripter.net/edit.php?id=154116
-- than posting it elsewhere!
(*
	Compiled  By McUsr 09/08/12:
	Based upen INFO FOR SELECTED Items, uses mouramartins convert mdlsinfo (spotlight metadata to list).
	New code converts mdls info to a list directly
*)
property metaList : missing value
property genericIcon : a reference to file ((path to library folder from system domain as Unicode text) & "CoreServices:CoreTypes.bundle:Contents:Resources:GenericEditionFileIcon.icns")
property ScriptTitle : "Spotlight Meta Data for Items info"

set infoIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")

set idOfFrontApp to getfrontAppId()
set ReportText to ""
set failed to false
try
	
	tell application "Finder"
		activate
		set selected_items_list to (get selection) as alias list
		
		set selCount to count selected_items_list
		
		if selCount ≠ 0 then set last_item to the last item of the selected_items_list as text
		
		try
			set startPath to target of its Finder window 1 as alias
		on error
			set starpath to path to desktop folder
		end try
		
	end tell
	
	
	if selCount = 0 then
		tell application "SystemUIServer"
			activate
			try
				set the selected_items_list to (choose file with prompt "Choose the files or folders you want to see info for for" default location startPath with multiple selections allowed)
			on error
				set failed to true
			end try
		end tell
		
		set selCount to count selected_items_list
		if ((count of the selected_items_list) = 0) or failed then
			alertDialog({aTextMessage:"No files or applications are selected.", aTextTitle:my ScriptTitle, timeInSecs:300, btnAsList:{"Ok"}, iconAsFileRef:infoIcon, bundleIdOfFrontApp:idOfFrontApp})
			abortNicely({bundleIdFrontApp:idOfFrontApp})
		end if
		set last_item to the last item of the selected_items_list as text
		
	end if
	
	set failed to false
	tell application "SystemUIServer"
		activate
		try
			set outputType to button returned of (display dialog "Please choose form of output" with title ScriptTitle buttons {"Cancel", "Report", "Dialogs"} cancel button 1 default button 3 with icon genericIcon)
		on error
			set failed to true
		end try
	end tell
	if failed then abortNicely({bundleIdFrontApp:idOfFrontApp})
	
	repeat with this_item in the selected_items_list
		if outputType is "Dialogs" then
			set ReportText to ""
		end if
		tell application "Finder" to set item_name to name of this_item
		
		
		set filepath to quoted form of POSIX path of (this_item as alias)
		set metaList to metadataList for filepath
		
		if outputType is "Report" then
			set ReportText to ReportText & return & "==================================" & return & "Name: " & item_name & return
		else
			set ReportText to ReportText & return & "Name: " & item_name & return
		end if
		
		repeat with i from 1 to (count metaList)
			
			set ReportText to ReportText & item 1 of item i of my metaList & ": "
			if class of item 2 of item i of my metaList = list then
				set oltids to AppleScript's text item delimiters
				set AppleScript's text item delimiters to "\" , \""
				set tmpTxt to item 2 of item i of my metaList as text
				set AppleScript's text item delimiters to oltids
				set ReportText to ReportText & "{ \"" & tmpTxt & "\" }" & return
			else
				set ReportText to ReportText & item 2 of item i of my metaList & return
			end if
		end repeat
		
		
		if outputType is "Dialogs" then
			set the clipboard to ReportText
			if contents of this_item is the last_item or selCount is 1 then
				set the button_list to {"Done"}
			else
				set the button_list to {"Cancel", "Next"}
			end if
			-- display the information
			with timeout of 900 seconds
				tell application "SystemUIServer"
					activate
					
					display dialog ReportText with title ScriptTitle buttons the button_list default button (the last item of the button_list)
				end tell
			end timeout
		end if
	end repeat
	if outputType is "Report" then
		
		tell application "TextEdit"
			activate
			make new document at the front
			set text of front document to "F i l e   i n f o r m a t i o n " & return & ReportText
		end tell
	end if
on error e number N
	if not failed then
		alertDialog({aTextMessage:e & " " & N, aTextTitle:my ScriptTitle, timeInSecs:300, btnAsList:{"Ok"}, iconAsFileRef:infoIcon, bundleIdOfFrontApp:idOfFrontApp})
		abortNicely({bundleIdFrontApp:idOfFrontApp})
	end if
end try


to metadataList for pxFilepath
	--  mouramartins Macscripter.net http://macscripter.net/viewtopic.php?id=39249
	local rs, prs, k, islist, p, x, i, titem, litem, y, z
	
	set islist to false
	set rs to (do shell script "mdls " & pxFilepath)
	set prs to {}
	repeat with k from 1 to count of paragraphs of rs
		set p to paragraph k of rs
		if islist then
			if text 1 of p is ")" then
				set islist to false
				set end of titem to litem
				set end of prs to titem
			else
				set y to offset of "\"" in p
				set z to (text (y + 1) thru -1 of p)
				set y to offset of "\"" in z
				set p to (text 1 thru (y - 1) of z)
				set end of litem to p
			end if
		else -- it is a new item
			
			set i to offset of "=" in p
			if i > 1 then
				set titem to {}
				set x to (text 1 thru (i - 1) of p)
				-- clean up x
				set y to offset of " " in x
				set z to (text 1 thru (y - 1) of x)
				if islist then
					set end of litem to z
				else
					set end of titem to z
				end if
				if text (i + 2) of p = "(" then
					set litem to {}
					
					set islist to true
				else
					set x to text (i + 2) thru -1 of p as text
					
					set y to offset of "\"" in x
					if y > 0 then
						set z to (text (y + 1) thru -1 of x)
						set y to offset of "\"" in z
						if (y - 1) > 0 then
							set x to (text 1 thru (y - 1) of z)
						else
							set x to ""
						end if
					end if
					set end of titem to x
					set end of prs to titem
				end if
			end if
		end if
	end repeat
	return prs
end metadataList

on getfrontAppId() -- Returns bundleid of active app
	local frontappId
	set frontappId to ""
	tell application "System Events"
		set frontappId to bundle identifier of first application process whose frontmost is true
	end tell
	return frontappId
end getfrontAppId

on abortNicely(R) -- Returns Nothing
	
	tell application "System Events" to tell application process id (bundleIdFrontApp of R)
		key down control
		key code 118
		key up control
	end tell
	error number -128
end abortNicely

on alertDialog(R) -- Returns Nothing
	-- R : {aTextMessage:theMessage,aTextTitle:thetitle,timeInSecs:lenToTimeout,btnAsList:theButton,iconAsFileRef:theIcon,bundleIdOfFrontApp:frontappId}
	local res, failed, e, N
	set failed to false
	tell application "SystemUIServer"
		activate
		try
			if (iconAsFileRef of R) is null then
				set res to button returned of (display dialog (aTextMessage of R) with title (aTextTitle of R) giving up after (timeInSecs of R) buttons (btnAsList of R) default button 1)
			else
				set res to button returned of (display dialog (aTextMessage of R) with title (aTextTitle of R) giving up after (timeInSecs of R) buttons (btnAsList of R) default button 1 with icon (iconAsFileRef of R))
			end if
			if res = "" then set failed to true
		on error e number N
			set failed to true
			
		end try
	end tell
	if failed is true then
		abortNicely({bundleIdFrontApp:(bundleIdOfFrontApp of R)}) -- Returns Nothing
	end if
	return
end alertDialog

Hello!

I fixed it to show the content type tree.

Spotlight meta data is generic, so if you want to have all the properties returned I recommend using something like:

		
		set recIdList to get user property names metaRec
		
		log recIdList

From Late Night Software’s List&Record tools, to get the properties. Maybe AsobjC-Runner is capable of the same, for all I know!

Hello!

I am very happy to report that a pure AS handler, actually are capable of extracting the properites, (or convert the record to a list while retaining the keys!

The handler can be found Here! and is written by yiam-jin-qui

Hello!

I have updated the script in post #2 so it handles items selected from a Spotlight window.

Enjoy :slight_smile:

Hello!

I have reinforced the script in post #2 so the ui works better. :slight_smile:

Enjoy

I have updated the script in post #9 as well!

Hello.

Mavericks no longer contains the genericIcon I used in the script in post #9, so here is a script with an alternative.



-- http://macscripter.net/edit.php?id=154143
-- New faster way to create record by Nigel Garvey

-- http://macscripter.net/viewtopic.php?id=39265
--  SPOTLIGHT INFO FOR SELECTED ITEMS
-- PARTS ©1998 Sal Soghoian, Apple Computer
-- Parts © 2012 McUsr I'd rather have you referring to this post at Macscripter.net http://macscripter.net/edit.php?id=154116
-- than posting it elsewhere!
(*
	Compiled  By McUsr 09/08/12:
	Based upen INFO FOR SELECTED Items, uses mouramartins convert mdlsinfo (spotlight metadata to list).
	New code converts mdls info to a list directly
*)
property metaList : missing value
global genericIcon
property ScriptTitle : "Spotlight Meta Data for Items info"

set genericIcon to a reference to file ((path to library folder from system domain as Unicode text) & "CoreServices:CoreTypes.bundle:Contents:Resources:ToolbarInfo.icns")

set infoIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")

set idOfFrontApp to getfrontAppId()
set ReportText to ""
set failed to false
try
	
	tell application "Finder"
		activate
		set selected_items_list to (get selection) as alias list
		
		set selCount to count selected_items_list
		
		if selCount ≠ 0 then set last_item to the last item of the selected_items_list as text
		
		try
			set startPath to target of its Finder window 1 as alias
		on error
			set starpath to path to desktop folder
		end try
		
	end tell
	
	
	if selCount = 0 then
		tell application "SystemUIServer"
			activate
			try
				set the selected_items_list to (choose file with prompt "Choose the files or folders you want to see info for for" default location startPath with multiple selections allowed)
			on error
				set failed to true
			end try
		end tell
		
		set selCount to count selected_items_list
		if ((count of the selected_items_list) = 0) or failed then
			alertDialog({aTextMessage:"No files or applications are selected.", aTextTitle:my ScriptTitle, timeInSecs:300, btnAsList:{"Ok"}, iconAsFileRef:infoIcon, bundleIdOfFrontApp:idOfFrontApp})
			abortNicely({bundleIdFrontApp:idOfFrontApp})
		end if
		set last_item to the last item of the selected_items_list as text
		
	end if
	
	set failed to false
	tell application "SystemUIServer"
		activate
		try
			set outputType to button returned of (display dialog "Please choose form of output" with title ScriptTitle buttons {"Cancel", "Report", "Dialogs"} cancel button 1 default button 3 with icon genericIcon)
		on error
			set failed to true
		end try
	end tell
	if failed then abortNicely({bundleIdFrontApp:idOfFrontApp})
	
	repeat with this_item in the selected_items_list
		if outputType is "Dialogs" then
			set ReportText to ""
		end if
		tell application "Finder" to set item_name to name of this_item
		
		set filepath to quoted form of POSIX path of (this_item as alias)
		set metaRec to metaDataRecord for filepath
		set metaList to Rec2UserKeyValues(metaRec)
		if outputType is "Report" then
			set ReportText to ReportText & return & "==================================" & return & "Name: " & item_name & return
		else
			set ReportText to ReportText & return & "Name: " & item_name & return
		end if
		
		repeat with i from 1 to (count metaList)
			
			set ReportText to ReportText & item 1 of item i of my metaList & ": "
			if class of item 2 of item i of my metaList = list then
				set oltids to AppleScript's text item delimiters
				set AppleScript's text item delimiters to "\" , \""
				set tmpTxt to item 2 of item i of my metaList as text
				set AppleScript's text item delimiters to oltids
				set ReportText to ReportText & "{ \"" & tmpTxt & "\" }" & return
			else
				set ReportText to ReportText & item 2 of item i of my metaList & return
			end if
		end repeat
		
		
		if outputType is "Dialogs" then
			set the clipboard to ReportText
			if contents of this_item is the last_item or selCount is 1 then
				set the button_list to {"Done"}
			else
				set the button_list to {"Cancel", "Next"}
			end if
			-- display the information
			with timeout of 900 seconds
				tell application "SystemUIServer"
					activate
					
					display dialog ReportText with title ScriptTitle buttons the button_list default button (the last item of the button_list) with icon genericIcon
				end tell
			end timeout
		end if
	end repeat
	if outputType is "Report" then
		
		tell application "TextEdit"
			activate
			make new document at the front
			set text of front document to "F i l e   i n f o r m a t i o n " & return & ReportText
		end tell
	end if
on error e number N
	if not failed then
		alertDialog({aTextMessage:e & " " & N, aTextTitle:my ScriptTitle, timeInSecs:300, btnAsList:{"Ok"}, iconAsFileRef:infoIcon, bundleIdOfFrontApp:idOfFrontApp})
		abortNicely({bundleIdFrontApp:idOfFrontApp})
	end if
end try


on metaDataRecord for fp
	-- http://macscripter.net/edit.php?id=154143 NG
	-- Ensure that we have a quoted POSIX path to the file.
	if (fp's class is text) then
		if (fp does not start with "'/") then
			if (fp does not start with "/") then set fp to POSIX path of fp
			set fp to quoted form of fp
		end if
	else
		set fp to quoted form of POSIX path of (fp as alias)
	end if
	
	-- Get the metadata text and edit it almost to compilability. Mark date entries with unlikely tags.  ;)
	set rs to do shell script "mdls " & fp & " | sed -Ee 's| *=|:|' -e 's|^ +([^\"][a-zA-Z]*[^\"])$|\"\\1\"|' -e 's|\"?([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [+-][0-9]{4})\"?|<McUsr>\\1</McUsr>|' -e 's|\\($|{ ¬|' -e 's|^\\)|}|' -e 's|,$|, ¬|' -e 's|([^¬])$|\\1, ¬|'"
	
	if ((count rs) > 0) then
		-- Append braces for the record representation.
		set rs to "{" & text 1 thru -4 of rs & "}"
		
		set astid to AppleScript's text item delimiters
		-- Zap any stray commas at the ends of lists.
		set AppleScript's text item delimiters to ", ¬" & return & "}"
		set rs to rs's text items
		set AppleScript's text item delimiters to " ¬" & return & "}"
		set rs to rs as text
		-- Replace the ISO dates with AppleScript dates transposed to the computer's time zone and coerced to text as per the local preferences. Requires AS 2.1 (Snow Leopard) or later for the multiple TIDs.
		set AppleScript's text item delimiters to {"<McUsr>", "</McUsr>"}
		set rs to rs's text items
		repeat with i from 2 to (count rs) by 2
			set dateString to item i of rs
			set item i of rs to "date \"" & getASLocalDate(dateString) & "\""
		end repeat
		set AppleScript's text item delimiters to ""
		set rs to rs as text
		set AppleScript's text item delimiters to astid
		
		-- Return the "compiled" record.
		return (run script rs)
	else
		return {}
	end if
end metaDataRecord

-- Return a local AppleScript date from a given ISO date/time with time-zone displacement.
on getASLocalDate(ISODate)
	-- Get the ISO date/time as as AppleScript date object. (The date object will be reused for different purposes below to save multiple calls to 'current date'.)
	tell (current date) to set {day, {year, its month, day, its hours, its minutes, its seconds}, ASDate} to {1, words 1 thru 6 of ISODate, it}
	
	-- Subtract the time-zone displacement to transpose to GMT.
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to space
	tell (text item -1 of ISODate) as integer to set ASGMTDate to ASDate - (it div 100 * hours + it mod 100 * minutes)
	set AppleScript's text item delimiters to astid
	
	-- Subtract the Unix era start from the GMT date to get the number of seconds since then.
	tell ASDate to set {day, month, year, time} to {1, 1, 1970, 0}
	set eraTime to ASGMTDate - ASDate
	-- Coerce this figure to text in straight decimal notation.
	if (eraTime > 99999999) then
		set eraTime to (eraTime div 100000000 as text) & text 2 thru 9 of (100000000 + eraTime mod 100000000 as integer as text)
	else if (eraTime < -99999999) then
		set eraTime to (eraTime div 100000000 as text) & text 3 thru 10 of (-100000000 + eraTime mod 100000000 as integer as text)
	else
		set eraTime to eraTime as text
	end if
	
	-- Run the figure through "date" to get the corresponding machine-local date/time and convert to AS.
	do shell script ("date -r " & eraTime & " '+%Y %m %d %H %M %S'")
	tell ASDate to set {year, its month, day, its hours, its minutes, its seconds} to words of result
	
	return ASDate
end getASLocalDate

on getfrontAppId() -- Returns bundleid of active app
	local frontappId
	set frontappId to ""
	tell application "System Events"
		set frontappId to bundle identifier of first application process whose frontmost is true
	end tell
	return frontappId
end getfrontAppId

on abortNicely(R) -- Returns Nothing
	
	tell application "System Events" to tell application process id (bundleIdFrontApp of R)
		key down «constant epmdctlm»
		key code 118
		key up «constant epmdctlm»
	end tell
	error number -128
end abortNicely

on Rec2UserKeyValues(recAny)
	-- http://macscripter.net/viewtopic.php?id=36842 yiam-jin-qui
	-- USE THE CLIPBOARD TO MAKE THE RECORD KEYS LEGIBLE
	set the clipboard to recAny
	set recLegible to (the clipboard as record)
	set lngPairs to count of (recAny as list)
	if lngPairs < 1 then return {}
	
	-- COLLECT ANY USER-DEFINED KEY-VALUE PAIRS
	set lstKeyValue to {}
	try
		set lstUser to list of recLegible
	on error
		display dialog (do shell script "osascript -e 'the clipboard as record'") buttons "OK" default button 1 with title "Contents of record"
		return {}
	end try
	
	repeat with i from 1 to (length of lstUser) - 1 by 2
		set end of lstKeyValue to {item i of lstUser, item (i + 1) of lstUser}
	end repeat
	
	-- IF ANY PAIRS ARE MISSING, TRY SOME SYSTEM-DEFINED KEYNAMES
	if (count of lstKeyValue) < lngPairs then
		try
			set beginning of lstKeyValue to {"Date", date of recAny}
		end try
		try
			set beginning of lstKeyValue to {"Name", name of recAny}
		end try
	end if
	lstKeyValue
end Rec2UserKeyValues

on alertDialog(R) -- Returns Nothing
	-- R : {aTextMessage:theMessage,aTextTitle:thetitle,timeInSecs:lenToTimeout,btnAsList:theButton,iconAsFileRef:theIcon,bundleIdOfFrontApp:frontappId}
	local res, failed, e, N
	set failed to false
	tell application "SystemUIServer"
		activate
		try
			if (iconAsFileRef of R) is null then
				set res to button returned of (display dialog (aTextMessage of R) with title (aTextTitle of R) giving up after (timeInSecs of R) buttons (btnAsList of R) default button 1)
			else
				set res to button returned of (display dialog (aTextMessage of R) with title (aTextTitle of R) giving up after (timeInSecs of R) buttons (btnAsList of R) default button 1 with icon (iconAsFileRef of R))
			end if
			if res = "" then set failed to true
		on error e number N
			set failed to true
			
		end try
	end tell
	if failed is true then
		abortNicely({bundleIdFrontApp:(bundleIdOfFrontApp of R)}) -- Returns Nothing
	end if
	return
end alertDialog

Hello.

The script in post #2 also used the genericIcon.

--http://macscripter.net/post.php?tid=39265
-- INFO FOR SELECTED ITEMS
-- ©1998 Sal Soghoian, Apple Computer
(*
	Tinkered By McUsr 2010-04-02 :
	Changed it to take a selcection of files to display info of instead of the usual selection.
	McUsr 2010-07-23 
	Changed it to display a Report in TextEdit
	McUsr 2010-07-25 
	Changed it to have options of both report and dialog, and added the locked and comment property
	to the report.
		McUsr 2010-07-28 
	Added the default application property.
	to the report.

	Pastes all reports to the clipboard silently.
	If selcount > 0 gives info for selected items, else lets you choose.

	changed to return the location of the frontmost finder window.
	added nice icon 
*)
property scriptTitle : "Info for Selected Items"

local genericaIcon, infoIcon

set infoIcon to a reference to file ((path to library folder from system domain as text) & "CoreServices:CoreTypes.bundle:Contents:Resources:AlertNoteIcon.icns")
set genericIcon to a reference to file ((path to library folder from system domain as Unicode text) & "CoreServices:CoreTypes.bundle:Contents:Resources:ToolbarInfo.icns")
set idOfFrontApp to getfrontAppId()
set ReportText to ""
set failed to false
try
	
	tell application "Finder"
		activate
		set selected_items_list to (get selection) as alias list
		
		set selCount to count selected_items_list
		
		if selCount ≠ 0 then set last_item to the last item of the selected_items_list as text
		--  det er alltid et finder window og det er desktop
		try
			set startPath to target of its Finder window 1 as alias
		on error
			set starpath to path to desktop folder
		end try
	end tell
	
	
	if selCount = 0 then
		tell application "System Events"
			activate
			try
				set the selected_items_list to (choose file with prompt "Choose the files or folders you want to see info for for" default location startPath with multiple selections allowed)
			on error
				set failed to true
			end try
		end tell
		if ((count of the selected_items_list) = 0) or failed then
			alertDialog({aTextMessage:"No files or applications are selected.", aTextTitle:my scriptTitle, timeInSecs:300, btnAsList:{"Ok"}, iconAsFileRef:infoIcon, bundleIdOfFrontApp:idOfFrontApp})
			abortNicely({bundleIdFrontApp:idOfFrontApp})
		end if
		set last_item to the last item of the selected_items_list as text
	end if
	
	tell application "SystemUIServer"
		activate
		try
			set outputType to button returned of (display dialog "Please choose form of output" with title scriptTitle buttons {"Cancel", "Report", "Dialogs"} cancel button 1 default button 3 with icon genericIcon)
		on error
			set failed to true
		end try
	end tell
	if failed then abortNicely({bundleIdFrontApp:idOfFrontApp})
	
	repeat with this_item in the selected_items_list
		if outputType is "Dialogs" then
			set ReportText to ""
		end if
		tell application "Finder"
			
			set this_item to this_item as text
			-- get the information for the item
			
			set item_info to info for alias this_item
			set item_kind to kind of alias this_item
			set item_comment to comment of alias this_item
			if locked of alias this_item is true then
				set locked_indicator to "True"
			else
				set locked_indicator to "False"
			end if
			set duti to type identifier of item_info
			-- extract the various properties from the stored list
			set item_name to name of item_info
			set file_type to file type of item_info
			set item_creator to file creator of item_info
			set item_size to size of item_info
			set item_creation_date to the creation date of item_info
			set item_modification_date to the modification date of item_info
			set item_version to short version of item_info
			set item_owner to owner of item this_item
			set item_ownerP to owner privileges of item this_item
			set item_group to group of item this_item
			set item_groupP to group privileges of item this_item
			set item_everyonesP to everyones privileges of item this_item
			-- convert the true or false value to text
			set alias_indicator to alias of item_info
			if alias_indicator is true then
				set alias_indicator to "True"
			else
				set alias_indicator to "False"
			end if
		end tell
		tell application "System Events"
			set finfo to properties of item this_item
			
			set ftype to type identifier of finfo
			set defApp to name of default application of finfo
		end tell
		if outputType is "Report" then
			set ReportText to ReportText & return & "==================================" & return & "Name: " & item_name & return
		else
			set ReportText to ReportText & return & "Name: " & item_name & return
		end if
		set ReportText to ReportText & "Pathname: " & POSIX path of (this_item as alias) & return
		set ReportText to ReportText & "Kind: " & item_kind & return
		set ReportText to ReportText & "Comment: " & item_comment & return
		set ReportText to ReportText & "File Type: " & file_type & return
		set ReportText to ReportText & "Creator Code: " & item_creator & return
		set ReportText to ReportText & "UTI: " & ftype & return
		set ReportText to ReportText & "Default Application: " & defApp & return
		
		set ReportText to ReportText & "Size: " & item_size & return
		set ReportText to ReportText & "Version: " & item_version & return
		set ReportText to ReportText & "Alias: " & alias_indicator & return
		set ReportText to ReportText & "Cdate: " & item_creation_date & return
		set ReportText to ReportText & "Mdate: " & item_modification_date & return
		set ReportText to ReportText & "Owner: " & item_owner & return
		set ReportText to ReportText & "Owner Privileges: " & item_ownerP & return
		set ReportText to ReportText & "Group: " & item_group & return
		set ReportText to ReportText & "Group Privileges: " & item_groupP & return
		set ReportText to ReportText & "Everybodys Privileges: " & item_everyonesP & return
		set ReportText to ReportText & "Locked: " & locked_indicator & return
		if outputType is "Dialogs" then
			set the clipboard to ReportText
			if this_item is the last_item then
				set the button_list to {"Done"}
			else
				set the button_list to {"Cancel", "Next"}
			end if
			-- display the information
			with timeout of 900 seconds
				tell application "SystemUIServer"
					activate
					display dialog ReportText with title scriptTitle buttons the button_list default button (the last item of the button_list) with icon genericIcon
				end tell
			end timeout
		end if
	end repeat
	if outputType is "Report" then
		
		tell application "TextEdit"
			activate
			make new document at the front
			set text of front document to "F i l e   i n f o r m a t i o n " & return & ReportText
		end tell
	end if
	
on error e number n
	if not failed then
		alertDialog({aTextMessage:e & " " & n, aTextTitle:my scriptTitle, timeInSecs:300, btnAsList:{"Ok"}, iconAsFileRef:infoIcon, bundleIdOfFrontApp:idOfFrontApp})
		abortNicely({bundleIdFrontApp:idOfFrontApp})
	end if
end try

on getfrontAppId() -- Returns bundleid of active app
	local frontappId
	set frontappId to ""
	tell application "System Events"
		set frontappId to bundle identifier of first application process whose frontmost is true
	end tell
	return frontappId
end getfrontAppId

on abortNicely(r) -- Returns Nothing
	
	tell application "System Events" to tell application process id (bundleIdFrontApp of r)
		key down «constant epmdctlm»
		key code 118
		key up «constant epmdctlm»
	end tell
	error number -128
end abortNicely

on alertDialog(r) -- Returns Nothing
	-- R : {aTextMessage:theMessage,aTextTitle:thetitle,timeInSecs:lenToTimeout,btnAsList:theButton,iconAsFileRef:theIcon,bundleIdOfFrontApp:frontappId}
	local res, failed, e, n
	set failed to false
	tell application "SystemUIServer"
		activate
		try
			if (iconAsFileRef of r) is null then
				set res to button returned of (display dialog (aTextMessage of r) with title (aTextTitle of r) giving up after (timeInSecs of r) buttons (btnAsList of r) default button 1)
			else
				set res to button returned of (display dialog (aTextMessage of r) with title (aTextTitle of r) giving up after (timeInSecs of r) buttons (btnAsList of r) default button 1 with icon (iconAsFileRef of r))
			end if
			if res = "" then set failed to true
		on error e number n
			set failed to true
			
		end try
	end tell
	if failed is true then
		abortNicely({bundleIdFrontApp:(bundleIdOfFrontApp of r)}) -- Returns Nothing
	end if
	return
end alertDialog