Re: Rep: sort with do Shell script
Re: Rep: sort with do Shell script
- Subject: Re: Rep: sort with do Shell script
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 5 May 2010 07:53:05 -0400
In at least SL and possibly Leopard, you can skip the "open for
access" step and just do
write (unsortedList as text) to (fileRef)
but Yvan is on Tiger.
Either way, the trick is getting that fileRef to a nonexistent file.
On Wednesday, May 5, 2010, Thomas Fischer <email@hidden> wrote:
> 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 fileHandleon error err display dialog "Problem: " & errend 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 1on error err display dialog "Problem: " & errend 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
>
--
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