Repository: dbader/alfred-countdown-timer
Branch: master
Commit: 3f08bab53c5c
Files: 9
Total size: 9.1 KB
Directory structure:
gitextract_5y6o__cd/
├── .gitignore
├── LICENSE.txt
├── README.md
├── Timer/
│ ├── LICENSE.txt
│ ├── alarm.m4a
│ ├── info.plist
│ ├── kudos.plist
│ └── timer.py
└── Timer.alfredworkflow
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
================================================
FILE: LICENSE.txt
================================================
The MIT License (MIT)
Copyright (c) 2013 Daniel Bader
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.
================================================
FILE: README.md
================================================
# [A countdown timer extension for Alfred.app](http://dbader.org/blog/alfred-timer-extension)
A simple countdown timer command for [Alfred.app](http://www.alfredapp.com/) that uses Mountain Lion User Notifications.

The extension is described in closer detail on my [blog](http://dbader.org/blog/alfred-timer-extension).
## Benefits
- Helps you make great tea.
- Solves your [Pomodoro](http://en.wikipedia.org/wiki/Pomodoro_Technique) needs.
- Uses Mountain Lion's User Notifications to tell you when time's up.
- Plays a non-intrusive alarm sound.
- Allows you to run multiple timers at the same time.
- Allows you to add an optional label to the timer, e.g. "Laundry is done!". Thanks to [Alexander Lehmann](http://rudairandamacha.blogspot.de) for the suggestion.
- Shows you how to write Alfred extensions in Python.
## Installation
- Download [Timer.alfredworkflow](https://github.com/dbader/alfred-countdown-timer/blob/master/Timer.alfredworkflow?raw=true)
- Double-click `Timer.alfredworkflow` to install the extension.
To use this extension you need [Alfred.app](http://www.alfredapp.com/) for macOS and the [Alfred PowerPack](http://www.alfredapp.com/powerpack/).
## Usage
- The general syntax is `timer [minutes] [optional:title]`
- `timer 5` sets a countdown timer that goes off after 5 minutes.
- `timer 0:30` or `timer 0.5` sets a timer that goes off after 30 seconds.
- `timer 40 Laundry is done!` adds an optional title to the timer.
- `timer` displays usage information.
## Meta
Daniel Bader – [@dbader_org](https://twitter.com/dbader_org) – mail@dbader.org
Distributed under the MIT license. See ``LICENSE.txt`` for more information.
https://github.com/dbader/alfred-countdown-timer
================================================
FILE: Timer/LICENSE.txt
================================================
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.
================================================
FILE: Timer/info.plist
================================================
action
category
SCRIPTS
command
python timer.py {query}
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
================================================
FILE: Timer/kudos.plist
================================================
creator
Daniel Bader
website
http://dbader.org/blog/alfred-timer-extension
================================================
FILE: Timer/timer.py
================================================
#!/usr/bin/env python3
"""
A simple countdown timer command for Alfred.app that
uses Mountain Lion User Notifications.
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.
"""
import json
import os
import subprocess
import sys
import time
def main(argv):
interval = parse_time(argv)
minutes = interval / 60
seconds = interval % 60
label = ' '.join(argv[1:])
title = 'Timer started' + (': %s' % label.capitalize() if label else '.')
if minutes and seconds:
notify(title, "I'll notify you in %i:%.2i." % (minutes, seconds))
passed_time = '%i:%.2i have passed.' % (minutes, seconds)
elif minutes:
notify(title, "I'll notify you in %i %s." % (minutes,
'minute' if minutes == 1 else 'minutes'))
passed_time = '%i %s passed.' % (minutes,
'minute has' if minutes == 1 else 'minutes have')
else:
notify(title, "I'll notify you in %i seconds." % seconds)
passed_time = '%i seconds have passed.' % seconds
time.sleep(interval)
notify("Time's up" + (': %s' % label.capitalize() if label else '.'),
passed_time)
play_sound('alarm.m4a')
def parse_time(argv):
"""Parse and return the desired countdown duration in seconds from
the commandline.
"""
try:
duration = argv[0]
if ':' in duration:
# Minutes and seconds, e.g. "5:30"
minutes, seconds = duration.split(':')
return int(minutes) * 60 + int(seconds)
else:
# Just minutes, e.g. "1.5"
return int(float(duration) * 60)
except:
show_usage()
sys.exit(1)
def show_usage():
notify('Timer usage', 'timer [minutes] [optional: title]')
def notify(title, text=None):
subprocess.Popen([
'osascript',
'-e',
f'''tell application id "com.runningwithcrayons.Alfred" to run trigger "notification" in workflow "org.dbader.alfred.timer" with argument "{title}|||{text}"'''
])
def play_sound(filename):
"""Play the given sound file using the `afplay` command line utility."""
subprocess.Popen(['afplay', filename])
if __name__ == '__main__':
if len(sys.argv) > 1:
argv = sys.argv[1].split()
else:
argv = []
main(argv)