Apple script - how I can insert number in active Numbers cell?
Hi, Community.
I need to insert variable's value (theRate) in active Numbers cell currently selected in opened document.
It is currency rate I get from National Bank site. I want to select needed cell and choose Apple Script from Scripts Menu – currency rate should be inserted in this cell.
Tried in several ways but get uninformative -10006 error which says "The write operation was denied."
The second problem – I can't get needed value (<rate> tag) via XML set of commands without errors, so I just croped XML result I get from National Bank site with "word" and "paragraph".
Here is the part of working script:
set {year:y, month:m, day:d} to (current date)
set day_str to text -1 thru -2 of ("00" & d)
set mon_str to text -1 thru -2 of ("00" & (m * 1))
set theDate to (y & mon_str & day_str) as string
set theURL to "https://bank.gov.ua/NBU_Exchange/exchange_site?date=" & theDate & "&valcode=usd"
set thePrice to do shell script "curl -s " & quoted form of theURL
set theRate to word 4 of paragraph 9 of thePrice
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
set theText to findAndReplaceInText(theRate, ".", ",")
Thanks for help.
MacBook Pro 15″, macOS 12.7