Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 102 lines (85 sloc) 2.355 kb
105a3fb Grant Hollingworth use the real scripts folder
authored
1 SCRIPTS_DIR = "#{ENV['HOME']}/Library/Scripts/Applications"
cda9229 Grant Hollingworth added compile and install tasks
authored
2
3 desc "Install AppleScripts for Safari and Terminal"
4 task :install => [:install_safari, :install_terminal]
5
6 desc "Compile AppleScripts for Safari and Terminal"
7 task :compile => [:compile_safari, :compile_terminal]
8
9 # utility bits
10 tab_n = (1..9).map {|n| "Go to Tab #{n}.scpt" }
11 last_tab = 'Go to Last Tab.scpt'
12
13 def compile(file, source)
14 sh "osacompile -d -o '#{file}' -e '#{source}'"
15 end
16
17 def hide_extension(file)
18 sh "test -e /usr/bin/SetFile && /usr/bin/SetFile -a E '#{file}'"
19 end
20
21 def install_scripts(app)
22 source_dir = app
23 install_dir = "#{SCRIPTS_DIR}/#{app.capitalize}"
24
25 mkdir_p install_dir
26 cp Dir["#{source_dir}/*.scpt"], install_dir
27 Dir["#{install_dir}/*.scpt"].each {|f| hide_extension f }
28 end
29
30 desc "Install Safari AppleScripts"
31 task :install_safari => :compile_safari do
32 install_scripts 'safari'
33 end
34
35 desc "Install Terminal AppleScripts"
36 task :install_terminal => :compile_terminal do
37 install_scripts 'terminal'
38 end
39
40 desc "Compile AppleScripts for Safari"
41 task :compile_safari # built up below
42
43 directory 'safari'
44 tab_n.map {|f| "safari/#{f}"}.each do |f|
45 file f => 'safari' do
46 n = f[/\d/]
47 compile f, <<-END
48 tell application "Safari"
49 try
50 tell front window to set current tab to tab #{n}
51 end try
52 end tell
53 END
54 end
55 file :compile_safari => f
56 end
57
58 file "safari/#{last_tab}" do |f|
59 compile f, <<-END
60 tell application "Safari"
61 try
62 tell front window to set current tab to last tab
63 end try
64 end tell
65 END
66 end
67 file :compile_safari => "safari/#{last_tab}"
68
69 desc "Compile AppleScripts for Terminal"
70 task :compile_terminal # built up below
71
72 directory 'terminal'
73 tab_n.map {|f| "terminal/#{f}"}.each do |f|
74 file f => 'terminal' do
75 n = f[/\d/]
76 compile f, <<-END
77 tell application "Terminal"
78 try
56ac27b Grant Hollingworth fixed tab number for Terminal scripts
authored
79 set selected of tab #{n} of front window to true
cda9229 Grant Hollingworth added compile and install tasks
authored
80 end try
81 end tell
82 END
83 end
84 file :compile_terminal => f
85 end
86
87 file "terminal/#{last_tab}" do |f|
88 compile f, <<-END
89 tell application "Terminal"
90 try
91 set selected of last tab of front window to true
92 end try
93 end tell
94 END
95 end
96 file :compile_terminal => "terminal/#{last_tab}"
97
98 desc "Remove generated files"
99 task :clean do
100 rm_rf ["scripts", "safari", "terminal"]
101 end
Something went wrong with that request. Please try again.