• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Passing Return-Delimited Text to UNIX Sort
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing Return-Delimited Text to UNIX Sort


  • Subject: Re: Passing Return-Delimited Text to UNIX Sort
  • From: Thomas Fischer <email@hidden>
  • Date: Tue, 09 Jul 2013 17:08:53 +0200

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

--
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

  • Follow-Ups:
    • Re: Passing Return-Delimited Text to UNIX Sort
      • From: Shane Stanley <email@hidden>
    • Re: Passing Return-Delimited Text to UNIX Sort
      • From: Rick Gordon <email@hidden>
References: 
 >Re: Passing Return-Delimited Text to UNIX Sort (From: Rick Gordon <email@hidden>)

  • Prev by Date: Re: Passing Return-Delimited Text to UNIX Sort
  • Next by Date: Re: Passing Return-Delimited Text to UNIX Sort
  • Previous by thread: Re: Passing Return-Delimited Text to UNIX Sort
  • Next by thread: Re: Passing Return-Delimited Text to UNIX Sort
  • Index(es):
    • Date
    • Thread