2

When creating services in automator, the topmost options is "Service receives selected..." Is there a way to create a service that just works on the currently open finder window, without having a file selected? The reason why this would be nice to have is the following:

I have my unit tests in a directory tree that duplicates that of my source code. I wrote a service using automator, applescript and php that makes it possible to toggle back and forth between the source directories and my test directories. Currently I have to select a file in the directory to activate the service. I would like to be able to just navigate to a folder and activate the service that toggles to the according directory, without having to select a file first (Sometimes there are no files yet!)

Edit: Following robmathers's suggestion in his comment to his answer I now use

tell application "Finder" to set windowTarget to the target of the front Finder window as alias
set posixPath to POSIX path of windowTarget`

which gives me the correct path to the finder window's path when I run the service in Automator.

The problem now is that the service does not show up in the "Services" panel, nor in System preferences under keyboard shortcuts when I create a new service with these settings. If I modify the existing service, It is not available when I don't have anything selected.

2

Yes, at the bottom of the Service receives drop down you’ll find a no input option. You should be able to activate it from the services menu (under the application menu, i.e. Finder → Services).

  • How do I then pass the folder name of the currently open folder to the applescript? – DudeOnRock Oct 7 '13 at 21:44
  • There are a few ways. You can try the Get Selected Finder Items, but that will only work if you use the list or column view in Finder and the folder is selected (if you just have a Finder window at the root of the folder, it doesn’t count as selected). You can also use the Ask for Finder Items action, which brings up a file/folder selection dialog. Finally, you could use an Applescript action to get the folder of the frontmost Finder window. – robmathers Oct 7 '13 at 23:11
  • Thank you, your comment was helpful in getting the path of the top window, but now the service doesn't show up under "Services" any more. Please see my edited question. Do you have any idea what might be happening? – DudeOnRock Oct 7 '13 at 23:54
  • It’s possible that it got saved as a workflow rather than a service (the title bar should indicate either workflow or service), or that the file isn’t in the services folder. To check that, hold down command (⌘) and click the icon in the title bar to show you where it’s saved. It should be ~/Library/Services. Finally, double check that it’s not in a section of the Keyboard Shortcuts prefs that you missed. The services are grouped by category, and since there’s no input, yours should appear in the general category. – robmathers Oct 8 '13 at 0:03
  • It is a service, and it is in my Services folder (which I turned into a symlink, could that be the reason? Other services I created function fine this way.) I don't have a "General" category in my services. – DudeOnRock Oct 8 '13 at 0:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .