diff --git a/Timer.alfredworkflow b/Timer.alfredworkflow index 61e5dca..954c842 100644 Binary files a/Timer.alfredworkflow and b/Timer.alfredworkflow differ diff --git a/Timer/info.plist b/Timer/info.plist index f72fd5d..6cb407c 100644 --- a/Timer/info.plist +++ b/Timer/info.plist @@ -2,43 +2,543 @@ - action - + bundleid + org.dbader.alfred.timer category - SCRIPTS - command - python timer.py {query} + Productivity + connections + + 1E0EB256-22B6-40E2-8D60-360D4234D802 + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + 2A5AE2D2-DDDC-4A7C-8122-1B8CF4803D4F + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + 4D6018DB-FDD4-4DD5-A9F4-886857285E9F + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + 521F2175-9FED-422E-8E6F-82E634477ED4 + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + 57D271D7-86E1-4BCD-A700-938C25A1F961 + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + 66F9D895-1105-4FA8-BA3E-FFCFF90BA718 + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + 6C9947D8-6F72-4071-A8F0-AA33DFC7D9FC + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + 89563A32-6754-46E2-A3D5-B06C504D4058 + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + A9E39FE5-FD8E-4EBD-B746-98620176507D + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + B5BB05D7-01ED-4433-8D76-69D4C77DA4BB + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + DAE2AE0D-D641-47DE-AE5E-821B401BCAD2 + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + FE60F512-821D-461F-B7D9-489E4F8BE3FE + + + destinationuid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + modifiers + 0 + modifiersubtext + + + + + createdby + Daniel Bader + description + A countdown timer that uses Mountain Lion User Notifications. disabled - escapedollar - - escapequery - - escapequerybackquotes - - escapequerybrackets - - escapequeryquotes - - escapequerysemicolons - - growloutput - - growloutputsticky - - keyword - timer - logging - - multifileargs - - parameter - 0 - silent - - subtitle - Example: timer 5:30 - title - Start a countdown timer + name + Timer + objects + + + config + + concurrently + + escaping + 62 + script + /usr/bin/python timer.py {query} > /dev/null 2>&1 & + type + 0 + + type + alfred.workflow.action.script + uid + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + version + 0 + + + config + + argumenttype + 1 + keyword + timer + subtext + Example: timer 5:30, timer killall + text + Start a countdown timer + withspace + + + type + alfred.workflow.input.keyword + uid + 1E0EB256-22B6-40E2-8D60-360D4234D802 + version + 0 + + + config + + argument + there got to be a better way + argumenttype + 3 + triggerid + betterway + triggername + there got to be a better way + workflowonly + + + type + alfred.workflow.trigger.remote + uid + 2B501686-0EE1-481D-9ADA-B84211F2553E + version + 0 + + + config + + argument + kall + argumenttype + 3 + triggerid + kall + triggername + Killall Timers + workflowonly + + + type + alfred.workflow.trigger.remote + uid + 2A5AE2D2-DDDC-4A7C-8122-1B8CF4803D4F + version + 0 + + + config + + argument + 1 + argumenttype + 3 + triggerid + t1 + triggername + Timer 1min + workflowonly + + + type + alfred.workflow.trigger.remote + uid + 521F2175-9FED-422E-8E6F-82E634477ED4 + version + 0 + + + config + + argument + 2 + argumenttype + 3 + triggerid + t2 + triggername + Timer 2min + workflowonly + + + type + alfred.workflow.trigger.remote + uid + 4D6018DB-FDD4-4DD5-A9F4-886857285E9F + version + 0 + + + config + + argument + 3 + argumenttype + 3 + triggerid + t3 + triggername + Timer 3min + workflowonly + + + type + alfred.workflow.trigger.remote + uid + 66F9D895-1105-4FA8-BA3E-FFCFF90BA718 + version + 0 + + + config + + argument + 5 + argumenttype + 3 + triggerid + t5 + triggername + Timer 5min + workflowonly + + + type + alfred.workflow.trigger.remote + uid + B5BB05D7-01ED-4433-8D76-69D4C77DA4BB + version + 0 + + + config + + argument + 10 + argumenttype + 3 + triggerid + t10 + triggername + Timer 10min + workflowonly + + + type + alfred.workflow.trigger.remote + uid + FE60F512-821D-461F-B7D9-489E4F8BE3FE + version + 0 + + + config + + argument + 15 + argumenttype + 3 + triggerid + t15 + triggername + Timer 15min + workflowonly + + + type + alfred.workflow.trigger.remote + uid + 6C9947D8-6F72-4071-A8F0-AA33DFC7D9FC + version + 0 + + + config + + argument + 30 + argumenttype + 3 + triggerid + t30 + triggername + Timer 30min + workflowonly + + + type + alfred.workflow.trigger.remote + uid + DAE2AE0D-D641-47DE-AE5E-821B401BCAD2 + version + 0 + + + config + + argument + 60:00 + argumenttype + 3 + triggerid + t60 + triggername + Timer 1hr + workflowonly + + + type + alfred.workflow.trigger.remote + uid + 89563A32-6754-46E2-A3D5-B06C504D4058 + version + 0 + + + config + + argument + 120:00 + argumenttype + 3 + triggerid + t120 + triggername + Timer 2hr + workflowonly + + + type + alfred.workflow.trigger.remote + uid + A9E39FE5-FD8E-4EBD-B746-98620176507D + version + 0 + + + config + + argument + 90:00 + argumenttype + 3 + triggerid + t90 + triggername + Timer 1hr30min + workflowonly + + + type + alfred.workflow.trigger.remote + uid + 57D271D7-86E1-4BCD-A700-938C25A1F961 + version + 0 + + + readme + A simple countdown timer command for Alfred.app that uses Mountain Lion User Notifications. + +Please note that this Workflow ***requires OS X Mountain Lion (10.8) or greater***. + +LICENSE: + +The icon is from ~MazeNL77's "nx10" icon set. + +The sound is "Ice" from Nitram+Nunca's awesome "Minutes" dashboard widget. Sadly, the company seems to have vanished. I love this sound and use it on all my devices as an alarm sound. So Nitram+Nunca, I hope it is okay for you that I include your sound file. If not please contact me and I will take it offline. + +The rest of the project is released under the MIT license. + + +Copyright (c) 2013 Daniel Bader (http://dbader.org) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + uidata + + 1E0EB256-22B6-40E2-8D60-360D4234D802 + + ypos + 10 + + 2A5AE2D2-DDDC-4A7C-8122-1B8CF4803D4F + + ypos + 130 + + 2B501686-0EE1-481D-9ADA-B84211F2553E + + ypos + 10 + + 4D6018DB-FDD4-4DD5-A9F4-886857285E9F + + ypos + 370 + + 521F2175-9FED-422E-8E6F-82E634477ED4 + + ypos + 250 + + 57D271D7-86E1-4BCD-A700-938C25A1F961 + + ypos + 1330 + + 66F9D895-1105-4FA8-BA3E-FFCFF90BA718 + + ypos + 490 + + 6C9947D8-6F72-4071-A8F0-AA33DFC7D9FC + + ypos + 850 + + 89563A32-6754-46E2-A3D5-B06C504D4058 + + ypos + 1090 + + A9E39FE5-FD8E-4EBD-B746-98620176507D + + ypos + 1210 + + B5BB05D7-01ED-4433-8D76-69D4C77DA4BB + + ypos + 610 + + DAE2AE0D-D641-47DE-AE5E-821B401BCAD2 + + ypos + 970 + + DCBD6FFA-4D13-4247-AF98-C8DFFDAD688B + + ypos + 10 + + FE60F512-821D-461F-B7D9-489E4F8BE3FE + + ypos + 730 + + + webaddress + http://dbader.org/blog/alfred-timer-extension diff --git a/Timer/timer.py b/Timer/timer.py index 9d5e887..ad1b71e 100755 --- a/Timer/timer.py +++ b/Timer/timer.py @@ -30,9 +30,47 @@ import subprocess import os import objc +import signal def main(): + + # setup interrupt + signal.signal(signal.SIGINT, handler) + + try: + actions = ["killall", "kall"] + token = (sys.argv[1]).lower() + if token in actions: + if token == actions[0] or token == actions[1]: + map(lambda x: int_process_if_possible(x), all_timers_pid()) + # even though, every timer is well behaving. + # If we force quit (kill -9) a python binary, + # it will *not* run the finially clause + # + # Should I clean or should I not. + # + # clear_timers_files() + sys.exit(0) + + except Exception as inst: + print type(inst) # the exception instance + print inst.args # arguments stored in .args + print inst # __str__ allows args to be printed directly + show_usage() + sys.exit(1) + + try: + open(timers_folder()+'/'+pid(), 'a').close() + + # Land of blocking operations + do_setTimer() + finally: + os.remove(timers_folder()+'/'+pid()) + + +def do_setTimer(): + interval = parse_time() minutes = interval / 60 seconds = interval % 60 @@ -77,7 +115,50 @@ def parse_time(): def show_usage(): - notify('Timer usage', 'timer [minutes] [optional: title]') + notify('Timer usage', 'timer [minutes|killall|kall] [optional: title]') + + +def pwd(): + return os.path.dirname(os.path.realpath(__file__)) + + +def pid(): + return str(os.getpid()) + + +def timers_folder(): + timer_hangout_place = pwd()+'/timers' + if not os.path.exists(timer_hangout_place): + os.makedirs(timer_hangout_place) + return timer_hangout_place + + +def all_timers_pid(): + timerpids = os.listdir(timers_folder()) + return filter(lambda x: x.isdigit(), timerpids) + + +def clear_timers_files(): + timerfolder = timers_folder() + timersInFolder = all_timers_pid() + try: + map(lambda pidf: os.remove(timerfolder+'/'+pidf), timersInFolder) + except: + pass + + +def int_process_if_possible(pid): + # Process doesn't exit nothing will be killed + # Let's hope this process id doesn't belong to some other process :/ + # + # Happens when timer is killed with -9 and another process + # spawn up with the same process id. + # We can't have handler for -9 to clean up our process file. + subprocess.call(["kill", "-2", str(pid)]) + + +def handler(signum, frame): + pass def swizzle(*args):