Re: Getting Info from the Finder
Re: Getting Info from the Finder
- Subject: Re: Getting Info from the Finder
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 20 May 2010 10:28:07 -0400
Well, you're already calling do shell script and having the shell
fork() and exec() a third executable (mdls); at this point your
efficiency is pretty much shot. It would be better to run mdls just
once for all the files you care about (or at least, only a few times,
with a lot of filename arguments each time) and then separate the
output appropriately (including the ItemName in the list of output
fields would help on that front).
On Thu, May 20, 2010 at 9:57 AM, Thomas Fischer <email@hidden> wrote:
> Hi Mark,
>
>> 1. Did you see my Python solution? I think it will work for you.
>
> Yes, it will work. But I don't really want to involve additional languages.
> It requires some minor adjustments ahead (e.g. it needs \u instead of \U) but the it will work:
>
> set myFile to alias "Macintosh HD:SUB:ELibM:ELibM-2010-04-07:elibm1:BSPM:Volume25_1-2:7421_4265.pdf"
> set myFile to choose file
> set myInfo to do shell script "mdls -raw -name kMDItemCreator -name kMDItemEncodingApplications " & (quoted form of (POSIX path of myFile))
> --> " TeX output 2008.01.24:1119(\r \"dvipdfm 0.13.2c, Copyright \\U00a9 1998, by Mark A. Wicks\"\r)"
>
> You can see this:
>
> set myInfo to " TeX output 2008.01.24:1119, Producer: (\r \"dvipdfm 0.13.2c, Copyright \\u00a9 1998, by Mark A. Wicks\"\r)"
> set myInfo to change "\\s*([()])\\s*" into "\\1" in myInfo with regexp # get rid of unnecessary whitespace (line breaks!)
> set myInfo to change "\\U" into "\\u" in myInfo # change \U into \u
> set myInfo to change character id 0 into ", Producer: " in myInfo # get rid of \x00, prevents evaluation
> do shell script "python <<EOF \nprint u" & quoted form of myInfo & ".encode('utf-8')"
> --> " TeX output 2008.01.24:1119, Producer:(\"dvipdfm 0.13.2c, Copyright © 1998, by Mark A. Wicks\")"
>
> But I didn't test the overhead of calling Python thousands of times.
>
>> 2. Bash is outputting a '?' because it thinks your terminal can only
>> handle ASCII. You could try setting LC_ALL to a UTF-8 locale (e.g.
>> "en_US.UTF-8" for US English) and see if that helps that case.
>
> I changed to "de_DE.UTF-8", but the printf command remains unchanged.
>
> But thanks for the hints.
>
> Thomas
>
>
>
>> On Thursday, May 20, 2010, Thomas Fischer <email@hidden> wrote:
>>> Hi Mark any Tommy,
>>>
>>> Am 19.05.2010 um 17:42 schrieb Mark J. Reed:
>>>
>>>> On Wed, May 19, 2010 at 11:09 AM, Thomas Fischer <email@hidden> wrote:
>>>>> Hi Mark,
>>>>> I didn't find any way to evaluate \U00A9 directly, but at least I can
>>>>> convert from hex number X to decimal number Z using
>>>>> do shell script ("printf \"%d\" 0x" & X)
>>>>> Unfortunately, printf seams to be completely unaware not only of Unicode,
>>>>> but of any characters beyond ASCII 127:
>>>>> e.g.
>>>>> printf "%b" "\x7e" -> ~
>>>>> but
>>>>> printf "%b" "\xe4" -> ?
>>>>
>>>> Well, that outputs exactly what you asked for - the one-byte value
>>>> 0xe4.
>>>
>>> I would expect
>>> printf "%b" "\x3f" -> ?
>>>
>>> the sign "?" as indicator for non identified character is a little problematic.
>>>
>>>> Which would work if you were using a one-byte character set
>>>> like Latin-1 or MacRoman. But for Unicode it doesn't work.
>>>
>>> I think it is a sign of shortcomings on the side of the shell.
>>> If my text editor required to type "ä" every time I need an "ä", I would discard it quickly.
>>> But this is exactly what the shell does:
>>> printf "%b" "\xC3\xA4" -> ä
>>> There are other shells, which behave better, e.g. the Z shell zsh:
>>> printf "%b" "\u00E4\n" -> ä
>>>
>>> (Without the \n zsh creates some very strange output, something like dozens of spaces stacked on top of each other.)
>>> or for that matter even easier:
>>> print "\u00E4" -> ä
>>> You can obtain this result from the standard shell using e.g.
>>> echo 'print \"TeX \\U00A9 output 2008.01.24\"'|zsh ->
>>> "TeX © output 2008.01.24"
>>> So I thought I was home free, but alas:
>>> do shell script "echo 'print \"TeX \\U00A9 output 2008.01.24\"'|zsh" ->
>>> "TeX "
>>> Everything from the \U00A9 onward vanishes!
>>>
>>> So I keep on looking for better solutions.
>>> Tommy's hint didn't seem to work for me.
>>>
>>> Thomas-
>> Mark J. Reed <email@hidden>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden