johnvining / dayonealfred Goto Github PK
View Code? Open in Web Editor NEWHelps ya help Alfred log stuff to Day One
Helps ya help Alfred log stuff to Day One
I'm trying to get this setup right now and I'm running into a bit of trouble. I've configured both scrips to point to the correct location of logtodayone.rb and when I try to log with either keyword I get a notification with the correct title, no error but also no text and nothing is added to Day One.
If you have any ideas on what might be going on I'd really appreciate it, this looks like a fantastic Alfred workflow!
I've installed the Day One CLI and have used it successfully to create an entry in Day One.
I've saved Brett's script and to test it I created the BASH profile alias he specified and successfully used it to create an entry from the Terminal.
Note that I've tried both /Users/cwhite/...
and ~/...
on alfred_script(q)
-- Set the location of the Script
set scriptLocation to “/Users/cwhite/Dropbox/Scripts/Day-One/logtodayone.rb"
-- Set what comes before the link in your entry
set prefix to "Reading: "
-- Set what comes after the link in your entry, use `\n\n` to put comments on new line
set separator to " - "
-- Set what separates the link and the clipboard text
set quoteSeparator to ":\n\n>"
set theCommand to ""
set feedback to "NO SCRIPT RAN!"
tell application "Safari"
set theTitle to name of front document
set theURL to URL of front document
end tell
if q is equal to ""
-- Without Comment or Star
set urlStr to prefix & "[" & theTitle & "](" & theURL & ")"
set theCommand to scriptLocation & " \"" & urlStr & "\""
set feedback to theTitle
else if character 1 of q is equal to "!"
-- Starred Entries
if q is equal to "!"
-- Without Comment
set urlStr to "!" & prefix & "[" & theTitle & "](" & theURL & ")"
set theCommand to scriptLocation & " \"" & urlStr & "\""
set feedback to "☆ " & theTitle
else
-- With Comment
set urlStr to "!" & prefix & "[" & theTitle & "](" & theURL & ")" & separator
set croppedQ to text 3 through -1 of q
set theCommand to scriptLocation & " \"" & urlStr & croppedQ & "\""
set feedback to "☆ " & theTitle & separator & croppedQ
end if
else if character 1 of q is equal to "q"
-- Quote Entries
set clippy to the clipboard
if q is equal to "q"
-- Without Star
set urlStr to prefix & "[" & theTitle & "](" & theURL & ")"
set theCommand to scriptLocation & " \"" & urlStr & quoteSeparator & clippy & "\""
set feedback to theTitle & "\n>" & clippy
else if q is equal to "q!"
-- With Star
set urlStr to "!" & prefix & "[" & theTitle & "](" & theURL & ")"
set theCommand to scriptLocation & " \"" & urlStr & quoteSeparator & clippy & "\""
set feedback to "☆ " & theTitle & "\n>" & clippy
end if
else
-- Unstarred, with Comment
set urlStr to prefix & "[" & theTitle & "](" & theURL & ")" & separator
set theCommand to scriptLocation & " \"" & urlStr & q & "\""
set feedback to theTitle & separator & q
end if
try
do shell script theCommand
on error errMsg
set feedback to "ERROR! " & errMsg
end try
return feedback
end alfred_script
on alfred_script(q)
try
do shell script “~/Dropbox/Scripts/Day-One/logtodayone.rb \"" & q & "\""
set feedback to q
on error errorMsg
set feedback to "Error! " & errorMsg
end try
return feedback
end alfred_script
#!/usr/bin/ruby
# logtodayone.rb
# Brett Terpstra (http://brettterpstra.com)
# Use and modify freely, attribution appreciated
#
# This script works with the Day One[1] command line utility
# It parses an input string for an exclamation point prefix to mark starred
# and/or a [date string] at the beginning to parse natural language dates
#
# Requirements:
# Chronic ruby gem
#
# Example usage:
# logtodayone.rb "! This is a starred entry."
# logtodayone.rb "[yesterday 3pm] Something I did yesterday at 3:00PM"
# logtodayone.rb "! [-2 1:30am] A starred entry about something I did two days ago"
require 'rubygems'
require 'chronic' # (`gem install chronic`)
if ARGV.length > 0
input = ARGV.join(" ").strip
else
print "Log entry: "
input = gets.strip
end
# If the input starts with an exclamation point, make it starred
starred = input =~ /^!/ ? "true" : "false"
# remove the bang from the input string
input = input.gsub(/^!\s*/,'')
# if there's a [date] specified, parse it
if input =~ /^\[(.*?)\]/
datestring = $1
# if the date starts with -X, assume it means X days ago
if datestring =~ /^\-(\d+)/
datestring.sub!(/\-(\d+)/,"\\1 days ago ")
end
# Replace a single 'y' within the date brackets with "Yesterday" for parsing
datestring.sub!(/\by\b/,'yesterday')
# Parse the resulting date string with Chronic
d = Chronic.parse(datestring, {:context => :past, :ambiguous_time_range => 8})
d = DateTime.now if d.nil?
else
# if no [date] specified, make it right now
d = DateTime.now
end
date = d.strftime("%m/%d/%Y %l:%M%p") # dayone formatted
input = input.gsub(/^\[.*?\]\s*/,'') # remove [date] from input
%x{echo "#{input}"|/usr/local/bin/dayone -d="#{date}" -s=#{starred} new}
I am no AppleScript guru, having come from UNIX, Linux, and SunOS, and doing BASH scripting, so I don't know anything.
I love your Alfred workflow, but tend to work in Firefox, due to my university having their websites and online classrooms written to work with that (Safari doesn't work well there). Can you suggest how I could adjust the script to make it work with Firefox?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.