├── LICENSE.txt ├── README.md └── cremind /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CodeReminder 2 | 3 | Brett Terpstra 2015 4 | 5 | MIT License 6 | 7 | A CLI to add a Reminders.app reminder and/or OmniFocus task so you don't forget about that repo you cloned to play with later. 8 | 9 | ## Usage 10 | 11 | cremind [-r] [-t] [-n NOTE] [path] 12 | 13 | -r, --reminder Create a Reminders.app reminder 14 | -t, --task Create an OmniFocus task 15 | -n, --note NOTE Add a note 16 | -h, --help Display this screen 17 | 18 | Both `-r` and `-t` options can be provided, if neither is given it will default to the `default_type` option (see Configuration). 19 | 20 | If an existing path is provided at the end of the command, it will be used, otherwise, cremind will default to the current working directory. 21 | 22 | The title of the task or reminder will always be the basename of the path, and 23 | the full path will be the first line of the attached note. If an additional (-n 24 | "NOTE") flag is provided, "NOTE" will be appended. 25 | 26 | ## Installation 27 | 28 | 1. Copy the `cremind` script to a location in your $PATH. 29 | 2. Make it executable with `chmod a+x /path/to/cremind` 30 | 31 | ## Configuration 32 | 33 | Edit the configuration options at the top of the script. 34 | 35 | **of_project** 36 | 37 | _Default: "Code Reminders"_ 38 | 39 | The name of OmniFocus project to add tasks to. Project can be nested in folders. If a project with the specified name doesn't exist, it will be created in the root of the OmniFocus document. 40 | 41 | **reminders_list** 42 | 43 | _Default: "Code Reminders"_ 44 | 45 | The name of the Reminders.app list to use. If it doesn't exist, it will be created. 46 | 47 | **default_type** 48 | 49 | _Default: "reminder"_ 50 | 51 | If neither -r or -t options are provided, default to this type. The value should be a quoted string, either "reminder" or "task". 52 | -------------------------------------------------------------------------------- /cremind: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | # CodeReminder 3 | # Brett Terpstra 2015 4 | # MIT License 5 | # 6 | require 'optparse' 7 | # A CLI to add a Reminders.app reminder and/or OmniFocus task 8 | # so you don't forget about that repo you cloned to play with later 9 | # 10 | # Usage: cremind [-r] [-t] [-n NOTE] [path] 11 | # -r, --reminder Create a Reminders.app reminder 12 | # -t, --task Create an OmniFocus task 13 | # -n, --note NOTE Add a note 14 | # -h, --help Display this screen 15 | # 16 | 17 | # If an existing path is provided at the end of the command, it will be used. 18 | # Otherwise, it will default to the current working directory. 19 | 20 | # The title of the task or reminder will always be the basename of the path, and 21 | # the full path will be the first line of the attached note. If an addition (-n 22 | # "NOTE") flag is provided, the "NOTE" will be appended. 23 | 24 | # CONFIGURATION 25 | 26 | # Name of OmniFocus project to add tasks to 27 | # Project can be nested. If it doesn't exist, it will be created in the root 28 | of_project = "Code Reminders" 29 | 30 | # Name of Reminders.app list to use 31 | # If it doesn't exist, it will be created 32 | reminders_list = "Code Reminders" 33 | 34 | # If neither -r or -t options are provided, default to this 35 | # "reminder" or "task" 36 | default_type = "reminder" 37 | # END CONFIGURATION 38 | 39 | def e_as(str) 40 | str.to_s.gsub(/(?=["\\])/, '\\') 41 | end 42 | 43 | def get_of_id(proj_name) 44 | # Credit to RobTrew http://forums.omnigroup.com/showthread.php?t=15269 45 | %x{osascript <<'APPLESCRIPT' 46 | on run 47 | tell application "OmniFocus" 48 | set oDoc to front document 49 | set lstAllProjects to my ProjectList(oDoc) 50 | repeat with _project in lstAllProjects 51 | if (name of _project as string) is "#{proj_name}" then 52 | return id of _project as string 53 | end if 54 | end repeat 55 | set newProj to make new project with properties {name:"#{proj_name}"} at end of projects 56 | return id of newProj 57 | end tell 58 | end run 59 | 60 | on ProjectList(oParent) 61 | using terms from application "OmniFocus" 62 | tell oParent 63 | set lstProject to projects 64 | 65 | set lstFolder to folders 66 | 67 | if length of lstFolder > 0 then 68 | return lstProject & my FolderProjects(lstFolder) 69 | else 70 | return lstProject 71 | end if 72 | end tell 73 | end using terms from 74 | end ProjectList 75 | 76 | on FolderProjects(lstFolder) 77 | set lstProject to {} 78 | repeat with oFolder in lstFolder 79 | set lstProject to lstProject & ProjectList(oFolder) 80 | end repeat 81 | return lstProject 82 | end FolderProjects 83 | APPLESCRIPT}.strip 84 | end 85 | 86 | options = {} 87 | 88 | optparse = OptionParser.new do|opts| 89 | opts.banner = "Usage: #{File.basename(__FILE__)} [-r] [-t] [-n NOTE] [path]" 90 | 91 | options[:reminder] = false 92 | opts.on( '-r', '--reminder', 'Create a Reminders.app reminder' ) do 93 | options[:reminder] = true 94 | end 95 | 96 | options[:task] = false 97 | opts.on( '-t', '--task', 'Create an OmniFocus task' ) do 98 | options[:task] = true 99 | end 100 | 101 | options[:note] = "" 102 | opts.on( '-n', '--note NOTE', 'Add a note' ) do |note| 103 | options[:note] = note 104 | end 105 | 106 | opts.on( '-h', '--help', 'Display this screen' ) do 107 | puts opts 108 | exit 109 | end 110 | 111 | end 112 | 113 | optparse.parse! 114 | 115 | if ARGV[0] 116 | if File.exists? (File.expand_path(ARGV[0])) 117 | path = File.expand_path(ARGV[0]) 118 | else 119 | $stderr.puts "Directory not found: #{ARGV[0]}" 120 | end 121 | end 122 | 123 | path ||= Dir.pwd 124 | name = File.basename(path) 125 | note = path 126 | note += "\n\n#{options[:note]}" unless options[:note] == '' 127 | 128 | unless options[:reminder] || options[:task] 129 | if default_type =~ /task/i 130 | options[:task] = true 131 | else 132 | options[:reminder] = true 133 | end 134 | end 135 | 136 | if options[:reminder] 137 | puts %x{osascript <<'APPLESCRIPT' 138 | tell application "Reminders" 139 | if name of lists does not contain "#{reminders_list}" then 140 | set _reminders to make new list with properties {name:"#{reminders_list}"} 141 | else 142 | set _reminders to list "#{reminders_list}" 143 | end if 144 | make new reminder at end of _reminders with properties {name:"#{name}", body:"#{e_as(note).strip}"} 145 | return "Added reminder to #{reminders_list}" 146 | end tell 147 | APPLESCRIPT} 148 | end 149 | 150 | if options[:task] 151 | id = get_of_id(of_project) 152 | if id == '' 153 | $stderr.puts %Q{"#{of_project}" project not found} 154 | Process.exit 1 155 | end 156 | props = %Q{with properties {name:"#{name}",note:"#{note.strip}"} at beginning of project id "#{id}"} 157 | puts %x{osascript <<'APPLESCRIPT' 158 | tell application "OmniFocus" to activate 159 | tell front document of application "OmniFocus" 160 | set newTask to make new task #{props} 161 | end tell 162 | return "Task created in #{of_project}" 163 | APPLESCRIPT}.strip 164 | end 165 | --------------------------------------------------------------------------------