Thank you for the clarification.
For my part, I am trying to read the url associated with the text of the cell in order to modify the url string, I think that will work. Really what I can't do is find the url, read it and then write the new string. Here is the start of the script
on replaceLinksInNumbers(filePath)
tell application "Numbers"
set theDocument to open filePath
tell theDocument
tell sheet 1
tell table 1
repeat with i from 2 to count of rows
set cellValue to value of cell ("B" & i)
if cellValue contains "mathilde.local" then
set newValue to my replaceText(cellValue, "http://foo.local/", "httpsr...")
set value of cell ("B" & i) to newValue
end if
-- This is where I'm trying to read the url of Bi,
-- for example B3 we see "Recapitualtion" (ie cellValue == "Recapitualtion" )
-- and if we right click we see "edit link"
-- This is what I want to do in applescript " (there are several hundred cells to modify)
end repeat
end tell
end tell
save
close saving yes
end tell
end tell
end replaceLinksInNumbers
on replaceText(theText, searchString, replaceString)
set AppleScript's text item delimiters to searchString
set theTextItems to text items of theText
set AppleScript's text item delimiters to replaceString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end replaceText
set filePath to "/Users/dhenin/Desktop/14_Travaux_en_cours/Chantier_Hermes/HermesTpe.numbers"
replaceLinksInNumbers(filePath)
"Be seeing you"
Number 6
SGIII wrote:
Not sure exactly what result you want but you can extract the url part of a hyperlink with this script.
-- select cells, command-c, run script, click cell 1x, command-v to paste urls
set the clipboard to (the clipboard as «class RTF »)
set theHTML to do shell script "pbpaste -Prefer rtf | textutil -convert html -stdin -stdout"
set htmlParts to splitText(theHTML, "<a href=\"http://")
set pasteStr to ""
repeat with i from 2 to (htmlParts's length)
set pasteStr to pasteStr & htmlParts's item i's first word & return
end repeat
set the clipboard to pasteStr's text 1 thru -2
return pasteStr
to splitText(t, d)
set text item delimiters to d
t's text items
end splitText
1.
Copy-paste into Script Editor (in Applications > Utilities).
2. Select the cells in Numbers with hyperlinks and then type command-c to copy to the system clipboard.
3. Click the triangle run button in Script Editor
4. Click a cell in Numbers and command-v to paste.
You should then see the urls pasted in a column.
Then you can use Numbers formulas to concatenate "https://" and ".fr" to produce the full url that you want, perhaps something like in the adjacent column.
"https://"&TEXTBEFORE(B2,".")&".bar.fr"
In a simple test I get something like this:
https://discussions.apple.com/content/attachment/654ca5b5-93a0-4319-9df2-d47bcb05a398
For my test the original link looked like this:
https://discussions.apple.com/content/attachment/ade143a4-7208-42c0-af4b-4deb36b7d2d4
SG
[Edited by Moderator]