I want to clear some text from a textedit text but its only half working for me
tell application "TextEdit"
set documentText to text of document 1
set {oldTID, my text item delimiters} to {my text item delimiters, "Administration"}
set textBits to text items of documentText
set my text item delimiters to ""
set text of document 1 to textBits as text
set my text item delimiters to oldTID
set documentText to text of document 1
set {oldTID, my text item delimiters} to {my text item delimiters, "New Search"}
set textBits to text items of documentText
set my text item delimiters to ""
set text of document 1 to textBits as text
set my text item delimiters to oldTID
set documentText to text of document 1
set {oldTID, my text item delimiters} to {my text item delimiters, "Advanced"}
set textBits to text items of documentText
set my text item delimiters to ""
set text of document 1 to textBits as text
set my text item delimiters to oldTID
set documentText to text of document 1
set {oldTID, my text item delimiters} to {my text item delimiters, "Tips"}
set textBits to text items of documentText
set my text item delimiters to ""
set text of document 1 to textBits as text
set my text item delimiters to oldTID
end tell
For some reason "New Search" is still on the text document.
Is that possible otherwise to only keep the text from the line 2 to 3 for example?
Kind regards.
Multiple text item delimiter calls can be tricky for AppleScript. Try this:
tell application "TextEdit" to set documentText to text of document 1
tell application "TextEdit" to set text of document 1 to my RemoveThis(documentText, {"Administration", "New Search", "Advanced", "Tips"})
to RemoveThis(txt, termList)
repeat with eachTerm in termList
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, (eachTerm as text)}
set textBits to text items of txt
set AppleScript's text item delimiters to oldTID
set txt to (textBits as text)
end repeat
return txt
end RemoveThis
In this way, you can define a list of terms to be sifted through, and not worry about the coding details.
Related
Essentially, I am taking a column of data from an excel file and breaking it up into small groups. So:
10
20
30
40
50
60
etc...
broken up into:
"10, 20, 30, 40"
"50, 60, 70, 80"
etc
Using AppleScript, I assume you would nest loops, something along the lines of:
tell application "TextEdit"
set theText to text of front document as string
set myParas to every paragraph of theText
set myNum to the number of paragraphs of theText
repeat myNum times
repeat 4 times
end repeat
end repeat
end tell
I'm going to be updating data once a month that comes through as a column of numbers and text. I can strip out all the text easy enough, just would like to know the principle of how to break up or merge the paragraphs into smaller blocks.
For many complicated reasons, I am stuck with AppleScript and textEdit, so other alternates (such as massaging with javascript or textWrangler or whatever) is not an option.
Also, maybe textEdit can do this on it's own but the script I will be using will have lots of other operations based on the above result, so AppleScript has to do all the heavy lifting.
You can specify the step size in a repeat loop, so you could do something like:
tell application "TextEdit" to set theText to text of front document
set paras to paragraphs of theText
set step to 4 -- number of items in a group
repeat with i from 1 to (count paras) by step
try
buildString(items i thru (i + step - 1) of paras)
on error errmess number errnum -- index out of bounds
log errmess
if errnum is -128 then error number -128 -- quit
buildString(items i thru -1 of paras) -- just to the end
end try
end repeat
to buildString(someList)
set tempTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ", "
set output to someList as text
set AppleScript's text item delimiters to tempTID
display dialog output -- show it
return output
end buildString
I have a code to import data from csv file to iMacros and the part at which i am struck now is the iMacros is printing the values of the excel row wise and i want it to be printed in colulmn wise. I Get this error though I have used the {keyword !Col1}}
VERSION BUILD=10.4.28.1074
'Uses a Windows script to submit several datasets to a website, e. g. for filling an online database
' Specify input file (if !COL variables are used, IIM automatically assume a CSV format of the input file
'CSV = Comma Separated Values in each line of the filE
TAB T=1
SET !DATASOURCE C:\Users\Arun\Desktop\Book2.csv
'Start at line 2 to skip the header in the file
SET !LOOP 1
'Increase the current position in the file with each loop
SET !DATASOURCE_LINE {{!LOOP}}
' Fill web form
URL GOTO=https://docs.google.com/forms/d/e/1FAIpQLSdDj_Rrydyd1ukk56tOL92LAu-jE9qfi1GwsAUTT1gviZNG7w/viewform?c=0&w=1
TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:mG61Hd ATTR=NAME:emailAddress CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:mG61Hd ATTR=NAME:entry.2005620554 CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:mG61Hd ATTR=NAME:entry.1045781291 CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:mG61Hd ATTR=NAME:entry.1065046570 CONTENT={{!COL4}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:mG61Hd ATTR=NAME:entry.1166974658 CONTENT={{!COL5}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:mG61Hd ATTR=NAME:entry.839337160 CONTENT={{!COL6}}
'Note * is used to ignore leading and trailing blanks that could be in the input data
'
'The precent (%) symbol is used to select the stateid by VALUE as defined in the website select statement and not by its index.
'
'The string ($) symbol is used to select the country by TEXT, not by its index.
'Index would be the position of an entry in the combo box list, e. g. 161 for United States
Take a look at one of the acceptable workarounds given below. Let's suppose that your CSV file doesn't contain any exclamation marks and has a comma as the datasource delimiter.
' fake delimiter
SET !DATASOURCE_DELIMITER "!"
' real delimiter
SET rd ","
SET !DATASOURCE Address.csv
SET !DATASOURCE_LINE 2
SET row2 EVAL("'{{!COL1}}'.split('{{rd}}')[{{!LOOP}}-1];")
SET !DATASOURCE_LINE 3
SET row3 EVAL("'{{!COL1}}'.split('{{rd}}')[{{!LOOP}}-1];")
SET !DATASOURCE_LINE 4
SET row4 EVAL("'{{!COL1}}'.split('{{rd}}')[{{!LOOP}}-1];")
' ...
PROMPT {{row2}}<BR>{{row3}}<BR>{{row4}}
Play this macro in loop mode. It must work in 'iMacros add-on' for Firefox or Chrome. I think my tip should help you.
I want to highlight the strings before and after '--'. Example good -- bad here i want to highlight good and bad. when ever the -- is comes then before and after the strings are become highlight. Is it possible.
Let's assume you have the following text in a field "mytext":
This text comes before -- this text comes after.
LiveCode (as most applications) does not allow discontinuous selections, so the 'select' command only works on continuous runs of text.
select word 1 to 3 of fld "mytext"
But you can simulate selection highlighting by setting the backgroundColor property of separate text runs:
put wordOffset("--",fld "mytext") into tWordIndex
set the backgroundColor of word 1 to tWordIndex - 1 of fld "mytext" to the hiliteColor
set the backgroundColor of word tWordIndex + 1 to -1 of fld "mytext" to the hiliteColor
Of course you can use any valid text chunk expression in the two 'set' statements, depending on what part of the text preceding and following the " -- " you want to "highlight".
To clear the backgroundColor from the field do this:
set the backgroundColor of char 1 to -1 of fld "mytext" to empty
I have a field "data" with Unicode text in it which displays properly. I want to copy a chunk of it and put it into another field called "someData".
I tried the following script in a button
on mouseUp
put word 2 of line 1 of the unicodeText of field "data" into t
set the unicodeText of field "someData" to t
end mouseUp
Non Unicode text displays fine in the field "someData" but Unicode text does not.
You could probably get away with UTF8 encoding then parsing then re-encoding
on mouseUp
put word 2 of line 1 of uniDecode(the unicodeText of field "data","UTF8") into t
set the unicodeText of field "someData" to uniEncode(t,"UTF8")
end mouseUp
on mouseUp
put unicode the unicodeText of word 2 of field "data" into field "someData"
end mouseUp
should work.
Marek
Here is another one-liner you can test:
set the unicodeText of field 2 to the unicodeText of word 2 of field 1
I am no expert in unicode, but there may be a clue in that LC treats most unicode stuff as properties. Because of this, one may set, say, the uniCodeText of a field:
set the unicodeText of fld 1 to "U+400"
But one cannot set that property, or any property, in a variable. Consider the following two handlers. It is assumed there exist two fields, "fld 1" and "fld 2".
on mouseUp
set the useUnicode to "true"
set the unicodeText of fld 1 to "U+400" -- an example
set the unicodeText of fld "f2" to the uniCodeText of fld 1
end mouseUp
on mouseUp
set the useUnicode to "true"
set the unicodeText of fld 1 to "U+400"
put fld 1 into temp
set the unicodeText of fld "f2" to temp
end mouseUp
The first works, the second does not. In your example, you try to put displayed uniCode into a variable. I don't think you can "put" that sort of thing. You have to set a property.
Now that said, check out the "put uniCode" command. This might get around the property thing. Write back if it does.
Craig Newman
AppleScript delimiters
How do I remove the last 3 text items?
My list is as follows:
{"Water", "Management", "in", "Ancient", "Greek", "Cities", "Jun", "1993", "pdf"}
I would like to remove the last 3 text item (e.g.: "Jun, "1993", and "pdf").
Here is my script so far:
set AppleScript's text item delimiters to ["USA."]
set stringToUse to "04.Oxford.University.Press.USA.Water.Mngt.in.Ancient.Greek.Cities.Jun.1993.pdf" as string
set stringUSA to last text item of stringToUse
set AppleScript's text item delimiters to ["."]
set pathNames to text item of stringUSA
return pathNames
As a general rule it's important that:
The number of text items in the list can be a variable
The text items to be deleted are always the last three
Try:
set AppleScript's text item delimiters to "USA."
set stringToUse to "04.Oxford.University.Press.USA.Water.Mngt.in.Ancient.Greek.Cities.Jun.1993.pdf" as string
set stringUSA to last text item of stringToUse
set AppleScript's text item delimiters to "."
set pathNames to text items 1 thru -4 of stringUSA
set AppleScript's text item delimiters to {""}
return pathNames