Hi buddies
Can someone illustrate me how do I replace a phrase in the middle of a text document, with a content line of another text document??
I tried with several actions methods but with no result.
Explaining what I want to do: bFirst Document[/b]
ic++;
slides[ic] = ‘fall-colors.jpg’;
menus[ic] = ‘Autumn Colors’;
cap[ic] = ‘Autumn Colors on the way down’;
Second Document
s001.jpg
s002.jpg
s003.jpg
.
I want to make several copies of block text in first document and change de text fall-colors.jpg by every line in second document one line per copy.
tell application "TextEdit"
activate
if not (exists first document) or not (exists second document) then
display dialog "This script requires two open documents." buttons {"Cancel"} default button 1 with icon note
end if
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"fall-colors.jpg"}
set firstTextItems to text items of (get text of first document)
set AppleScript's text item delimiters to ASTID
set secondTextItems to paragraphs of ((text of second document) & "")
set newText to ""
get (count secondTextItems)
repeat with i from 1 to result
set newText to newText & (item i of firstTextItems) & (item i of secondTextItems)
end repeat
set text of first document to (newText & (last item of firstTextItems))
end tell
You guys are genius. I have been thinking on it since yesterday morning and I was getting stuck!!
Thanks for the fast reply,
I am using TextEdit, everything was fine until a get this message “Can’t make item 3 of {"ic++;
slides[ic] = ‘", "’;
menus[ic] = ‘Autumn Colors’;
cap[ic] = ‘Autumn Colors on the way down’;
"} into type string.”
Hey Bruce
It worked allright
I have no words to thank you
I don´t want to push too much of your good wiling
Could you tell me just one more thing.
which is. as you said in the earlier post I have much more items in the second document
how could I.
First: copy the block of text several times in the document then,
I want copy several numbers (603 more exactlly) to that fiirst field.
puting in short.
Each number on its block of text but in that right position inside the block
I’m trying to find a way to do this without the first document (this would avoid the need to copy the blocks), but I’m running into a few problem.
Edit: Try something like this:
set newText to "ic++;
slides[ic] = '"
set myDelimiter to "';
menus[ic] = 'Autumn Colors';
cap[ic] = 'Autumn Colors on the way down';
ic++;
slides[ic] = '"
tell application "TextEdit"
activate
if not (exists front document) then
display dialog "This script requires an open document." buttons {"Cancel"} default button 1 with icon note
end if
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {myDelimiter}
set newText to newText & (paragraphs of (text of first document) & "") as Unicode text
set AppleScript's text item delimiters to {((ASCII character 10) & "';")}
set newText to text items of newText
set AppleScript's text item delimiters to {((ASCII character 13) & "';")}
set newText to text items of newText
set AppleScript's text item delimiters to {"';"}
set newText to newText as Unicode text
set AppleScript's text item delimiters to ASTID
make new document with properties {text:newText}
tell result to delete (paragraphs -2 thru -1 of it's text)
end tell
The next to last line (tell result to delete.) only works in TextEdit. To make it work in BBEdit, you have to change “paragraphs” to “lines” [1].
You are amazing, this peace of art (code) work in perfetion.
and you understood exactlly what I meant
On running the script I notice that each ‘copied’ block hould stayd formatted like this: ic++;
slides[ic] = 's598.jpg
';
menus[ic] = ‘Autumn Colors’;
cap[ic] = ‘Autumn Colors on the way down’;
and I wanted like this: ( that '; after the name of the image) ic++;
slides[ic] = ‘s598.jpg’;
menus[ic] = ‘Autumn Colors’;
cap[ic] = ‘Autumn Colors on the way down’;
with a black line on the end and bettween the blocks
do you think it is possible??
I am trying to follow your code lines and I understand what they do and what they mean
but I am honest I would never discover it by myself
That’s supposed to be taken care of by these lines:
set AppleScript's text item delimiters to {((ASCII character 10) & "';")}
set newText to text items of newText
set AppleScript's text item delimiters to {((ASCII character 13) & "';")}
set newText to text items of newText
There should already be a blank line at the end. To put one between the blocks, you just need to change “myDelimiters”:
set myDelimiter to "';
menus[ic] = 'Autumn Colors';
cap[ic] = 'Autumn Colors on the way down';
ic++;
slides[ic] = '"
Hey Bruce
You were rigth the end blank line was there,
the blank line bettween blocks is already there as you instruted me
I was messing around on your code trying to put the semicolon ( after
the name of the images but I couldn’t
I know you are giving me a hand and I have almost your arm here
but could you explain me how to solve this?
by the way. where I can find a e-book about Applescript.
I am from Portugal - Lisbon
I work in Design (outdoor) business and I am really interested in learnig applescript.