macdown icon indicating copy to clipboard operation
macdown copied to clipboard

Feature Request: Refresh after write from terminal

Open somamizobuchi opened this issue 5 years ago • 1 comments

+R only applies changes made from the GUI editor. For users using text editors like vim, it'd be nice to see the preview refresh after writing to the document from a terminal. Currently, I am having to :w in the console, close the preview in MacDown, and Reopen it back in the console with the command line utility.

somamizobuchi avatar May 04 '20 05:05 somamizobuchi

I encountered the same issue. I did come up with a hack that works in my workflow. I wrote a shell script I named macdown-reopen that utilizes AppleScript:

#!/bin/sh

if [ $# != 1 ]; then
        echo "Usage: ${0##*/} path" 1>&2
        exit 1
fi
FILE=$1
NAME=${1##*/}
case $FILE in
/*);;
*) FILE=$PWD/$FILE;;
esac
osascript <<!
tell application "MacDown"
        set ws to windows
        repeat with w in ws
                if w's name is "$NAME" then
                        tell w
                                close
                        end tell
                end if
        end repeat
        open "$FILE"
end tell
!

I use this in conjunction with the the autocmd command line application I wrote some time ago.

When working on a README.md file I run the following command in a terminal:

$ autocmd README.md macdown-reopen README.md

Now each time the file README.md is modified (e.g., written out by vi) macdown-reopen README.md is run and macdown will close the current README.md window (if any) and then open up a new window with the new contents.

As I said, it is a hack, but at least I don't have to keep closing and re-opening my file in macdown each time I save it. If it helps you out, that is great. If it doesn't, well, I am sorry for the time you spent figuring that out.

pborman avatar Feb 08 '23 02:02 pborman