-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathomnifocus.py
49 lines (34 loc) · 1.47 KB
/
omnifocus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import subprocess
INBOX = 'Inbox'
PROJECTS = 'Projects'
CONTEXTS = 'Contexts'
TAGS = 'Tags'
FORECAST = 'Forecast'
FLAGGED = 'Flagged'
REVIEW = 'Review'
DEFAULT_OF_VERSION = '3'
DEFAULT_OF2_PERSPECTIVES = [INBOX, PROJECTS, CONTEXTS, FORECAST, FLAGGED, REVIEW]
DEFAULT_OF3_PERSPECTIVES = [INBOX, PROJECTS, TAGS, FORECAST, FLAGGED, REVIEW]
PERSPECTIVE_SEARCH_SCRIPT = '''
tell application "OmniFocus"
try
return every perspective's name
end try
end tell
'''
LOCATION_SCRIPT = 'tell application "Finder" to get (POSIX path of (path to application "OmniFocus"))'
def list_perspectives():
results = run_script(PERSPECTIVE_SEARCH_SCRIPT)
results = [result.rstrip("\n").decode('utf-8', 'ignore') for result in results if result != "missing value"]
return DEFAULT_OF3_PERSPECTIVES + results
def search_perspectives(query):
return [perspective for perspective in list_perspectives() if query.lower() in perspective.lower()]
# see suggestion from deanishe at:
# http://www.alfredforum.com/topic/5934-search-omnifocus-free-text-search-your-omnifocus-data
def find_install_location():
results = run_script(LOCATION_SCRIPT)
return results[0].rstrip("\n")
def run_script(query):
# thanks Dr Drang: http://www.leancrew.com/all-this/2013/03/combining-python-and-applescript/
osa = subprocess.Popen(['osascript', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
return osa.communicate(query)[0].split(', ')