-
Notifications
You must be signed in to change notification settings - Fork 5
/
findinmail.py
executable file
·79 lines (58 loc) · 2.25 KB
/
findinmail.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python
import os
from appscript import *
import time, string
def typestring(s):
for i in range(0,len(s)):
c = s[i]
if c == '\n':
continue
if c in string.ascii_uppercase:
app(u'System Events').keystroke(s[i], using=k.shift_down)
else:
app(u'System Events').keystroke(s[i])
#print s[i]
def backtab():
app(u'System Events').keystroke("\t", using=k.shift_down)
def tab():
app(u'System Events').keystroke("\t")
def cr():
app(u'System Events').keystroke(u'\r')
app(u'System Events').keystroke(u'\n')
# sends cmd-opt-f which in mail selects the search widget
def select_search():
app(u'Mail').activate()
app(u'System Events').keystroke(u'f', using=[k.command_down, k.option_down])
def makesmartmailbox(email=u'[email protected]'):
M = app(u'Mail')
SE = app(u'System Events').processes[u'Mail']
# Open New Smart Mailbox Sheet
M.activate()
SE.menu_bars[1].menu_bar_items[u'Mailbox'].menus[1].menu_items[u'New Smart Mailbox\u2026'].click()
SMB = app(u'System Events').processes[u'Mail'].windows[1].sheets[1]
# Set Smart Mailbox Name
SMB.text_fields[1].value.set(email)
# Set rules as any
SMB.pop_up_buttons[1].click()
SMB.pop_up_buttons[1].menus[1].menu_items[1].click()
# switch to menu_items[2] to click "all"
# Select First Rule
SMB.scroll_areas[1].pop_up_buttons[1].click()
# Click "From" (2cd menu item)
SMB.scroll_areas[1].pop_up_buttons[1].menus[1].menu_items[2].click()
SMB.scroll_areas[1].text_fields[1].value.set(email)
# Create Second Rule
SMB.scroll_areas[1].buttons[u'add criterion'].click()
# the new rule type is button 3
SMB.scroll_areas[1].pop_up_buttons[3].click()
SMB.scroll_areas[1].pop_up_buttons[3].menus[1].menu_items[2].click()
# the new text area is text field 2
SMB.scroll_areas[1].text_fields[2].value.set(email)
# include messages from sent
SMB.checkboxes[u'Include messages from Sent'].click()
# Save the rule
SMB.buttons[u'OK'].click()
def test():
makesmartmailbox(u'[email protected]')
if __name__ == '__main__':
test()