Created
April 14, 2012 21:11
-
-
Save farski/2387891 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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