• 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: read a specific word of a text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read a specific word of a text file


  • Subject: Re: read a specific word of a text file
  • From: Michelle Steiner <email@hidden>
  • Date: Wed, 22 Sep 2004 23:39:24 -0700


On Sep 22, 2004, at 11:12 PM, Jasneet Kaur wrote:

I need to read a specific word of a text file (in Mac's text editor) and
then replace it with another word.


(that is, the kind of action we do with the "Replace All" option in notepad
when using windows)


So could you please help me do that using AppleScript.

Here is one way.

set x to text returned of (display dialog "what word do you wish to replace?" default answer "")
set y to text returned of (display dialog "what word do you wish to replace it with?" default answer "")
set foo to open for access (choose file) with write permission
set bar to read foo
set {tid, text item delimiters} to {text item delimiters, x}
set barlist to text items of bar
set text item delimiters to y
set z to barlist as text
set text item delimiters to tid
set eof of foo to 0
write z to foo
close access foo


--
"Colorless green ideas sleep furiously."

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


References: 
 >read a specific word of a text file (From: Jasneet Kaur <email@hidden>)

  • Prev by Date: read a specific word of a text file
  • Next by Date: read a specific word of a text file
  • Previous by thread: read a specific word of a text file
  • Next by thread: Re: read a specific word of a text file
  • Index(es):
    • Date
    • Thread