Jump to content

Create new file in finder


Recommended Posts

I've recently started receiving an error with a Alfred workflow called "Create New File in Finder"

 

Ruby Code

_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'

if '{query}' == 'help' || '{query}' == '?'
	system("open", "http://ianisted.co.uk/new-finder-file-alfred-2")
	exit
else
	if '{query}' && '{query}'.include?(?.)
	  filename = '{query}'.split('.')[0]
	  extension = '{query}'.split('.')[1]
	end
	
	file = [filename, extension].join('.')
	path = [activeFinderPath, file].join
	
	if (File.exists?("#{path}"))
		exit
	end

	template = [extension, extension].join('.')
	if (File.exists?("templates/#{template}"))
	  system(%[cp "templates/#{template}" "#{path}"])
	else
	  system(%[touch "#{path}"])
	end
end

 

Error Message on Debugger

[input.keyword] Processing output of 'action.script' with arg 'testing.txt'
[ERROR: action.script] -e:15: warning: string literal in condition

Anyone have an ideas?

 

 

 

Edited by SCalkins
Link to comment

You'll be better to post your problem at the workflow thread to have the discussion there (look at the attached link). But for your question, I think if you change this line:

	if '{query}' && '{query}'.include?(?.)

To:

	if !'{query}'.empty? && '{query}'.include?(?.)

Then I think this will clear your error

 

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...