Dynamic Named Styles based on text or saved filter?

With the upcoming built-in JavaScript automation (testable now as discussed in that thread, but lacking documentation) you’ll be able to create an automation handler which notices when a row changes and automatically updates its format based on that row’s content.

For example, to make rows red when they contain the word “red” you’d declare a handler along these lines:

var _ = function(){
	var handler = new PlugIn.Handler(function(sender, item, column, state) {
		console.log("invoke; sender: ", sender);
		console.log("invoke; item: ", item);
		console.log("invoke; column: ", column);

		var outline = item.outline;
		for (idx in outline.columns) {
			var c = outline.columns[idx];
			// console.log("looking at " + c);
			// console.log("type is " + c.type);
			// console.log("vs  " + ColumnType.Text);
			if (c.type == Column.Type.Text) {
				var value = item.valueForColumn(c);
				// console.log("value " + value);
				if (!value) {
					continue;
				}
				var string = value.string;
				// console.log("checking string " + string);
				if (string.indexOf("red") >= 0) {
					item.style.set(Style.Attribute.BackgroundColor, Color.RGB(1.0, 0.5, 0.5, 1.0));
					// console.log("found red");
					return;
				}
			}
		}

		item.style.set(Style.Attribute.BackgroundColor, Color.RGB(1.0, 1.0, 1.0, 1.0));
		
		// var styles = selection.styles;
		// console.log("styles = " + styles);
	});
	
	return handler;
}();
_;

Sorry that we don’t have an actual working sample for you to try out and modify yet. The omni-automation.com website has mostly been focused on OmniGraffle automation (with a goal of having that ready to go when OmniGraffle 3 for iOS ships), but I’ll suggest to @Sal that we include an example along these lines when he shifts his attention to OmniOutliner and automation handlers.

For now, the script @SGIII posted above is a better answer since it’s an actual working solution (which is more useful than a not-yet-working proposal). Just wanted you all to know that you’ll be able to automate even more of this in the future! (As well as other handler-based logic like making a column be the sum of two other columns, etc.)

4 Likes