3

I always have the problem in my dock, where the download bar just stops and stays froze. I know you can do a killall -KILL Dock and it will fix the issue.

Is there a way to click a button or do a keyboard-shortcut that runs this Terminal command?

CousinCocaine
  • 9,748
  • 11
  • 49
  • 73
Display Name
  • 143
  • 1
  • 3
  • 9

2 Answers2

4

There are multiple ways to do this, here are 2.

First method: Create a quick script that runs after a double-click.

Create a text file, named myScript.command. The '.command' postfix will let Finder know to run it on opening.

Add the following as plain text:

#!/bin/bash
killall -KILL Dock

Now the script exists but needs to be executable. To do this you need to do a chmod.

chmod 755 myScript.command 

Running myScript.command will open a Terminal window and run the command. The first line, hashbang, will let your computer know to use bash for the following script. You can set the preferences in Terminal.app to close the terminal window after a clean exit.

Second method: Create a 'Service' and bind a keystroke to that service.

Create and install the service:

  1. Open Automator
  2. New Document -> Service
  3. Add the 'Run Shell Script' module and insert your code killall -KILL Dock
  4. Set the 'Service receives no input', save and quit.
  5. Install your newly created service by opening it in Finder and choose 'Install'.

Attach a keystroke to this service:

  1. Open 'System preferences' -> 'Keyboard' -> 'Keyboard shortcuts' -> 'Services'
  2. Find the 'Kill Dock' service and attach a keystroke to it.

Automator - Run Shell Script

CousinCocaine
  • 9,748
  • 11
  • 49
  • 73
  • If I were to add another command to the myscript.command would I just write the other command on the bottom like if I want it to KILL finder and dock. – Display Name May 07 '15 at 14:39
  • Added the fix for your problem. – CousinCocaine May 07 '15 at 19:14
  • @Ilya See [Full privileges on .command file, but it says I don't have appropriate privileges](http://apple.stackexchange.com/questions/113974/full-privileges-on-command-file-but-it-says-i-dont-have-appropriate-privilege), Gatekeeper isn't the problem here. – grg May 07 '15 at 19:15
  • @grgarside, thnx. I updated the answer. So used to this that I forgot. – CousinCocaine May 07 '15 at 19:19
  • So I used automator and did everything exactly but whenever I enable the service through Keyboard Commands it doesnt work but whenever I run it in Automator it works and restarts my dock. This it the command I set (⌃⌥⌘D). See it works fine in Automator > http://i.imgur.com/CEYnmqK.png – Display Name May 07 '15 at 23:29
  • @CousinCocaine ^ – Display Name May 08 '15 at 04:04
  • @IlyaVorobyev, does your Service exist in the System? You can check this by pressing 'Safari -> Services -> Kill Dock' (http://imgur.com/7eGVleP) – CousinCocaine May 08 '15 at 06:26
  • @CousinCocaine Ohh it only works whenever I have text selected. How can I do it so I can hit the command anywhere? – Display Name May 09 '15 at 05:46
  • @IlyaVorobyev I made this in a rush, and now it keeps comming back with small errors. Sorry. In Automator set the 'Service receives no input'. I fixed this in the screenshot and the text. – CousinCocaine May 09 '15 at 12:04
  • Oh thanks a lot I get it now :D I'm just sort of new to this. I recently made the change to mac and haven't gotten to deep into it. – Display Name May 11 '15 at 03:50
0

If you want to use a shortcut to run an applescript which runs the terminal command. here is a question on superuser with the first answer explaining how to make a shortcut to an applescript.

How to Make a Shortcut to Applescript in Automator

Make a new service and add your applescript alt

alt Make a keyboard shortcut using system preferences

Keyboard shortcuts will work across applications.


Made by rahul_send89 from Super User

Then you can do this as the applescript to the Automator input (As shown on the screenshot):

do shell script "sudo killall -KILL Dock" with administrator privileges

I put it in sudo (admin) just in case it would require.

Or without admin:

do shell script "killall -KILL Dock" with user privileges
John K
  • 2,052
  • 3
  • 23
  • 39