How to change htmlText to all fields in group "DGP"? I am using this code:
repeat with x = 1 to 16--the number of lines in dataarray
put the htmlText of field x of group "DGP" into myHtml
replace ss with "<font bgcolor=" & quote & "green" & quote & ">" & ss & "</font>" in myHtml
set the htmlText of field x of group "DGP" to myHtml
end repeat
If I write the number of lines in dataarray instead of 16, the following error occurs:
group "NDGP": execution error at line 35 (Chunk: no such object), char 11
I think this is because of the small size of the grid. When I changed the code to 16 it works, but if I scroll down, the bgcolor is lost.
If you changed the htmlText propeties of the fields of a datagrid, you would ignore the datagrid-specific properties. The datagrid might even completely ignore the changes and display the original data as soon as an update of the visible part of the data is triggered, e.g. by scrolling.
You should not change the htmlText property of individual fields of a datagrid.
Related
I asked and read different topic about this in the last month, but still didn't get it
I want to extract some data from a website using Applescript or something simular
With this script
to getInputByClass2(theClass, num) -- defines a function with two inputs, theClass and num
tell application "Safari" --tells AS that we are going to use Safari
set input to do JavaScript "
document.getElementsByClassName('" & theClass & "')[" & num & "].innerHTML;" in document 1 -- uses JavaScript to set the variable input to the information we want
end tell
return input --tells the function to return the value of the variable input
end getInputByClass2
-- start here
getInputByClass2("field type-string field-accountname", 0)
set theText to Unicode text
set theText to getInputByClass2("field type-string field-accountname", 0)
I have this result :
"<div class=\"content\"><div class=\"related-orders-indicator component\" id=\"XXXX-BBBB-CCCC-DDDD-EEEE\" data-bad=\"0\" data-good=\"51\" data-total=\"51\">
<label class=\"count\" style=\"display: block;\">51</label>
</div><label class=\"name\">accountname</label><span class=\"value\">1985</span><div class=\"confirmation\"><input type=\"checkbox\" class=\"tri-state confirmation square-confirmation-style\"></div></div>"
How can I have only the account name as a variable, in this example 1985.
Many thanks in advance
You can do it with text item delimiters:
property leftEdge : "class=\"value\">"
property rightEdge : "</span>"
set theSource to "<div class=\"content\"><div class=\"related-orders-indicator component\" id=\"XXXX-BBBB-CCCC-DDDD-EEEE\" data-bad=\"0\" data-good=\"51\" data-total=\"51\"><label class=\"count\" style=\"display: block;\">51</label></div><label class=\"name\">accountname</label><span class=\"value\">1985</span><div class=\"confirmation\"><input type=\"checkbox\" class=\"tri-state confirmation square-confirmation-style\"></div></div>"
set saveTID to text item delimiters
set text item delimiters to leftEdge
set classValue to text item 2 of theSource
set text item delimiters to rightEdge
set theResult to text item 1 of classValue
set text item delimiters to saveTID
theResult
I was wondering if there is a short way to convert an AppleScript list into a string separating each item. I can achieve this in a way which is more lengthy that I would like, so I wondered if there is a simple way to achieve this. Basically, I would like to take a list such as {1,2,3} and convert it in to a string "1, 2, 3". I can do something like below, but that results in a comma following the resulting string:
set myList to {"1.0", "1.1", "1.2"}
set Final to ""
if (get count of myList) > 1 then
repeat with theItem in myList
set Final to Final & theItem & ", "
end repeat
end if
There is a short way, it's called text item delimiters
set myList to {"1.0", "1.1", "1.2"}
set saveTID to text item delimiters
set text item delimiters to ", "
set Final to myList as text
set text item delimiters to saveTID
Create your own snippet for this
Convert a list to a string is so frequent that you better create a subroutine.
on list2string(theList, theDelimiter)
-- First, we store in a variable the current delimiter to restore it later
set theBackup to AppleScript's text item delimiters
-- Set the new delimiter
set AppleScript's text item delimiters to theDelimiter
-- Perform the conversion
set theString to theList as string
-- Restore the original delimiter
set AppleScript's text item delimiters to theBackup
return theString
end list2string
-- Example of use
set theList to {"red", "green", "blue"}
display dialog list2string(theList, ", ")
display dialog list2string(theList, "\n")
I'm trying to build an applescript to sort tags in the Genre field of a music file in iTunes.
I'm using a semi-colon separated list for the Genre field, like this: Rock; Art Rock; Female Vocalists
The string I want to sort is named genreList in my script:
{"Art Rock", "Female Vocalists", "Rock"}
My preferred tag order is listed as sortList:
{"Rock", "Dance", "Art Rock", "New Wave", "Female Vocalists", "Male Vocalists"}
I want the items in genreList to sort according to sortList, like this:
{"Rock", "Art Rock", "Female Vocalists"}
How do I sort the first list using the second list? I've searched here and on Google, but as I am a scripting novice I'm not even sure I'm searching for the right terms.
Try this, select one or multiple tracks in iTunes and run the script.
If the separator is supposed to be semicolon + space, please change the second property line.
If the genre property does not contain the separator, nothing will be changed.
If a genre does not match the items in the sorted list it will be appended at the end.
property sortedGenreList : {"Rock", "Dance", "Art Rock", "New Wave", "Female Vocalists", "Male Vocalists"}
property separator : ";"
tell application "iTunes" to set selectedItems to (get selection)
if selectedItems is {} then
display dialog "Nothing selected" buttons {"Cancel"} default button 1
end if
set {TID, text item delimiters} to {text item delimiters, separator}
repeat with aTrack in selectedItems
set orderedGenreList to {}
set nonOrderableGenres to {}
tell application "iTunes" to set trackGenreList to text items of (get genre of aTrack)
if (count trackGenreList) > 1 then
repeat with aGenre in trackGenreList
if sortedGenreList does not contain aGenre then set end of nonOrderableGenres to contents of aGenre
end repeat
repeat with aGenre in sortedGenreList
if trackGenreList contains aGenre then
set end of orderedGenreList to contents of aGenre
end if
end repeat
set orderedGenres to (orderedGenreList & nonOrderableGenres) as text
tell application "iTunes" to set genre of aTrack to orderedGenres
end if
end repeat
set text item delimiters to TID
If you want to use a text file with a genre per line replace the first property line with
set sortedGenreList to paragraphs of (read (choose file))
I am using a progress bar and I think it's not working properly. My requirement is when my replacement are over that time progress bar show a message and it must be reached to end point.If I run my code more than one time then the current value of progress bar property is automatically set to 100 I am using the following code
global searchStr
global replaceStr
global assa
global tCurrentProgress
on mouseUp
----------progressbar coding------------------------
global tCurrentProgress
put 0 into tCurrentProgress
if tCurrentProgress >= the endValue of scrollbar "Progress Scrollbar" then
else
add 1 to tCurrentProgress
---------------------------------------------
put the htmlText of field "MytextField" into myHtml
set the caseSensitive to true
put the field SRText into myArrayToBe
split myArrayToBe by CR
put the number of lines of (the keys of myArrayToBe) into myArraylength
repeat with i = 1 to myArraylength
--return i
put myArrayToBe[i] into y
split y by colon
put y[1] into searchStr
put y[2] into replaceStr
if searchStr is empty then
put the 0 into m
else
replace searchStr with "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & searchStr & "</font></strike><font bgcolor=" & quote & "green" & quote & ">" & replaceStr & "</font>" in myHtml
end if
end repeat
set the htmlText of fld "MytextField" to myHtml
end if
send "push_thumb" to me in .1 second ----------progressbar coding-------
end mouseUP
----------progressbar coding------------------------
command push_thumb
put the thumbPosition of scrollbar "Progress Scrollbar" into tCurrentProgress
if tCurrentProgress >= the endValue of scrollbar "Progress Scrollbar" then
answer "Process complete"
else
add 1 to tCurrentProgress
send "push_thumb" to me in .1 second -- keep the timer going
end if
set the thumbPosition of scrollbar "Progress Scrollbar" to tCurrentProgress
end push_thumb
-------------------------------------------------------------------------
Since you've made tCurrentProgress a global variable, its contents will stay in memory until you change it. Whenever you start your mouseUp process, you need to put 0 into tCurrentProgress and you need to set the thumbPosition of your progressbar to its startValue (probably 0).
Keep in mind that using a progressbar implies that you have a specific number of tasks that will be completed, and the percentage of completed tasks corresponds with the filled percentage of the progressbar. It's not clear from your example that the value of the progressbar corresponds with the number of replacements being done by your code.
If there's no way to know how long a process will take, you should use something that communicates indeterminate progress, like changing the cursor to watch or busy, or using something like a loading/spinning GIF. This shows your application is processing, but without tracking any specific progress.
How can i get content from scrolling field and place content in an array in Live code. I have code for replace content in the array
on mouseUp
put "" into field f1
put "red,RED" & CR & "green,GREEN" & CR & "blue,BLUE" into myArrayToBe
split myArrayToBe by CR
put the number of lines of (the keys of myArrayToBe) into myArraylength
repeat with i = 1 to myArraylength
put myArrayToBe[i] into y
split y by comma
put y[1] into searchStr
put y[2] into replaceStr
put replaceStr &CR after field f1
end repeat
end mouseUp
This function should do the trick
function lines_to_array pLines
put pLines into tArray
split tArray by return
RETURN tArray
end lines_to_array
Example
on mouseUp
put lines_to_array(field "Guests") into tGuests
-- do something with the array tGuests here
end mouseUp