MacOS – how to add button to Finder toolbar to call python script with current folder as argument

applescriptfindermacospython

Recently I added context menu under services to execute python script but I think it would be convenient if I add a button on the Finder toolbar, like next to New Folder Button in below image.

enter image description here

Is this possible at add button on Finder Toolbar that triggers a python script and passes the current folder as argument ?

Best Answer

See if this works.

Download the Get first Finder Window Path BETA 10.9 automator action from from my blog : my_very_first_automator_action

The action returns the path of the front most finder window. It does not take any input from above actions. The post explains it all :-)

Create a new Application document in Automator and add the Get first Finder Window Path to it. Then just add you Run shell script after it.

Save as Application. And then do the drag and drop.

I would test it with your code but I do not have the python slideshow...


Note from Apple documentation in regard to Third party Actions.

Installing Actions When your action has been thoroughly debugged and tested, build a deployment version of the bundle (using the proper optimizations). Then create an installation package for the action (or add the action to your application’s installation package). The installer should copy the action to /Library/Automator or ~/Library/Automator, depending on whether access to the action should be system wide or restricted to the installing user.

Instead of installing your action separately, you can put it inside the bundle of your application, especially if the action uses the features of that application. When Automator searches for actions to display, it looks inside registered applications as well in the standard Automator directories. The advantage of packaging your actions inside an application is that you don’t need to create a separate installation package to install the actions. To install the actions, users need only drag the application to a standard location.

Action bundles should be stored inside the application wrapper at Contents/Library/Automator. Thus, if your action is MyAction.action and your application is MyApp.app, the path inside the application would be:

MyApp.app/Contents/Library/Automator/MyAction.action

You can either manually copy an action into this location (after creating the necessary subdirectories) or you have Xcode copy it using a Copy Files build phase. If you copy an action into an application bundle but the application is already installed on a system, you must get Launch Services to recognize that the application has new content to register (that is, the new action) by changing the application’s modification date. You can do this by entering the touch command in the Terminal application.

sudo touch /Applications/MyApp.app

Or you can rename the application in Finder to something else, change it back to the original name, and then launch the application once.