Script: Clean strikethrough rows

The script only handles the selected rows and it’s not perfect.
Note the third and fourth lines.
.

tell front document of application "Bike"
	set rs to selection rows
	repeat with each in rs
		if exists character of text content of each then
			if strikethrough of text content of each is true then
				delete each
			end if
		end if
	end repeat
end tell

.

I’ve also been looking into removing parts of a row with partial strikethrough, but haven’t had any success yet, it seems to be because it can’t directly process the array with attributes obtained by attribute runs. Maybe?

Want to clean strikethrough parts
tell front document of application "Bike"
	set rs to selection row
	set rsa to attribute runs of text content of rs
	repeat with each in rsa
		if strikethrough of each is true then
			delete each
		end if
	end repeat
end tell

Alas I don’t have any idea why this works an your attempt didn’t, but this script is deleting strikethrough runs for me:

tell front document of application "Bike"
	set rs to selection rows
	repeat with eachRow in rs
		tell text content of eachRow
			delete (every attribute run whose strikethrough is true)
		end tell
	end repeat
end tell
2 Likes

Thank you! This script completely solves my problem!

1 Like

Update: Clear hyperlink

to remove all hyperlinks from the selected rows while keeping other formatting intact.

tell front document of application "Bike"
  set ls to selection rows
  repeat with each in ls
    set link of every attribute run of text content of each to ""
  end repeat
end tell

And I tried JXA, but it was hard to arrive there.

const bike = Application('Bike');
const doc = bike.documents.at(0);
const rows = doc.selectionRows();
rows.forEach(row => {
  if (row.textContent.attributeRuns.link().some(x => x)) {
    row.textContent = row.name();
  }
});

I think AppleScript and JXA each have their own advantages.

From JavaScript from Automation, you can also use the new (Bike 2 Preview) Extension Kit API, which can simplify things a bit.

Perhaps, for example, something like:

const clearLinks = () =>
    bike.frontmostWindow.currentOutlineEditor.selection.rows
        .forEach(
            row => row.text.removeAttribute('a')
        );


Application("Bike").evaluate({ script: `${clearLinks}` })
2 Likes

Or more generally (for adaptation to clearing code or mark attributes, for example) you could add a TextAttributeName parameter:

const clearTextAttribute = attributeName =>
    bike.frontmostWindow.currentOutlineEditor
        .selection.rows.forEach(
            row => row.text.removeAttribute(attributeName)
        );


Application('Bike').evaluate({ script: `${clearTextAttribute}`, input: 'a' })

Where 'a', the name of the HTML link tag, is drawn from the various possible values of TextAttributeName

export type TextAttributeName =
    | 'em' // was emphasize
    | 'strong'
    | 'code'
    | 'mark' // was highlight
    | 's' // was strikethough
    | 'a' // was link
    | 'base' // was baseline
    | string

(see the api > app > outline.d.ts file in the Bike Extension Kit)

2 Likes