Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: A script to view Spotlight metadata in text files System 10.4
Tiger only hintWhen reading this hint, I realised that to read the metadata of a file(s), I did not always want to go to the Terminal or open the clumsy Get Info window.

So here is a simple script to get the selected file(s) metadata, and open them in a text file. It can be used with most hotkey apps to make it usable via keyboard shortcut:
(* This script will open any selected file/s in finder and do a shell 
   script "mdls" to get the metadata of the file/s, and display the result
   in a Texedit document for each file *)

tell application "Finder"
  set miTem to selection
  repeat with i from 1 to number of items in miTem
    set this_item to item i of miTem as string
    set this_item to POSIX path of this_item
    do shell script "mdls " & quoted form of this_item & " | open -f"
     
  end repeat
end tell
[robg adds: I tested this one, and it works as described...]
    •    
  • Currently 2.50 / 5
  You rated: 5 / 5 (4 votes cast)
 
[13,052 views]  

10.4: A script to view Spotlight metadata in text files | 7 comments | Create New Account
Click here to return to the '10.4: A script to view Spotlight metadata in text files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: A script to view Spotlight metadata in text files
Authored by: DougAdams on Jun 14, '05 10:41:39AM

Nice one, Mark ;)

---
Doug's AppleScripts for iTunes
http://www.dougscripts.com/itunes/



[ Reply to This | # ]
10.4: A script to view Spotlight metadata in text files
Authored by: mark hunte on Jun 14, '05 02:22:18PM

Hey Thanks Doug,
And your script ABOVE mine ( http://www.macosxhints.com/article.php?story=20050614071122965 ) helped me figure out how to set the comment without pasting into the info window.

I submitted a script hint to get the contents of AppleScripts file/s and put it into the Spotlight comments, so I could find the parts in a script I wanted to refer toas must times I can not remember the name of the file/s.

Not sure if it will show up here but if it does I will have to update it.

So Thanks

---
mh



[ Reply to This | # ]
10.4: A script to view Spotlight metadata in text files
Authored by: ever on Jun 14, '05 09:11:26PM
That is a great script. I had submitted an as-yet unpublished script a few weeks ago that does something vaguely similar. If a file has one or more URLs associated to it, this script presents them in a dialog, and clicking a link opens it in Safari:

try
	tell application "Finder"
		set theFile to selection as alias
		set theFile to POSIX path of theFile
	end tell
	set AppleScript's text item delimiters to "\""
	set theInfo to (do shell script "mdls -name kMDItemWhereFroms " & theFile)
	set url1 to (text item 2 of theInfo) as text
	set url2 to (text item 4 of theInfo) as text
	set theURLs to {url1, url2}
	set theURL to (choose from list theURLs) as string
	if theURL is not "false" then
		tell application "Safari"
			make new document at end of documents
			set URL of document 1 to theURL
		end tell
	end if
	set AppleScript's text item delimiters to ""
end try


[ Reply to This | # ]
Oops...
Authored by: ever on Jun 14, '05 09:15:58PM
Now I see why that was probably never posted! In comparing with your script, I can see now that if its missing "quoted form of" then the script might break. So make that:

try
	tell application "Finder"
		set theFile to selection as alias
		set theFile to POSIX path of theFile
	end tell
	set AppleScript's text item delimiters to "\""
	set theInfo to (do shell script "mdls -name kMDItemWhereFroms " & quoted form of theFile)
	set url1 to (text item 2 of theInfo) as text
	set url2 to (text item 4 of theInfo) as text
	set theURLs to {url1, url2}
	set theURL to (choose from list theURLs) as string
	if theURL is not "false" then
		tell application "Safari"
			make new document at end of documents
			set URL of document 1 to theURL
		end tell
	end if
	set AppleScript's text item delimiters to ""
end try


[ Reply to This | # ]
Oops...
Authored by: mark hunte on Jun 15, '05 07:53:18PM

Hey, Nice script too, I like that a lot..

---
mh



[ Reply to This | # ]
10.4: A FINDER PLUG-IN to view Spotlight metadata
Authored by: aribn on Jun 15, '05 10:39:43AM
Here is something similar, packaged as a Automator-based plugin for the Finder.

View all metadata for selected files.workflow
Instructions, screenshots, and the download are available there.

Right-click on files, and you can access metadata through a contextual menu item. The results show up in Terminal windows (one per file.) Check out the screenshots...


[ Reply to This | # ]
10.4: A script to view Spotlight metadata in text files
Authored by: jporten on Jun 18, '05 07:23:45PM
Liked the script. Didn't like that TextEdit wrapped the resulting windows. Modified the script so it resizes each window as it is opened. (Note: if your default editor is NOT TextEdit, well, don't use this.)

tell application "Finder"
	set miTem to selection
	repeat with i from 1 to number of items in miTem
		set this_item to item i of miTem as string
		set this_item to POSIX path of this_item
		do shell script "mdls " & quoted form of this_item & " | open -f"
		tell application "TextEdit"
			set currBounds to bounds of window 1
			set item 3 of currBounds to ((item 3 of currBounds) + 150)
			set bounds of window 1 to currBounds
		end tell
	end repeat
end tell


[ Reply to This | # ]