# Finder - Refresh

jms1 2019-10-06

When you use Finder to work with a directory on a network or external drive, it may not automatically update itself to show changes which may have been made (i.e. files added, changed, or removed by other processes). Finder also doesn't have a way to *manually* refresh the contents of the window. There is, however, a way to tell Finder to refresh the window using Applescript.

So in order to work around this, we're going to...

* Use Automator to create an item on the "App &#x279C; Services" menu, which runs the necessary Applescript.
* Use System Preferences to set up a Keyboard shortcut which selects that item from the "App &#x279C; Services" menu.

## Automator

* Run Automator.app

* New Document

* Quick Action, "Choose"

* Workflow receives current "**no input**" in "**Finder.app**"

* On left, Library &#x279C; Utilities, drag "Run Applescript" to right

* In the Applescript item, add this:

    ```applescript
    on run {input, parameters}
        tell application "Finder" to tell front window to update every item
        return input    end run
    ```

* File &#x279C; Save...

* You will be asked for a name. This is what will appear in the Services menu. I used the name "Refresh".

At this point:

* In the Finder &#x279C; Services menu, in the "General" section, you should see a "Refresh" item.
* In other programs' menus, in the App &#x279C; Services menu, you should *not* see this item.

## Keyboard Shortcut

* System Preferences &#x279C; Keyboard

* Click the "Shortcuts" tab

* On the left, choose "Services"

* On the right, under "General", you should see your new item, with no keyboard shortcut. (There will probably be a lot of items, you may need to scroll down.)

* Click the word "none" where a keyboard short would be. This changes to an "Add Shortcut" button.

* Click that "Add Shortcut" button. A white panel appears.

* Press the shortcut key combination you want to use.

    * I tried to use **&#x2318;-R**, but the shortcut didn't appear in Finder's Services menu. I don't know for sure, but I'm guessing either Finder has some other shortcut using &#x2318;-R, or it only recognizes Services shortcuts which have &#x2303; as one of the modifiers, because **&#x2303;&#x2318;R** seems to work just fine.

* I'm not sure if this is a bug, but after pressing the shortcut, the display goes back to showing the "Add Shortcut" button. If you click on another item on the list, the button will go away and you'll see your selected shortcut instead of the button.

At this point, unless you've chosen a shortcut which already exists in Finder, pressing that shortcut key while Finder is the current app will run that Applescript code, and the front-most Finder window will refresh itself.

# Other

**`/keybase/private/jms1/bin/export-ebooks`** is a script which finds the "best" format of each ebook in the Calibre library storage directory, and prints `cp` commands which can be piped into `bash` to copy those files to a specific directory.

* The "best" format is, by default, the *first* of the following formats which exists in the book's directory:

    * `epub`
    * `pdf`
    * `txt`

    The list of formats can be overridden.

* The Calibre library directory defaults to `$HOME/BTSync/Caibre2/` (I mis-spelled it when linking the BTSync directory on this machine), this can be overridden.

* The output directory defaults to `.`, this can also be overridden.
