Hi and season greetings
I have a text file ( series of one line paragraphs) and I hope to perform as follows
This is a file example
Text1 Text2
I would like to get something like this
Text1 “[content from Clipboard]” Text2 [content from Clipboard 2]
I was thinking to do as follows Move the cursor at the end of the first tab then invoke the script tyo sadd the content from the clipboard between [ content ]
move the cursor to the next Tab and repeat
I created the following code, maybe it helps to point you in the right direction:
on run
set cp to (the clipboard) as text
-- reading the text file
set txtfilepath to "Macintosh HD:Users:martin:Desktop:input.txt"
set txt to read (txtfilepath as alias)
set newtxt to ""
-- slicing the text into lines
set txtlines to paragraphs of txt
-- iterating over the lines, creating the new content
repeat with txtline in txtlines
set txtlineitems to my gettxtitems(tab, txtline)
set newtxtline to item 1 of txtlineitems & tab & cp & tab & item 2 of txtlineitems & tab & cp & tab & return
set newtxt to newtxt & newtxtline
end repeat
-- writing the modified input to a new file on the desktop
set desktoppath to (path to desktop) as text
set newtxtfilepath to desktoppath & "output.txt"
try
set newtxtfile to open for access newtxtfilepath with write permission
set eof of newtxtfile to 0
write newtxt to newtxtfile
close access newtxtfile
on error errmsg number errnum
try
close access newtxtfile
end try
display dialog errmsg
end try
end run
-- I am return the text items of a text separated by the given delimiter
on gettxtitems(delim, txt)
set olddelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {delim}
set txtitems to text items of txt
set AppleScript's text item delimiters to olddelims
return txtitems
end gettxtitems