-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 56bfc05
Showing
12 changed files
with
2,612 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Dean Jackson <[email protected]> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Sublime Text Projects Alfred Workflow # | ||
|
||
Filter and open your Sublime Text (2 and 3) project files. | ||
|
||
![](demo.gif "") | ||
|
||
## Usage ## | ||
|
||
Enter the keyword `.st` (the default—you can change it) in Alfred and an optional query. | ||
|
||
Hit `↩` on a result to open it in Sublime Text or `⌘+↩` to reveal in Finder. | ||
|
||
## Licensing, thanks ## | ||
|
||
All the code is released under the [MIT Licence](http://opensource.org/licenses/MIT). | ||
|
||
The icons are by [dmatarazzo](https://github.com/dmatarazzo/Sublime-Text-2-Icon). |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>bundleid</key> | ||
<string>net.deanishe.alfred-sublime-text-projects</string> | ||
<key>connections</key> | ||
<dict> | ||
<key>0D6DB001-6C1A-4973-BD3C-0CD4706096CB</key> | ||
<array> | ||
<dict> | ||
<key>destinationuid</key> | ||
<string>1F8CC3FB-B3D4-4FCB-B929-EB7E6E186DCD</string> | ||
<key>modifiers</key> | ||
<integer>0</integer> | ||
<key>modifiersubtext</key> | ||
<string></string> | ||
</dict> | ||
<dict> | ||
<key>destinationuid</key> | ||
<string>E934D964-B0B8-4A32-8DF3-4692A8F26E97</string> | ||
<key>modifiers</key> | ||
<integer>1048576</integer> | ||
<key>modifiersubtext</key> | ||
<string>Reveal in Finder</string> | ||
</dict> | ||
</array> | ||
</dict> | ||
<key>createdby</key> | ||
<string>Dean Jackson</string> | ||
<key>description</key> | ||
<string>Find and open Sublime Text projects</string> | ||
<key>disabled</key> | ||
<false/> | ||
<key>name</key> | ||
<string>Sublime Text Projects</string> | ||
<key>objects</key> | ||
<array> | ||
<dict> | ||
<key>config</key> | ||
<dict/> | ||
<key>type</key> | ||
<string>alfred.workflow.action.openfile</string> | ||
<key>uid</key> | ||
<string>1F8CC3FB-B3D4-4FCB-B929-EB7E6E186DCD</string> | ||
<key>version</key> | ||
<integer>1</integer> | ||
</dict> | ||
<dict> | ||
<key>config</key> | ||
<dict> | ||
<key>argumenttype</key> | ||
<integer>1</integer> | ||
<key>escaping</key> | ||
<integer>68</integer> | ||
<key>keyword</key> | ||
<string>.st</string> | ||
<key>runningsubtext</key> | ||
<string>Finding projects…</string> | ||
<key>script</key> | ||
<string>/usr/bin/python sublime.py "{query}"</string> | ||
<key>subtext</key> | ||
<string>Search and Open Sublime Text Projects</string> | ||
<key>title</key> | ||
<string>Sublime Text Projects</string> | ||
<key>type</key> | ||
<integer>0</integer> | ||
<key>withspace</key> | ||
<true/> | ||
</dict> | ||
<key>type</key> | ||
<string>alfred.workflow.input.scriptfilter</string> | ||
<key>uid</key> | ||
<string>0D6DB001-6C1A-4973-BD3C-0CD4706096CB</string> | ||
<key>version</key> | ||
<integer>0</integer> | ||
</dict> | ||
<dict> | ||
<key>type</key> | ||
<string>alfred.workflow.action.revealfile</string> | ||
<key>uid</key> | ||
<string>E934D964-B0B8-4A32-8DF3-4692A8F26E97</string> | ||
<key>version</key> | ||
<integer>0</integer> | ||
</dict> | ||
</array> | ||
<key>readme</key> | ||
<string></string> | ||
<key>uidata</key> | ||
<dict> | ||
<key>0D6DB001-6C1A-4973-BD3C-0CD4706096CB</key> | ||
<dict> | ||
<key>ypos</key> | ||
<real>10</real> | ||
</dict> | ||
<key>1F8CC3FB-B3D4-4FCB-B929-EB7E6E186DCD</key> | ||
<dict> | ||
<key>ypos</key> | ||
<real>10</real> | ||
</dict> | ||
<key>E934D964-B0B8-4A32-8DF3-4692A8F26E97</key> | ||
<dict> | ||
<key>ypos</key> | ||
<real>130</real> | ||
</dict> | ||
</dict> | ||
<key>webaddress</key> | ||
<string></string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
# | ||
# Copyright © 2014 [email protected] | ||
# | ||
# MIT Licence. See http://opensource.org/licenses/MIT | ||
# | ||
# Created on 2014-06-12 | ||
# | ||
|
||
""" | ||
""" | ||
|
||
from __future__ import print_function, unicode_literals | ||
|
||
import sys | ||
import os | ||
import subprocess | ||
|
||
from workflow import Workflow, ICON_WARNING | ||
|
||
VERSION = '1.0' | ||
|
||
# Log filter scores (and rules) | ||
DEBUG = True | ||
# How long to cache the list of projects for (in seconds) | ||
CACHE_DURATION = 20 | ||
|
||
# Will be set when the Workflow object is instantiated | ||
log = None | ||
decode = None | ||
|
||
|
||
def find_projects(): | ||
"""Return a list of Sublime Text project files""" | ||
cmd = ['mdfind', '-name', '.sublime-project'] | ||
output = subprocess.check_output(cmd) | ||
lines = [s.strip() for s in decode(output).split('\n') if s.strip()] | ||
log.debug('{} projects found'.format(len(lines))) | ||
return lines | ||
|
||
|
||
def main(wf): | ||
query = None | ||
args = wf.args | ||
if len(args): | ||
query = args[0] | ||
|
||
projects = wf.cached_data('projects', find_projects, max_age=15) | ||
|
||
if query: | ||
projects = wf.filter(query, projects, | ||
key=lambda p: os.path.basename(p), | ||
include_score=DEBUG, | ||
min_score=20) | ||
|
||
if DEBUG: # Show scores, rules | ||
for (path, score, rule) in projects: | ||
log.debug('{:0.2f} [{}] {}'.format(score, rule, path)) | ||
|
||
projects = [t[0] for t in projects] | ||
|
||
if not projects: | ||
wf.add_item('No matches found', | ||
'Try a different query', | ||
icon=ICON_WARNING) | ||
|
||
home = os.getenv('HOME') | ||
for path in projects: | ||
wf.add_item(os.path.basename(path).replace('.sublime-project', ''), | ||
path.replace(home, '~'), | ||
arg=path, | ||
uid=path, | ||
valid=True, | ||
icon='document_icon.png') | ||
|
||
wf.send_feedback() | ||
|
||
|
||
if __name__ == '__main__': | ||
wf = Workflow() | ||
log = wf.logger | ||
decode = wf.decode | ||
sys.exit(wf.run(main)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
# | ||
# Copyright (c) 2014 Dean Jackson <[email protected]> | ||
# | ||
# MIT Licence. See http://opensource.org/licenses/MIT | ||
# | ||
# Created on 2014-02-15 | ||
# | ||
|
||
""" | ||
A Python helper library for `Alfred 2 <http://www.alfredapp.com/>`_ Workflow | ||
authors. | ||
Alfred Workflows typically take user input, fetch data from the Web or | ||
elsewhere, filter them and display results to the user. **Alfred-Workflow** | ||
helps you do these things. | ||
There are convenience methods for: | ||
- Parsing script arguments. | ||
- Text decoding/normalisation. | ||
- Caching data and settings. | ||
- Secure storage (and sync) of passwords (using OS X Keychain). | ||
- Generating XML output for Alfred. | ||
- Including external libraries (adding directories to ``sys.path``). | ||
- Filtering results using an Alfred-like algorithm. | ||
- Generating log output for debugging. | ||
- Capturing errors, so the workflow doesn't fail silently. | ||
Quick Example | ||
============= | ||
Here's how to show recent `Pinboard.in <https://pinboard.in/>`_ posts in Alfred. | ||
Create a new Workflow in Alfred's preferences. Add a **Script Filter** with | ||
Language ``/usr/bin/python`` and paste the following into the **Script** field | ||
(changing ``API_KEY``): | ||
.. code-block:: python | ||
:emphasize-lines: 4 | ||
import sys | ||
from workflow import Workflow, ICON_WEB, web | ||
API_KEY = 'your-pinboard-api-key' | ||
def main(wf): | ||
url = 'https://api.pinboard.in/v1/posts/recent' | ||
params = dict(auth_token=API_KEY, count=20, format='json') | ||
r = web.get(url, params) | ||
r.raise_for_status() | ||
for post in r.json()['posts']: | ||
wf.add_item(post['description'], post['href'], arg=post['href'], | ||
uid=post['hash'], valid=True, icon=ICON_WEB) | ||
wf.send_feedback() | ||
if __name__ == u"__main__": | ||
wf = Workflow() | ||
sys.exit(wf.run(main)) | ||
Add an **Open URL** action to your Workflow with ``{query}`` as the **URL**, | ||
connect your **Script Filter** to it, and you can now hit **ENTER** on a | ||
Pinboard item in Alfred to open it in your browser. | ||
Installation | ||
============ | ||
Download the ``alfred-workflow-X.X.zip`` file from the | ||
`GitHub releases page <https://github.com/deanishe/alfred-workflow/releases>`_ | ||
and either extract the ZIP to the root directory of your workflow (where | ||
``info.plist`` is) or place the ZIP in the root directory and add | ||
``sys.path.insert(0, 'alfred-workflow-X.X.zip')`` to the top of your | ||
Python scripts. | ||
Alternatively, you can download | ||
`the source code <https://github.com/deanishe/alfred-workflow/archive/master.zip>`_ | ||
from the `GitHub repository <https://github.com/deanishe/alfred-workflow>`_ and | ||
copy the ``workflow`` subfolder to the root directory of your Workflow. | ||
Your Workflow directory should look something like this (where | ||
``yourscript.py`` contains your Workflow code and ``info.plist`` is | ||
the Workflow information file generated by Alfred):: | ||
Your Workflow/ | ||
info.plist | ||
icon.png | ||
workflow/ | ||
__init__.py | ||
background.py | ||
workflow.py | ||
web.py | ||
yourscript.py | ||
etc. | ||
Or like this:: | ||
Your Workflow/ | ||
info.plist | ||
icon.png | ||
workflow-1.4.zip | ||
yourscript.py | ||
etc. | ||
""" | ||
|
||
__version__ = '1.5' | ||
|
||
from .workflow import Workflow, PasswordNotFound, KeychainError | ||
from .workflow import (ICON_ERROR, ICON_WARNING, ICON_NOTE, ICON_INFO, | ||
ICON_FAVORITE, ICON_FAVOURITE, ICON_USER, ICON_GROUP, | ||
ICON_HELP, ICON_NETWORK, ICON_WEB, ICON_COLOR, | ||
ICON_COLOUR, ICON_SYNC, ICON_SETTINGS, ICON_TRASH, | ||
ICON_MUSIC, ICON_BURN, ICON_ACCOUNT, ICON_ERROR) | ||
from .workflow import (MATCH_ALL, MATCH_ALLCHARS, MATCH_ATOM, | ||
MATCH_CAPITALS, MATCH_INITIALS, | ||
MATCH_INITIALS_CONTAIN, MATCH_INITIALS_STARTSWITH, | ||
MATCH_STARTSWITH, MATCH_SUBSTRING) |
Oops, something went wrong.