1

I have bash script that creates a screenshot in a given directory saved as an Automator service. I've then assigned ⇪⌘2 from System Preferences > Keyboard > Shortcuts > Services. The problem is that it doesn't work much at all. The only place I've found were it actually runs when using the macro is (how random) when click on the urlbar of Safari, and even then not without inconveniences, as it popups an error message saying "The “Take Screenshot” service could not be used because the “Take Screenshot” workflow did not provide valid data. - Try running the “Take Screenshot” workflow in Automator.", even though the process works fine and the screenshot is indeed captured and saved as intended. What's wrong?

fdate=`date`
screencapture "/Users/username/Unorganized/Studio/$fdate.png"

enter image description here

  • Can you clarify whether it is the shortcut itself that usually doesn't work, or is it the Service in general that usually doesn't work? To put it another way, does the service always work when manually selecting it from the Services menu option with your mouse pointer, but usually not work when trying to activate it via the keyboard shortcut? – Monomeeth May 15 at 7:47
  • Yes, sorry. The shortcut itself is what usually doesn't work. The service itself works as intended when run within automator. It does not appear under the services menu option, however, although I suppose that's to be expected since it's not associated to any one program. – firewater May 15 at 18:34
  • Ok, since you haven't explained the process you used to create your service, I've added an answer to show all the necessary to create an Automator service that runs a bash script and how to then add a keyboard shortcut. Can you follow these steps from scratch and let me know how you go? – Monomeeth May 15 at 23:51
0

In summary you will need to use:

  • Automator to create a service that runs your bash script
  • System Preferences to assign a keyboard shortcut to the service

Below are the steps involved for each.

1. Create a service using Automator

  1. Launch Automator (usually found within your Applications folder)
  2. Go to File > New
  3. Select Service and click Choose
  4. In the top right hand of the window that appears, ensure that "No input" is selected from the Service receives drop-down list
  5. Ensure the In drop-down list is showing "Finder"
  6. In the second column containing the long list, find "Run Shell Script" and double-click on it
  7. This will add the Run Shell Script window on the right
  8. Within the Run Shell Script section ensure you have selected the "/bin/bash" option for your Shell
  9. Now add your code
  10. Save the service using a meaningful name (e.g. Take Reference Screenshot).

Now to the next step.

2. Creating your shortcut

  1. Go to System Preferences > Keyboard > Shortcuts
  2. Select Services from the sidebar
  3. Find your service (it'll be in the list on the right-hand side)
  4. Add a shortcut by double clicking on the service name
  5. Now go to System Preferences > Security & Privacy > Privacy
  6. Select Accessibility in the sidebar
  7. Click on the + sign (you may need to unlock the padlock if it's locked)
  8. Add Automator.
  9. Add Finder (to find this you will need to navigate to /System/Library/CoreServices/Finder.app).
  10. Exit your System Preferences.

Let me know how you go.

  • I've set this as the answer in so far as I feel it progresses the solution, but I'm not sure. An implication of my post is that the service is to be run from any app, so instead of "Finder", I used "Any Application" for in. I already had Finder.app added as described too, so I was left like in the beginning. By disabling ⌘+Space for Spotlight 1 the shortcut now works. Enabling it back again makes it work too, so bottomline is this feature is bugged, as detailed in a post referenced above. – firewater May 16 at 20:28

You must log in to answer this question.

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