• 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: Rick Gordon <email@hidden>
  • Date: Tue, 09 Jul 2013 00:47:58 -0700

Title: Re: Passing Return-Delimited Text to UNIX Sort
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:
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: Thomas Fischer <email@hidden>
    • Re: Passing Return-Delimited Text to UNIX Sort
      • From: Christopher Stone <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