• 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: Creating/saving/appending to files the Cocoa way
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating/saving/appending to files the Cocoa way


  • Subject: Re: Creating/saving/appending to files the Cocoa way
  • From: Robert DuToit <email@hidden>
  • Date: Mon, 18 Jan 2010 07:28:58 -0500

Hi Bill,

On Jan 17, 2010, at 11:20 PM, Bill Hernandez wrote:

> On Jan 17, 2010, at 7:47 PM, Robert DuToit wrote:
>
>> set somestring to "stat info"
>> set filePath to (POSIX path of (path to desktop)) & "newfile.txt"
>> set oldtext to do shell script "cat " & quoted form of filePath
>> set newtext to oldtext & tab & somestring
>> do shell script "echo " & newtext & " >" & quoted form of filePath
>
> Look at the five examples below
>
> Using Bash all you need to replace the five lines is :
>
> $ echo -n $'\t'hello >> ~/Desktop/hello.txt

Yes it is much simpler from command line but I am using "do shell script."

>
>
>> Craig, I used just the '>>' in my case but since he wanted a tab delineated string I appended the new string to the old one first so the new text is not on a new line. Though there is a simple way to avoid the new line with echo, I think.
>
> Robert,
>
> ( 1 ) echo -n whatever >> ~/Desktop/hello.txt
> the -n prevents a newline from being added to the end of the echo argument
>
> $ echo -n hello >> ~/Desktop/hello.txt
> $ echo -n hello >> ~/Desktop/hello.txt
> $ echo -n hello >> ~/Desktop/hello.txt
>
> ---> hellohellohello
>
> ( 2 ) we can easily add a space by using quotes around the text
>
> $ echo -n "hello " >> ~/Desktop/hello.txt
> $ echo -n "hello " >> ~/Desktop/hello.txt
> $ echo -n "hello " >> ~/Desktop/hello.txt
>
> ---> hello hello hello
>
>
> ( 3 ) adding \t converts the output to t which is not what you want.
>
> $ echo -n \thello >> ~/Desktop/hello.txt
> $ echo -n \thello >> ~/Desktop/hello.txt
> $ echo -n \thello >> ~/Desktop/hello.txt
>
> ---> thellothellothello
>
> ( 4 ) we CAN add a tab character by using $'\t'
>
> $ echo -n $'\t'hello >> ~/Desktop/hello.txt
> $ echo -n $'\t'hello >> ~/Desktop/hello.txt
> $ echo -n $'\t'hello >> ~/Desktop/hello.txt
>
> ---> 	hello	hello	hello
>
> ( 5 ) we can add THREE tab characters by using $'\t\t\t'
>
> echo -n $'\t\t\t'hello >> ~/Desktop/hello.txt
> echo -n $'\t\t\t'hello >> ~/Desktop/hello.txt
> echo -n $'\t\t\t'hello >> ~/Desktop/hello.txt
>
> ---> 			hello			hello			hello
>
> ( 6 ) However, AppleScript does not like the -n switch


Yes - I am using applescript and tried '-n' but it didn't work. I couldn't find any way to do it simply while using "do shell script."

But I am not that unix savvy and this is a good reminder for echo.

Thanks, Rob


>
> set somestring to "stat info"
> set filePath to do shell script "echo ~/Desktop/hello.txt"
> do shell script "echo -n $'\\t' " & somestring & " >> " & quoted form of filePath
> do shell script "echo -n $'\\t' " & somestring & " >> " & quoted form of filePath
>
> ---> -n 	 stat info
> ---> -n 	 stat info
>
> Bill Hernandez
> Plano, Texas
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> applescriptobjc-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Creating/saving/appending to files the Cocoa way (From: Shane Stanley <email@hidden>)
 >Re: Creating/saving/appending to files the Cocoa way (From: Robert DuToit <email@hidden>)
 >Re: Creating/saving/appending to files the Cocoa way (From: Bill Hernandez <email@hidden>)

  • Prev by Date: Re: NSSavePanel oddity
  • Next by Date: Re: Creating/saving/appending to files the Cocoa way
  • Previous by thread: Re: Creating/saving/appending to files the Cocoa way
  • Next by thread: Re: Creating/saving/appending to files the Cocoa way
  • Index(es):
    • Date
    • Thread