Hi everyone.
I’m trying to study AppleScript of Leopard, special with Spotlight.
For example, reading spot tag of a AAC file, this command
set kMDtags to paragraphs of (do shell script "mdls " & quoted form of POSIX path of this_item & " | grep 'kMDItemAuthors'")
display dialog kMDtags as string
give me the right Author in Tiger, but give me empty on Leopard.
I’ve take a look to full result of mdls command and I’ve seen that the author is between parenthesis (not in Tiger, I remember)
So, here you are my questions.
How to ghange the command for to bring the Authors of AAC in Leopard?
How to know if the script is running on Tiger or Leopard?
Thx for everyone in advance
Model: iMac 2007
AppleScript: 2.2
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.8) Gecko/20071010 Camino/1.5.2
Operating System: Mac OS X (10.5)
.
set kMDtags to (do shell script "mdls -name kMDItemAuthors " & quoted form of POSIX path of this_item)
set {TID, text item delimiters} to {text item delimiters, quote}
set kMDtags to text item 2 of kMDtags
set text item delimiters to TID
display dialog kMDtags
.
set sysV to ((system attribute "sysv") mod 4096 div 16)
if sysV = 5 then
-- it is Leopard
else if sysV = 4 then
-- it is Tiger
else
-- it is vintage ;)
end if
set this_item to choose file without invisibles -- example
do shell script "/usr/bin/mdls -name kMDItemAuthors " & ¬
quoted form of POSIX path of this_item & ¬
" | /usr/bin/sed -e 's/^ *\"//g; s/\"$//g'"
set kMDtags to paragraph 2 of result
display dialog kMDtags
Alternatively (are multiple authors possible?):
set this_item to choose file without invisibles -- example
do shell script "/usr/bin/mdls -name kMDItemAuthors " & ¬
quoted form of POSIX path of this_item & ¬
" | /usr/bin/sed -e 's/^ *\"//g; s/\"$//g'"
set kMDtags to paragraphs 2 thru -2 of result
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ", "
set kMDtags to "" & kMDtags
set AppleScript's text item delimiters to ASTID
display dialog kMDtags
Stefan covered this, but I’ll mention that you could also consider checking the AppleScript version.
version of AppleScript -- At least "2.0" for Leopard