Skip to content

Instantly share code, notes, and snippets.

@BuddyLReno
Created July 23, 2015 19:17
Show Gist options
  • Save BuddyLReno/bd17e79b10c188aeb370 to your computer and use it in GitHub Desktop.
Save BuddyLReno/bd17e79b10c188aeb370 to your computer and use it in GitHub Desktop.
Aflred Weekly Report Workflow
require 'fileutils'
require 'date'
# {query} is the user input from Alfred. Not used in this particular script.
query = "{query}"
firstDay = Date.parse("25-02-2013")
report_source_dir = "#{Dir.home}/Dropbox/Lampo/Weekly Reports/#{Date.today.year}/MD Source/"
vol = ((Date.today.year * 12 + Date.today.month) - (firstDay.year * 12 + firstDay.month)) / 12 + 1
header_template = %Q{# The Reno Report
**#{Date.today} | Vol. #{vol}**
---
}
FileUtils.cd(report_source_dir) do
last_report = Dir.glob("WeeklyReport_*.md").last
new_report_content = header_template + File.read(last_report).split("\n---\n")[1]
new_report_name = "WeeklyReport_#{Date.today.strftime('%m-%d-%y')}.md"
File.new(new_report_name, "w+")
File.open(new_report_name, "w") do |file|
file.puts(new_report_content)
end
# Opens report in default application.
system %{ open "#{report_source_dir + new_report_name}" }
end
# Alfred passes anything echoed or printed to the next item in the workflow.
# This allows us to copy the file name to the clipboard.
print "WeeklyReport_#{Date.today.strftime('%m-%d-%y')}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment