Skip to content

Instantly share code, notes, and snippets.

@alvin-milton
Last active September 10, 2020 22:43
Show Gist options
  • Select an option

  • Save alvin-milton/f2d7e8caa842ee1bf4932c8cfa01805f to your computer and use it in GitHub Desktop.

Select an option

Save alvin-milton/f2d7e8caa842ee1bf4932c8cfa01805f to your computer and use it in GitHub Desktop.

Revisions

  1. alvin-milton revised this gist Sep 10, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion empty-trash-via-hammerspoon.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    How many times do you empty your trash?

    If you are like me, sometimes a lot sometimes never.
    If you are like me, sometimes a lot, sometimes never.

    It really depends on how long you tend to keep certain files in your system.

  2. alvin-milton revised this gist Sep 10, 2020. 1 changed file with 33 additions and 13 deletions.
    46 changes: 33 additions & 13 deletions empty-trash-via-hammerspoon.md
    Original file line number Diff line number Diff line change
    @@ -1,38 +1,58 @@
    # Fun w Hammerspoon

    I wanted to automate emptying of the trash.
    How many times do you empty your trash?

    I don't want to use the mouse each time.
    If you are like me, sometimes a lot sometimes never.

    I want to be able to use the keyboard and map to a command that does this.
    It really depends on how long you tend to keep certain files in your system.

    I wanted to automate the emptying of the trash.

    I don't want to use the mouse each time because keyboard shortcuts tend to be quicker.

    So ultimately, I want to be able to use the keyboard and "map" to a command that does this.

    Sounds simple right?

    In terminal, emptying the trash looks like this:
    First step was to work out in terminal how to do this.


    Found out you'd type a command like this to get it done:

    `rm -rf ~/.Trash/*`

    I don't want to type this everytime in terminal, so I created an alias.
    I definitely don't want to type this every time in terminal.

    Thats multiple keystrokes - the antithesis of what I want to achieve, so I created an alias.

    In `~/.bash_profile` this line exists:

    `alias trash="rm -rf ~/.Trash/*`

    Aliases are cool but this still requires me to be in the terminal.
    This is closer, it maps the word trash to the command for emptying the trash.

    While aliases are cool, this still requires me to be in the terminal.

    & I'm not always in the terminal.

    I'm not always in the terminal.
    Enter [Hammerspoon](http://www.hammerspoon.org/). Feel free to check that out.

    Enter hammerspoon.
    In my Hammerspoon config, lives a little bit of Lua _which kinda looks like JS_ code that looks like this:

    ```
    hs.hotkey.bind(hyper, 'E', function()
    hs.execute('trash', true)
    end)
    ```

    `hyper` is a variable that simulates pressing CMD + SHIFT + ALT + SHIFT.
    Google on how to set that up if you haven't done it already.
    `hyper` is a variable I set higher in the config that simulates pressing the keys `CMD + SHIFT + ALT + SHIFT` together.

    Do enough research on Hammerspoon, and you'd end up understanding why this type of thing is helpful.

    [Hint, it has something to do with keyboard automation](https://karabiner-elements.pqrs.org/).

    So I'm binding to the letter E to be able to execute a terminal command.
    I use the Caps Lock key to simulate pressing all those buttons.

    The terminal command being the alias to the terminal command.
    After reloading the config, I can now press CAPS LOCK + E to execute the terminal command `trash` but without being in the terminal & this will empty my trash.

    As long as my bash profile is in tact, simply press CAPS LOCK + E and empty my trash.
    Mission achieved.
  3. alvin-milton revised this gist Sep 10, 2020. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion empty-trash-via-hammerspoon.md
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,29 @@
    # Fun w Hammerspoon

    I wanted to automate emptying of the trash.

    I don't want to use the mouse each time.

    I want to be able to use the keyboard and map to a command that does this.

    Sounds simple right?

    In terminal, emptying the trash looks like this:

    `rm -rf ~/.Trash/*`

    I don't want to type this everytime in terminal, so I created an alias.

    `alias trash="rm -rf ~/.Trash/*`

    Aliases are cool but this still requires me to be in the terminal.

    I'm not always in the terminal.

    Enter hammerspoon.
    ```hs.hotkey.bind(hyper, 'E', function()

    ```
    hs.hotkey.bind(hyper, 'E', function()
    hs.execute('trash', true)
    end)
    ```
    @@ -25,5 +32,7 @@ end)
    Google on how to set that up if you haven't done it already.

    So I'm binding to the letter E to be able to execute a terminal command.

    The terminal command being the alias to the terminal command.

    As long as my bash profile is in tact, simply press CAPS LOCK + E and empty my trash.
  4. alvin-milton created this gist Sep 10, 2020.
    29 changes: 29 additions & 0 deletions empty-trash-via-hammerspoon.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # Fun w Hammerspoon

    I wanted to automate emptying of the trash.
    I don't want to use the mouse each time.
    I want to be able to use the keyboard and map to a command that does this.

    Sounds simple right?

    In terminal, emptying the trash looks like this:
    `rm -rf ~/.Trash/*`

    I don't want to type this everytime in terminal, so I created an alias.
    `alias trash="rm -rf ~/.Trash/*`

    Aliases are cool but this still requires me to be in the terminal.
    I'm not always in the terminal.

    Enter hammerspoon.
    ```hs.hotkey.bind(hyper, 'E', function()
    hs.execute('trash', true)
    end)
    ```

    `hyper` is a variable that simulates pressing CMD + SHIFT + ALT + SHIFT.
    Google on how to set that up if you haven't done it already.

    So I'm binding to the letter E to be able to execute a terminal command.
    The terminal command being the alias to the terminal command.
    As long as my bash profile is in tact, simply press CAPS LOCK + E and empty my trash.