| MacTalk Forums |
| Mac OS X Discussion and support on Mac OS X. If you have an issue with an application (e.g: Safari, or iPhoto, or Adium), it goes in the Applications forum. |
| Reply |
|
|
LinkBack | Thread Tools | Display Modes |
| MacTalk Forums |
| Mac OS X Discussion and support on Mac OS X. If you have an issue with an application (e.g: Safari, or iPhoto, or Adium), it goes in the Applications forum. |
| Reply |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
HI there,
I want to extract keywords from a CSV file to a text file, and in turn to put all the keywords in the text file to spotlight comment. One line from applescript is: do shell script "echo " & quoted form of formatted_keyword & ">>" & text_file where formatted_keyword = the individuals keywords and text_file is the filename of the output file. However, it seems like the applescript I'm fiddling with insert the keyword with "return key" in between, so the text file is something like: *blank with return keystoke* &KeywordA &KeywordB &KeywordC &KeywordD Is it possible to convert this textfile with applescript to become something like this: &KeywordA &KeywordB &KeywordC &KeywordD I just started learning applescript few days ago, so I'm sorry if this is a stupid straight-forward question. P.S. do shell script "echo " & quoted form of formatted_keyword & ">>" & text_file Cheers, Chris |
|
|||
|
I'm no Applescript user kurisu but I remember seeing a part of Apples forums ( Apple-Support-Discussions ) had a dedicated Applescript page...
Apple - Support - Discussions - AppleScript Maybe post this question there and I am sure one of the gurus would be able to post some info for you. Stewie
__________________
Lotsa Macs - PM's , G3's , G4's & Powerbooks - Love 'em ---------------- Painless trades : William , Clockwork , Brains, Applecollector, Simo, TimWallG5, ric3am, JMD , Forgie, Avolve, Zen, Mctastic, iCant Freebies from : Clockwork, TimRyan twice, Asphotos twice , DebB , Avolve , Froggy, Bee-J , Stepandy, Hoony |
|
|||
|
__________________
On the whole, I'd rather be in Philadelphia ... |
|
||||
|
Personally I'm fairly limited with AppleScript, I almost always use bash scripts (they run in the Terminal without need for AppleScript). Here's a script that will convert all line-endings to spaces in a text file:
#!/bin/bash TEXTFILE='insert the name of your text file here' perl -pi -e 's/\r\n/\n/g' "$TEXTFILE" perl -pi -e 's/\r/\n/g' "$TEXTFILE" perl -pi -e 's/\n/ /g' "$TEXTFILE" If you want to run this from within AppleScript, this is how you would type it: do shell script "TEXTFILE='insert the name of your text file here' ; perl -pi -e 's/\r\n/\n/g' \"$TEXTFILE\" ; perl -pi -e 's/\r/\n/g' \"$TEXTFILE\" ; perl -pi -e 's/\n/ /g' \"$TEXTFILE\"" Does that work for you?
__________________
Successful trades: sold Final Cut Express to Silver. bought a random PC serial cable from Simo. |
|
||||
|
Quote:
do shell script "echo -n" & quoted form of formatted_keyword & "\ >>" & text_file The -n after echo will leave out the return character. The \ (backslash before the space) will insert a space at the end of the keyword.
__________________
Successful trades: sold Final Cut Express to Silver. bought a random PC serial cable from Simo. |
|
||||
|
Agree with Nevets & Jon that you are trying to fix a problem you can avoid having but, FWIW, this kind of thing is pretty straightforward to do in AS. Personally, I would read the original file using AS and pull the keywords straight out but I don't know what you've got in the file so I can't offer any suggestions on that.
Anyway, this, from The FooDoo Lounge, will do the find/replace you are asking for. Copy it to Script Editor and run it: Code:
set inputText to "
&KeywordA
&KeywordB
&KeywordC
&KeywordD"
set outputText to findReplace for inputText from {"
"} into {" "}
-- findReplace -- by Richard Morton, 2002 --
-- Multiple find/replace
-- Pass a string, a list of 'find' strings and a list of 'replace' strings
to findReplace for inputString from oldChars into newChars
tell AppleScript
set olTids to text item delimiters
copy inputString to tempStr
try
repeat with n from 1 to length of oldChars
set text item delimiters to item n of oldChars
set tmpList to text items of tempStr
set text item delimiters to item n of newChars
set tempStr to text items of tmpList as string
end repeat
set text item delimiters to olTids
on error eStr number eNum
set text item delimiters to olTids
error eStr number eNum
end try
return tempStr
end tell
end findReplace
|
| Reply |
| Bookmarks |
| Tags |
| applescript |
| Thread Tools | |
| Display Modes | |
|
|