Skip to content

Commit

Permalink
actions
Browse files Browse the repository at this point in the history
  • Loading branch information
soniccat committed Jul 6, 2014
1 parent da3359b commit e6214d1
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 0 deletions.
45 changes: 45 additions & 0 deletions EvernoteExport.lbaction/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.alexeyglushkov.LaunchBar.action.EvernoteExport</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleName</key>
<string>Evernote Export</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LBDebugLogEnabled</key>
<true/>
<key>LBScripts</key>
<dict>
<key>LBDefaultScript</key>
<dict>
<key>LBScriptName</key>
<string>default.scpt</string>
<key>LBRunInBackground</key>
<true/>
<key>LBRequiresArgument</key>
<false/>
<key>LBReturnsResult</key>
<false/>
<key>LBLiveFeedbackEnabled</key>
<false/>
</dict>
</dict>
<key>LBDescription</key>
<dict>
<key>LBSummary</key>
<string>Export your evernote notes to be able to look through them by Evernote Search tool</string>
<key>LBAuthor</key>
<string>Glushkov Alexey</string>
<key>LBWebsite</key>
<string>https://medium.com/@sonicCat</string>
<key>LBTwitter</key>
<string>@soniccat</string>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2014 Gluhkov Alexey</string>
</dict>
</plist>
Binary file not shown.
51 changes: 51 additions & 0 deletions EvernoteSearch.lbaction/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.alexeyglushkov.LaunchBar.action.EvernoteSearch</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleName</key>
<string>Evernote Search</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LBTextInputTitle</key>
<string>Options after --:rtm</string>
<key>LBDebugLogEnabled</key>
<true/>
<key>LBScripts</key>
<dict>
<key>LBDefaultScript</key>
<dict>
<key>LBScriptName</key>
<string>default.rb</string>
<key>LBRunInBackground</key>
<true/>
<key>LBRequiresArgument</key>
<true/>
<key>LBAcceptedArgumentTypes</key>
<array>
<string>string</string>
</array>
<key>LBReturnsResult</key>
<true/>
<key>LBLiveFeedbackEnabled</key>
<true/>
</dict>
</dict>
<key>LBDescription</key>
<dict>
<key>LBSummary</key>
<string>Search through exported Evernote notes by text</string>
<key>LBAuthor</key>
<string>Glushkov Alexey</string>
<key>LBWebsite</key>
<string>https://medium.com/@sonicCat</string>
<key>LBTwitter</key>
<string>@soniccat</string>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2014 Gluhkov Alexey</string>
</dict>
</plist>
120 changes: 120 additions & 0 deletions EvernoteSearch.lbaction/Contents/Scripts/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env ruby

require 'json'
require 'CGI'

#get search folder
homeFolder = `echo ~/`
homeFolder = homeFolder[0..-2]

exportPath = ""

containersPath = "#{homeFolder}/Library/Group Containers/"
files = Dir.entries(containersPath)
files.each do |f|
if f.end_with?("com.evernote.Evernote")
exportPath = containersPath + f + "/Evernote/evernoteExport"
end
end

if exportPath == nil || exportPath.length == 0
item = {}
item['title'] = "Can't build path to a search folder"
items.push(item)
return item
end

folderPath = exportPath
searchString = ARGV[0]

optionIndex = searchString.index('--')
optionsString = ""

if optionIndex != nil
optionsString = searchString[optionIndex+2..-1]
searchString = searchString[0..optionIndex-1]
end

$showDebug = optionsString.index('d') != nil


#seach
startTime = Time.now
results = []


resultStrings = Dir[folderPath+'/'+'*.html'].inject(Hash.new(0)){ |result, item| result.update(item => File.read(item).scan(/#{searchString}/i).size) }
resultStrings.each do |k, v|
if v > 0
item = {}
item[:filePath] = k
item[:matches] = v
results << item
end
end

#p resultStrings

#p "find \"#{folderPath}\" -name \"*.html\" -exec grep -c \"#{searchString}\" {} +"
#value = `find "#{folderPath}" -name "*.html" -exec grep -c "#{searchString}" {} +`
#resultStrings = value.split("\n")

#return;

=begin
resultStrings.each do |str|
values = str.split(":")
matches = values[0].to_i
if matches > 0
item = {}
item[:filePath] = values[0]
item[:matches] = matches
results << item
end
end
=end


#sort by matches count
results = results.sort do |dict1, dict2|
numberOfMatchies1 = dict1[:matches]
numberOfMatchies2 = dict2[:matches]

numberOfMatchies2 - numberOfMatchies1
end

finishTime = Time.now
timeIntervale = finishTime - startTime

#convert to response
items = []

if ($showDebug)
item = {}
item['title'] = "scanning takes #{timeIntervale} seconds"
items.push(item)
end

results.each do | dict |

item = {}
item['title'] = File.basename(dict[:filePath])
item['subtitle'] = dict[:matches].to_s + " matches"
item['path'] = dict[:filePath]

items.push(item)
end

if items.count == 0
item = {}
item['title'] = "no matches"
items.push(item)
end

puts items.to_json



21 changes: 21 additions & 0 deletions EvernoteSearch.lbaction/Contents/Scripts/pick.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env ruby

require 'io/console'
require 'CGI'


=begin
str = ARGV[0]
args = str.split("||")
wordsString = args[0] + ", " + args[1] + ", " + args[2]
selectedIndex = args[3]
selectedWord = args[selectedIndex.to_i]
#copy selected word
IO.popen('pbcopy', 'w') { |f| f << selectedWord }
#show all words
wordsString = CGI::escape(wordsString)
value = `open \"x-launchbar:large-type?string=#{wordsString}\"`
=end
51 changes: 51 additions & 0 deletions IrregularVerbs.lbaction/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.alexeyglushkov.LaunchBar.action.IrregularVerbs</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleName</key>
<string>Irregular Verb List</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LBDebugLogEnabled</key>
<true/>
<key>LBTextInputTitle</key>
<string>Word:</string>
<key>LBScripts</key>
<dict>
<key>LBDefaultScript</key>
<dict>
<key>LBScriptName</key>
<string>default.rb</string>
<key>LBRunInBackground</key>
<true/>
<key>LBRequiresArgument</key>
<true/>
<key>LBAcceptedArgumentTypes</key>
<array>
<string>string</string>
</array>
<key>LBReturnsResult</key>
<true/>
<key>LBLiveFeedbackEnabled</key>
<true/>
</dict>
</dict>
<key>LBDescription</key>
<dict>
<key>LBSummary</key>
<string>Show all forms of a typed irregular verbs</string>
<key>LBAuthor</key>
<string>Glushkov Alexey</string>
<key>LBWebsite</key>
<string>https://medium.com/@sonicCat</string>
<key>LBTwitter</key>
<string>@soniccat</string>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2014 Gluhkov Alexey</string>
</dict>
</plist>
60 changes: 60 additions & 0 deletions IrregularVerbs.lbaction/Contents/Scripts/default.rb

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions IrregularVerbs.lbaction/Contents/Scripts/pick.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby

require 'io/console'
require 'CGI'

str = ARGV[0]
args = str.split("||")

wordsString = args[0] + ", " + args[1] + ", " + args[2]
selectedIndex = args[3]
selectedWord = args[selectedIndex.to_i]

#copy selected word
IO.popen('pbcopy', 'w') { |f| f << selectedWord }

#show all words
wordsString = CGI::escape(wordsString)
value = `open \"x-launchbar:large-type?string=#{wordsString}\"`

0 comments on commit e6214d1

Please sign in to comment.