Hi all! First time Apple Script user, first time poster.
What I’m trying to do is find the cells in Numbers which contain italicised words, then highlight the cell by changing the background colour.
I have made a droplet and was able to find certain words which trigger the background colour update condition, but not specific word formatting. Having trouble with the syntax.
Right now I have:
on open droppedItems
repeat with anItem in droppedItems
tell application "Numbers"
open anItem
delay 2
tell the front document
try
-- Loop through each sheet in the document
repeat with sheetIndex from 1 to count of sheets
tell sheet sheetIndex
-- Loop through each table in the sheet
repeat with tableIndex from 1 to count of tables
tell table tableIndex
-- Loop through each cell in the table
repeat with rowIndex from 1 to count of rows
repeat with colIndex from 1 to count of columns
try
set cellValue to formatted value of cell colIndex of row rowIndex
if cellValue is not missing value then
set cellText to formatted value of cell colIndex of row rowIndex
set cellFormat to formatted value of rich text of cellText
-- display notification "cellText: " & cellText
set fontStyle to font of word of cellFormat
display notification "font: " & fontStyle
repeat with i from 1 to count of paragraphs of cellText
if (font of word i of cellFormat) contains "italic" then
-- Change the background color to pink (RGB: 255, 192, 203)
set background color of cell colIndex of row rowIndex to {65535, 49344, 51400}
exit repeat
end if
end repeat
end if
on error errMsg
end try
end repeat
end repeat
end tell
end repeat
end tell
end repeat
on error errMsg
display dialog "Error: " & errMsg
end try
end tell
end tell
end repeat
end open
I feel like the issue is in this area
set cellFormat to formatted value of rich text of cellText
set fontStyle to font of word of cellFormat
Then of course below with the repeat with i from 1 to count of paragraphs of cellText
section as the syntax is similar, but the script doesn’t reach that far since the display notification "font: " & fontStyle
doesn’t pop any notifications.
Thank in advance. Hope this is enough info to go off of.