Search CompFight From MarsEdit with AppleScript

flickr-me.pngOften 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.

comp-fight-sml.png

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.

3 Responses to Search CompFight From MarsEdit with AppleScript

  1. Excellent tip! Thank you very much for sharing some of your workflows.

    Greetings

  2. My pleasure, Patrick. Good luck with your blog!

  3. Long time lurker, thought I would say hello! I really dont post much but thanks for the good times I have here. Love this place..

    When I was hurt in that motorcycle accident my life would be changed for all time. Sadly that driver had no car insurance and I was going to be in pain for ever.

    This was not time for me to start and guess what to do. I had to find a good personal injury lawyer to help me get what I needed. After all, my family was counting on me.

    How dreadful was it? I has bedridden for 4 months, I had to have constant care and my hospital bills went through the roof!

    Luckily, I found a good referral site to help me.

    I will post more later this period to tell you more about what I have been going through.

    If you need an accident lawyer try the guys at If you need an personal injury lawyer try the guys at

Think different?