Skip to content

Instantly share code, notes, and snippets.

@farski
Created April 14, 2012 21:11
Show Gist options
  • Save farski/2387891 to your computer and use it in GitHub Desktop.
Save farski/2387891 to your computer and use it in GitHub Desktop.
# command
ruby extension.rb {query}
# extension.rb
_osa1 = 'tell application \"Finder\" to set insertionLocation to insertion location as alias'
_osa2 = 'return POSIX path of insertionLocation'
activeFinderPath = (`osascript -e "#{_osa1}" -e "#{_osa2}"`).strip
filename = 'untitled'
extension = 'txt'
filename = ARGV[1] if ARGV[1]
extension = ARGV[0] if ARGV[0]
if ARGV[0] && ARGV[0].include?(?.)
filename = ARGV[0].split('.')[0]
extension = ARGV[0].split('.')[1]
end
file = [filename, extension].join('.')
path = [activeFinderPath, file].join
template = [extension, extension].join('.')
if (File.exists?("templates/#{template}"))
system(%[cp "templates/#{template}" "#{path}"])
else
system(%[touch "#{path}"])
end
# templates/html.html inside the extension's folder
<html>...etc
@mrnebbi
Copy link

mrnebbi commented Apr 16, 2012

Thanks for providing a much better version of my extension. I have packaged your script up and provided it as version 2. You can find it here. http://ianisted.co.uk/new-file-for-alfred-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment