I managed to find a workaround using Keyboard Maestro. The Compile process starts with the KM macro, which is pretty simple:
- Activate Scrivener
- Select “Show Project in Finder” in the Menu “File” – At this point, Scrivener opens a Finder window with the .scriv project file already selected.
- Set variable “
scrivener_project_path
” to text %FinderSelection%
– grabs the path from the selected file
- Set system clipboard to
scrivener_project_path
- Activate Scrivener again
- Select “Compile…” in the menu “File”
- Press button “Title:Compile” when enabled
At this point, the KM macro is finished, and the rest is handled by Scrivener. I type the desired name of the compiled .md file and click Export. Scrivener then processes and saves the compiled .md file, and then it runs the post-processing bash script using three arguments that stand for the (1) compiled_md_file
as provided by the Scrivener placeholder, (2) output_dir
, and (3) bib_file
:
<$inputfile> "squarto_output" "path/to/Zotero/MY_LIBRARY.bib"
So where is the specification of the path to the Scrivener project, aka scriv_file
? (That was my whole dilemma, after all…) Well, that happens within the bash script itself, using the pbpaste
command to insert the contents of the system clipboard that was just grabbed via the KM macro:
# Get path to .scriv project file (via system clipboard, using KM macro)
path_to_scriv_file=$(pbpaste)
# Get path to Scrivener-compiled .md file (via the first Scrivener argument)
compiled_md_file="$1"
dir=$(pwd)
path_to_compiled_md_file="$dir/$compiled_md_file"
# Get path to output_dir (via the second Scrivener argument)
# This may be a relative path, so it will be expanded
path_to_output_dir="$2"
path_to_output_dir=$(eval echo "$path_to_output_dir")
# Get path to .bib file (via the third Scrivener argument)
# This may be a relative path, so it will be expanded
path_to_bib_file="$3"
path_to_bib_file=$(eval echo "$path_to_output_dir")
The parameters are printed to a log file to help with debugging.
Finally, Squarto is run by the bash script using all of these parameters…
# Run Squarto
echo "Running Squarto..."
squarto build --scriv_file=$path_to_scriv_file --compiled_md_file=$path_to_compiled_md_file --output_dir=$path_to_output_dir --bib_file=$path_to_bib_file --bib_file_as_alias
and I open a Finder window at the location of the output (which is a Quarto book).
I did not include the command for quarto render
in the bash script. I usually run quarto preview
once at the beginning, and I mainly wanted this workflow to rebuild the folders/files so that any active Quarto preview (in a browser window) can refresh the contents while I’m working. It’s reasonably close to a live preview (but may still take some time if Quarto needs to execute code).
Last, I assigned a hotkey so that when I’m working in Scrivener, I can deploy my workflow in seconds.
It works very well… but the perfectionist in me is still pained by the fact that I have to rely on a hack via KM to get this done, and I couldn’t do it simply by using a <$projectfile>
placeholder as an argument (best choice) or via an AppleScript command to Scrivener (which doesn’t seem to have much in terms of AppleScript support, let alone Shortcuts). Oh well… I’m thankful that tools like KM exist! And thanks, @nontroppo, for mentioning your AppleScript attempt, which got me thinking about ways to grab the scriv_file
path somehow from the Scrivener window itself, before entering into the Compile modal window. I appreciate the help.