Re: Passing Return-Delimited Text to UNIX Sort
Re: Passing Return-Delimited Text to UNIX Sort
- Subject: Re: Passing Return-Delimited Text to UNIX Sort
- From: Rick Gordon <email@hidden>
- Date: Tue, 09 Jul 2013 14:12:41 -0700
Title: Re: Passing Return-Delimited Text to UNIX
Sort
Thanks to Thomas and Chris for your on-the-mark comments.
Regarding the suggestion to use paragraphs rather than text
items, that didn't seem to work for me. I was working within the tell
block of the InDesign application, but I had called out that line with
either tell
me or tell
AppleScript, but in any case, sill got the ending line feed. So
I just went with ...
set vSortedNameList to text
items 1 thru -2
of
vSortedText
... and that worked fine. Thanks again.
Rick Gordon
------------------
On 7/9/13 at 5:08 PM +0200, Thomas Fischer wrote in a message
entitled
"Re: Passing Return-Delimited Text to UNIX Sort":
Hi Rick,
just some additional
remarks:
1. "ASCII character 10" is
deprecated since it doesn't respect Unicode, "character id 10"
would be correct, but there is also a constant linefeed with the same
value, so you might use that to make the script more
readable.
2. set vBookChapterNameText to (text items of vBookChapterNameList) as string
is somewhat strange: you
take the text apart at every line break and then glue it together with
line breaks.
Thus nothing is changed. If
you want to allow for different kinds of paragraph separators you
could do
set
vBookChapterNameText to (paragraphs of vBookChapterNameList)
as string
3. As Chris mentioned, "without
altering line endings" will give you an extra empty line at the
end,
set
vSortedNameList to text items 1 thru -2 of ¬
(do
shell script "echo " & quoted form of
vBookChapterNameText & " | sort" without altering line
endings)
would
take care of that.
4. set my text item delimiters to
{""} isn't necessary unless you are using text items in
the rest of the script.
Best
Thomas
Am 09.07.2013 um 09:47 schrieb Rick
Gordon:
AT FIRST, IT THOUGHT:
The additional wrinkle that was needed
was that I needed to delimit with the linefeed to run the shell
script, but then I needed to get the text items of the returned text
from the script delimited with a return, or else I'd only get a
one-item list.
set my text item delimiters to ASCII
character 10
set vBookChapterNameText to (text items of vBookChapterNameList) as string
set my text item delimiters to return --needed to reconvert to list; otherwise it's
truncated.
set vSortedNameList to text items of (do shell script "echo " & quoted form of vBookChapterNameText & " | sort")
set my text item delimiters to {""}
set vChosen to choose from list vSortedNameList with prompt "Open one or more chapters from
THOM." with multiple selections
allowed
BUT THEN I SAW:
... that if I added without altering line endings to the do shell
script command that that wasn't necessary.
Two lessons learned.
Rick Gordon
------------------
On 7/9/13 at 12:45 AM -0500, Christopher
Stone wrote in a message entitled
"Re: Passing Return-Delimited Text
to UNIX Sort":
On Jul 09, 2013, at 00:19, Rick Gordon <email@hidden>
wrote:
For instance, if I have compiled an
unsorted list of strings, and then coerced that into a string of text
lines separated by a return, how can I pass that to the UNIX sort
command?
______________________________________________________________________
Hey Rick,
The shell doesn't do returns. It understands linefeeds (Unix),
so you need to delimit with linefeeds in the first place or pipe
through 'tr'.
set AppleScript's text item delimiters to
return
set _var to quoted form of
(characters of "zyx" as text)
do shell script "echo "
& _var & " | tr '\\r' '\\n' | sort"
If you haven't already it's a good idea
to read through Tech-Note TN2065:
http://developer.apple.com/library/mac/#technotes/tn2065/_index.html
--
Best Regards,
Chris
--
___________________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________
WWW: http://www.shelterpub.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
@aon.at
Archives: http://lists.apple.com/archives/applescript-users
This email sent to 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:
>kgordon.com
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
--
___________________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________
WWW: http://www.shelterpub.com
_______________________________________________
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