Skip to content

One hotkey: Search selected text/image, open url(s) from selected text.

License

Notifications You must be signed in to change notification settings

willbchang/alfred-search-selection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Search Selection Logo
Dedicated to my friend @Y4m1n for her 24th birthday.

Search Selection

An Alfred workflow to do daily searches(text, image and open urls in text) with one hotkey.

Installation

  1. Download Search Selection.alfredworkflow
  2. Double click Search Selection.alfredworkflow to install.
  3. Click Import Button.
  4. Double click Hotkey and set your shortcut.(I'm using alt + s).

Features & Usages

alt+s

  • Open url(s):
    Select this line and press hotkey, it will open willbc.cn and https://news.ycombinator.com/ in the browser. 
    
    open urls
  • Text Search:
    • Search this lines and press the hotkey.
    • Search these two lines and press the hotkey. search text
  • Image Search: Select a local image or browse in Alfred File Search and press hotkey, please wait for seconds. search image

Change Search Engine

Default: Google

  1. Search test with your favorite search engine.
  2. Get the url from the results, e.g. https://duckduckgo.com/?q=
  3. Open Alfred Preferences -> Workflows -> Search Selection
  4. Right click Open in Editor workflow -> Open in Finder
  5. Open script.rb, press Command + F to find text.
  6. Replace https://google.com/search?q= with your favorite search engine url.

Contribution

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

The code logic is very simple:

if File.exist?(filepath)
  if File.image?(filepath)
    search_image(filepath)
  else
    push_notification('Please select an image', 'Supports jpg, gif, png, bmp, tif, or webp')
  end
elsif extract_urls(query).any?
  open_urls(query)
else
  search_text(query)
end

Credits

I tried write it with Python, it was not simple at all, I had to deal with some package/language issues. Pain!
I tried write it with Shell, all I did was trying to figure out the syntax. Deep Pain!
I tried write it with Go, well I never get started. Lost...
I tried Ruby(with little Shell code inside), it just worked without much pain! 💖 I really enjoyed it!

License

AGPL-3.0