• 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: Rep: sort with do Shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rep: sort with do Shell script


  • Subject: Re: Rep: sort with do Shell script
  • From: Thomas Fischer <email@hidden>
  • Date: Wed, 5 May 2010 10:46:32 +0200

Hello,


But there is a straightforward shell solution: simply write the list out to a file and then sort that:

set sortedList to paragraphs of (do shell script "sort -n -u " & quoted form of POSIX path of someFile)

(The annoying part of that solution, IMO, is the actual writing to a file, which is just far more work in AS than it seems like it should be.  open for access, set eof, aliases vs files vs file specifications vs furls...)

I agree on both counts: for long lists writing data to a file is the only way to hand it over to the Unix system (or is there a direct way to put it into a Unix variable, like declaring an AppleScript variable visible to the Unix system?).
And writing files is extremely awkward in AppleScript. I tried the "write" command (ASLG p. 168), but failed: it seems that it can't write to a file before the file actually exits. That looks like a bug to me.
There should be a more direct way to write intermediate data to a file than

set theText to "Hello World"
set fileRef to ((path to temporary items) as text) & "tempFile.txt"
try
set fileHandle to open for access fileRef with write permission
set eof fileHandle to 0
write theText to fileHandle as «class utf8» starting at 0
close access fileHandle
on error err
display dialog "Problem: " & err
end try

If the file already exists and you want to use the same file over again, something like

set theText to "Hello World"
set fileRef to ((path to temporary items) as text) & "tempFile.txt"
try
set eof of file fileRef to 0
write theText to file fileRef as «class utf8» starting at 1
on error err
display dialog "Problem: " & err
end try

would work too, but you have to make sure that the file remains where it is, so the temp folder should be replaced by a place more stable.

Thomas

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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: Rep: sort with do Shell script
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Rep: sort with do Shell script (From: Yvan KOENIG <email@hidden>)
 >Re: Rep: sort with do Shell script (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Transmit 3 "on open" vs "choose file" problem
  • Next by Date: Re: Rep: sort with do Shell script
  • Previous by thread: Re: Rep: sort with do Shell script
  • Next by thread: Re: Rep: sort with do Shell script
  • Index(es):
    • Date
    • Thread