-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplescriptGenerator.py
47 lines (40 loc) · 1.65 KB
/
ApplescriptGenerator.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 re
import applescript
def splitOnEmptyLines(s):
# match 2 or more empty-lines (can contain spaces)
blank_line_regex = r'\r?\n\s*\n'
return re.split(blank_line_regex, s.strip())
def generate(filename, songs):
script = '''
tell application "Keynote"
activate
set thisDocument to make new document with properties {document theme:theme "Worship", width:1920, height:1080}
tell front document
'''
for song in songs:
title = song[1]
lyrics = splitOnEmptyLines(song[2])
script += '''
set currentSlide to make new slide with properties {base layout:slide layout "Title - Lyrics"}
tell currentSlide
set the object text of the default title item to "%s"
set the object text of the default body item to "%s"
end tell
''' % (title, lyrics[0])
for section in lyrics[1:]:
script += '''
set currentSlide to make new slide with properties {base layout:slide layout "Lyrics"}
tell currentSlide
set the object text of the default body item to "%s"
end tell
''' % section
script += '''
move the first slide to before first slide
delete first slide
end tell
save thisDocument in file (((path to desktop folder) as string) & "%s" & ".key")
end tell
''' % filename
# the move before delete is to let Keynote focus on the first slide
# print(script)
applescript.run(script)