Skip to content

Instantly share code, notes, and snippets.

@bps
Created March 12, 2009 15:51
Show Gist options
  • Save bps/78135 to your computer and use it in GitHub Desktop.
Save bps/78135 to your computer and use it in GitHub Desktop.
Rakefile to build plain-text applescripts and install them in ~/Library/Scripts/, maintaining proper hierarchy.
require 'ftools'
require 'rake/clean'
DESTDIR = File.join(ENV['HOME'], 'Library', 'Scripts')
SRC = FileList['**/*.applescript']
SCPTSDIR = 'build'
SCPTS = SRC.collect { |s| File.join(SCPTSDIR, s.sub(/\.applescript$/, '.scpt')) }
CLEAN.include(SCPTS)
CLEAN.include(SCPTSDIR)
verbose true
# Create directories for the build output
SCPTS.each do |s|
directory File.dirname(s)
end
directory DESTDIR
rule '.scpt' => lambda { |scpt| find_source(scpt) } do |t|
# Make sure the directory exists
Rake::Task[File.dirname(t.name)].invoke
# Compile execute-only (-x)
sh "osacompile -x -o '#{t.name}' '#{t.source}'"
end
# We want to build into a parallel directory structure, so this is used to go
# find the applescript
def find_source(scpt)
base = File.basename(scpt, '.scpt')
SRC.find { |s| File.basename(s, '.applescript') == base }
end
desc 'Compile the scripts as execute-only scpt.'
task :compile => SCPTS do
end
desc "Install scripts to #{DESTDIR}."
task :install => [:compile] do
Rake::Task[DESTDIR].invoke
SCPTS.each do |s|
# Strip off SCPTSDIR, append to DESTDIR
d = File.join(DESTDIR, s.split(File::Separator)[1..-1])
# Make sure the directory exists
directory File.dirname(d)
Rake::Task[d].invoke
puts "cp #{s} #{d}" if verbose
File.copy(s, d)
end
end
desc "Install scripts to #{DESTDIR} and clean up."
task :installclean => [:install, :clean] do
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment