so I'm trying to create a service that will be located in the contextual menu of the Finder and that would allow to create a new document in the current directory.
I've been doing that using Automator: Sorry everything's in French ^^
Anyway here's the AppleScript that I'm using to retrieve the current working directory:
on run {input, parameters}
tell application "Finder"
set pwdAlias to insertion location as alias
if not (exists folder pwdAlias) then
set pwdAlias to (container of pwdAlias) as alias
end if
end tell
set pwd to POSIX path of pwdAlias
return pwd
end run
Then I'm setting this value to a variable, then creating a new text document using the variable as the path for the document and finally I'm using the command Reveal in Finder to show the created document.
Everything's is working fine except that the script seems to always be late! What I mean is that when I open a new Finder window and select my service, it is systematically creating the document on the previous window as shown below:
But then if I try a second time, the document is being created properly at the expected location:
And this is very systematic it happens every time!!
Sorry if I'm not very clear, it is not so easy to explain!
Well otherwise, I'm running Mountain Lion and here's the Automator project attached: create_new_document
To add the service just unzip and put the file under ~/Library/Services/
Hope to get some answers but I fear that this is just an Automator bug!
Try this
Set the Services selected to: 'folders' or files or folders. in 'Finder.app'
You can download the Get first Finder Window path Action from my blog post here The download is at the bottom of the post. The Action gets the posix path of the frontmost finder window. Since you are clicking on a folder in a window. that window will be the one returned.
Set Value of Variable
Get Specified Text
The next action 'New Text File' needs some input. If it does not get any, no file will be created. You can leave the text field blank. Just having the action in place works.
Drag the Variable 'path' or what ever you named it on to the Where: drop down menu.
you can click the double blue lines at the bottom of the Automator window to toggle the workflow Variable List
Save your service. And try it. (It may take a short while to show up in the contextual Menu.)