I asked Newsgator to include the ability to toggle images on and off in NetNewsWire or at least include it as a thing I could get at via Applescript. A look at NNW’s scripting dictionary this morning seemed to indicate that no such ability is in there. There’s also no direct way to set NNW’s style through Applescript.
I don’t have some religious objection to images in RSS readers, but I really hate the huge, graceless globs of pixels some bloggers toss up regardless of the value they add to the text. But I don’t want to have to toggle images off across the board, either. Sometimes they’re useful.
io9 was the straw that broke the camel’s back with yet another ginormous image that pushed out a bunch of text. I broke down and set up style toggling in NNW with a combination of CSS and UI scripting so I could toggle without having to reach for the mouse and select an option from the dinky style menu NNW presents.
1. Make a Custom Style Sheet
NetNewsWire keeps all its styles in ~/Library/Application Support/NetNewsWire/StyleSheets/. They’re all called “*.nnwstyle,” and they’re bundles with a plist and a plain old CSS file called “stylesheet.css.”
I copied the default style (Default (3.1).nnwstyle) over to Default - Image Free.nnwstyle, right-clicked to “Show Package Contents” on the new .nnwstyle file, and opened the stylesheet.css file in an editor.
I added this selector:
.newsItemDescription img {
display: none;
}
I saved the file and doubleclicked the .nnwstyle file, which caused NNW to install it.
Here are before and after shots of NNW with the new stylesheet:
2. UI Scripting to Toggle Stylesheets
Next up, I fired up Prefab UI Browser to figure out how to handle the UI scripting. The fruits of that are below.
Nutshell: return the value of the styles menu in the lower right corner of the NNW menu (note that you may need to toggle “Show Styles Menu” in the “View” menu), then click either the image-free or default style sheet.
–Open this script in a new Script Editor window.
set myImageFreeCSS to "Default - Image Free"
set myDefaultCSS to "Default (3.1)"
activate application "NetNewsWire"
tell application "System Events"
tell process "NetNewsWire"
set mySheet to get value of pop up button 1 of window 1
perform action "AXPress" of pop up button 1 of window 1
if mySheet is equal to myImageFreeCSS then
perform action "AXPress" of menu item myDefaultCSS of menu 1 of pop up button 1 of window 1
else
perform action "AXPress" of menu item myImageFreeCSS of menu 1 of pop up button 1 of window 1
end if
end tell
end tell
Because I’m feeling friendly and expansive, I made the stylesheets variables for easy modification.
3. Connect It to a Keyboard Shortcut
Once I had a working script, I saved it in ~/Library/Scripts/Applications/NetNewsWire. I use Red Sweater’s FastScripts to assign keyboard shortcuts to scripts. So now ^⌘S toggles between styles.


Post a Comment