Search CompFight From MarsEdit with AppleScript
Often times I need an image for MacMembrane and an app icon or a screenshot won’t do the trick. To find relevant, interesting and legal images I use the amazing Flickr search tool CompFight.
Use CompFight to Search Flickr
CompFight does away with Flickr’s stingy 10 search results page and replaces it with browser wide thumbnail results based on your keywords. It also let’s you add Creative Commons/Commercial paramarers to your search. I leave these on so that my results are narrowed to only images that I can use on my blog without violating copyright.
Search CompFight from MarsEdit using AppleScript
As I said, I use CompFight to search images for my blog, and when I’m writing for my blog I’m in MarsEdit. Here is an AppleScript to take the selected text from a MarsEdit and search CompFight for CC images.
tell application "MarsEdit"
activate
try
set needImg to selected text in document 1
end try
end tell
try
if needImg is equal to "" then
activate me
try
set needImg to text returned of ¬
(display dialog "Enter keywords to search CompFight:" with title ¬
"Nothing Selected" default answer "" buttons ¬
{"No Thanks", "Search"} default button 2)
end try
my addSyntax(needImg)
else
my addSyntax(needImg)
end if
end try
on addSyntax(needImg)
if needImg is not "" then
set AppleScript's text item delimiters to " "
set theTextItems to text items of needImg
set AppleScript's text item delimiters to "%20"
set needImg to theTextItems as string
set AppleScript's text item delimiters to {""}
open location "http://www.compfight.com/#search_type=tags&query=" & ¬
needImg & ¬
"&commit=Search&license=1%2C2%2C3%2C4%2C5%2C6&original=1&safe_search=3"
end if
end addSyntax
How to Use the Script
Copy and paste the above code into Script Editor (in Applications >> AppleScript) and save it to your scripts folder. Select some text in MarsEdit and run the script. A new browser window will open with your search terms pre-populated. Because the script adds the CC parameters to your search, any image you see should be usable on your blog.
It isn’t the most complicated script in the world, but it does eliminate a few steps when searching for blog images, and eliminating simple but repetitive tasks is what AppleScript is all about.
Need some more MarsEdit AppleScripts and tricks? Try 2 AppleScripts to Simplify Your MarsEdit Workflow and MarsEdit Breaks it’s Silence with Sent to Weblog Sound. And don’t forget to Subscribe to MacMembrane.

December 5th, 2008 at 5:30 pm
Excellent tip! Thank you very much for sharing some of your workflows.
Greetings
December 7th, 2008 at 10:31 am
My pleasure, Patrick. Good luck with your blog!