Re: NNW, Growl, and images

23 views
Skip to first unread message

steve harley

unread,
Mar 26, 2013, 8:17:10 PM3/26/13
to netnews...@googlegroups.com
On Mon, Mar 25, 2013 at 1:34 PM, Alec Quig <aleco...@gmail.com> wrote:
> ive been a user of NNW for a while now, mostly for craigslist, and have
> always wondered why i don't see images in posts. you'd think this would be a
> straightforward option to config in prefs, but i can't figure out how to
> display images. here's what i'm seeing.

as noted, the feed has just a summary of each craigslist post; but you
can use the Open Link command to display the full post

> now, my personal shangri la for this would be if i could have growl display images in its notifications for each post that's downloaded to my feed. so, instead of seeing a notification like this, i'd have a notification for each post, complete with pictures. is this possible? if not, is there another app that might fit the bill?

an AppleScript to spin through the posts and Growl the titles is
pretty simple; Growling the images is messier because you have to
screen-scrape craigslist; here's a proof of concept; i am not
responsible if it does any harm; what this does not do is trigger
itself automatically when the feed updates — that's for you to figure
out:

script NNW_craigs_to_growl
-- assumes a craigslist feed is selected in NetNewsWire
-- growls the titles from the feed, along with a thumbnail if available

-- limit requests during testing to avoid abuse
property max_items : 10

on run
-- assume Growl is installed and running
tell application id "com.Growl.GrowlHelperApp"
register as application ¬
"NNW growlrss" all notifications {"item"} ¬
default notifications {"item"}
end tell
tell application "NetNewsWire"
set the_headlines to headlines of selectedSubscription
repeat with i from 1 to my min(count of the_headlines, max_items)
set a_headline to item i of the_headlines
set {a_title, an_URL} to {title, URL} of a_headline

-- note that if the post has craigslist-loaded images ("pic" in
subject list) the thumbs will be
-- in img tags with "/thumb/" in the URL; posts with user included
images ("image" in the subject list) aren't handled
-- this may break when craigslist changes things
try
set the_thumb_links to ""
set the_thumb_links to do shell script "/usr/bin/curl -s " &
an_URL & " | /usr/bin/grep '/thumb/' | cut -d '\"' -f2"
end try
if the_thumb_links is not "" then
set the_link to my get_line(the_thumb_links, 1)
my growl_item(a_title, the_link)
end if
end repeat
end tell
end run

on growl_item(subject, thumb_url)
set temp_file to do shell script "mktemp -t growlimg" --
~/Desktop/growlimg.XXXX"
set temp_file to POSIX path of (temp_file & ".jpg")
try
set img_data to missing value
do shell script "curl -s " & thumb_url & " > " & temp_file
set img_data to my get_image(temp_file)
end try

tell application id "com.Growl.GrowlHelperApp"
if img_data is missing value then
notify with name "item" title "craigslist" description subject ¬
application name "NNW growlrss"
else
notify with name "item" title "craigslist" description subject ¬
application name "NNW growlrss" image img_data
end if
end tell

end growl_item

-- from http://code.google.com/p/growl/issues/detail?id=541&q=image%20for%20location&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20BlockedOn%20Summary%20Product
on get_image(the_path)
set imgfd to open for access POSIX file the_path
set img to read imgfd as "TIFF" -- works on JPEG too
close access imgfd
return img
end get_image

on min(x, y)
if x ≤ y then
return x
else
return y
end if
end min

on get_line(str, l)
set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set the_lines to text items of str
set the_result to item l of the_lines
set AppleScript's text item delimiters to old_delims
return the_result
end get_line

end script

run NNW_craigs_to_growl
Reply all
Reply to author
Forward
0 new messages