-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRakefile
More file actions
101 lines (85 loc) · 2.31 KB
/
Rakefile
File metadata and controls
101 lines (85 loc) · 2.31 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
SCRIPTS_DIR = "#{ENV['HOME']}/Library/Scripts/Applications"
desc "Install AppleScripts for Safari and Terminal"
task :install => [:install_safari, :install_terminal]
desc "Compile AppleScripts for Safari and Terminal"
task :compile => [:compile_safari, :compile_terminal]
# utility bits
tab_n = (1..9).map {|n| "Go to Tab #{n}.scpt" }
last_tab = 'Go to Last Tab.scpt'
def compile(file, source)
sh "osacompile -d -o '#{file}' -e '#{source}'"
end
def hide_extension(file)
sh "test -e /usr/bin/SetFile && /usr/bin/SetFile -a E '#{file}'; true"
end
def install_scripts(app)
source_dir = app
install_dir = "#{SCRIPTS_DIR}/#{app.capitalize}"
mkdir_p install_dir
cp Dir["#{source_dir}/*.scpt"], install_dir
Dir["#{install_dir}/*.scpt"].each {|f| hide_extension f }
end
desc "Install Safari AppleScripts"
task :install_safari => :compile_safari do
install_scripts 'safari'
end
desc "Install Terminal AppleScripts"
task :install_terminal => :compile_terminal do
install_scripts 'terminal'
end
desc "Compile AppleScripts for Safari"
task :compile_safari # built up below
directory 'safari'
tab_n.map {|f| "safari/#{f}"}.each do |f|
file f => 'safari' do
n = f[/\d/]
compile f, <<-END
tell application "Safari"
try
tell front window to set current tab to tab #{n}
end try
end tell
END
end
file :compile_safari => f
end
file "safari/#{last_tab}" do |f|
compile f, <<-END
tell application "Safari"
try
tell front window to set current tab to last tab
end try
end tell
END
end
file :compile_safari => "safari/#{last_tab}"
desc "Compile AppleScripts for Terminal"
task :compile_terminal # built up below
directory 'terminal'
tab_n.map {|f| "terminal/#{f}"}.each do |f|
file f => 'terminal' do
n = f[/\d/]
compile f, <<-END
tell application "Terminal"
try
set selected of tab #{n} of front window to true
end try
end tell
END
end
file :compile_terminal => f
end
file "terminal/#{last_tab}" do |f|
compile f, <<-END
tell application "Terminal"
try
set selected of last tab of front window to true
end try
end tell
END
end
file :compile_terminal => "terminal/#{last_tab}"
desc "Remove generated files"
task :clean do
rm_rf ["scripts", "safari", "terminal"]
end