You should quote all paths otherwise if they contain spaces the script 
won't do what you expect.

On Wednesday, March 23, 2022 at 9:55:10 AM UTC+1 Rainer Krug wrote:

> Thanks Jean - these sound interesting options and definitely worth 
> following. But thew (especially the launch agent approach) made me 
> thinking: what if I background the quarto process?
>
> I have now written the following script to start the previewer:
>
> #!/bin/bash
>
> quarto preview $BB_DOC_PATH &
> pid=$!
> pidfile=$(dirname "${BB_DOC_PATH}")/quarto.$BB_DOC_NAME.pid
> echo pid: $pid
> echo pidfile: $pidfile
> echo $pid > $pidfile
>
> But it has two problems:
>
> 1) I still have to click "cancel", but the previewer continues running, 
> which is nice.
> 2) the file .pid does not contain the pid of the quarto process
>
> The second one, I will solve with quarto, and the first one, I can live 
> with. It would be nice, to have a message pops up which tells the user to 
> close the dialog once the preview is visible?
>
> Thanks,
>
> Rainer
>
>
> On Tuesday, March 22, 2022 at 8:12:56 PM UTC+1 jj wrote:
>
>> Hi Rainer,
>>
>> I suspect that BBEdit's Script menu will always be blocking because as 
>> far as I know it uses an XPCService. (This should be checked with Bare 
>> Bones support though!)
>>
>> I think of 2 other options that you could try:
>>
>>
>> *Option 1. Use the menubar Script Menu.* 
>>   • Activate the menubar Script Menu in Script Editor > Preferences > 
>> General > Script Menu.
>>   
>>   • Create BBEdit's application scripts directory : 
>>     
>>     % mkdir -p ~/Library/Scripts/Applications/BBEdit
>>
>>   • Scripts placed in this directory should appear in the menubar Script 
>> Menu when BBEdit is the frontmost application. Generally they act as if 
>> they where run from the Script Editor. 
>>   
>>   • Sometimes this allows you to do things you couldn't do from BBEdit's 
>> Script menu (like restarting BBEdit for example).
>>     
>> *Option 2. Create a launchAgent that watches the folder containing your 
>> quarto files and that executes a script whenever a file is saved and thus 
>> refreshes the preview. *(Replace '<rainer>' with your user account in 
>> the below paths.)
>>  
>>   • Save this launchAgent in ~/Library/LaunchAgents/quarto_watcher.plist
>>   
>>         <?xml version="1.0" encoding="UTF-8"?>
>>         <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
>>         http://www.apple.com/DTDs/PropertyList-1.0.dtd>
>>         <plist version="1.0">
>>         <dict>
>>             <key>Label</key>
>>             <string>quarto_watcher</string>
>>             <key>ProgramArguments</key>
>>             <array>
>>                 <string>/Users/<rainer>/Library/Application 
>> Support/BBEdit/Scripts/quarto_previewer.sh</string>
>>             </array>
>>             <key>WatchPaths</key>
>>             <array>
>>                 <string>/Users/<rainer>/Documents/Quarto</string>
>>             </array>
>>         </dict>
>>         </plist>
>>   
>>   • Save this script in ~/Library/Application 
>> Support/BBEdit/Scripts/quarto_previewer.sh and give it the execution 
>> permission.
>>   
>>         #!/usr/bin/env sh
>>         
>>         DOCPATH=$(osascript -e 'tell application "BBEdit" to (URL of 
>> first document) as string')
>>         EXTENSION="${DOCPATH##*.}"
>>         
>>         #echo $DOCPATH
>>         #echo $EXTENSION
>>         
>>         if [ $EXTENSION == "quarto" ]; then
>>             /usr/bin/open -a quarto "$DOCPATH"
>>         fi
>>  
>>   • Create the /Users/<rainer>/Documents/Quarto directory. (Or some 
>> other directory and change the launchAgent accordingly.)
>>   
>>   • Start the launchAgent in the terminal with:
>>   
>>      % launchctl load 
>> /Users/<rainer>/Library/LaunchAgents/quarto_watcher.plist
>>      
>>   • Now whenever a file with extension ".quarto" is saved in the 
>> ~/Documents/Quarto directory, the quarto_previewer.sh script should 
>> execute and open or reload this file in quarto.
>>   
>> HTH
>>
>> Jean Jourdain
>>
>> On Tuesday, March 22, 2022 at 2:52:19 PM UTC+1 Rainer Krug wrote:
>>
>>> I have an using quarto <https://quarto.org> to render technical 
>>> documents (it is very nice!) and writing them in BBEdit.
>>>
>>> Now I have a script which I want to start from BBEdit as I do with all 
>>> scripts, but this script runs continuously and updates the preview. I would 
>>> very much like to have this in BBEdit (in the Scripts Menu), but when I 
>>> start this script, it blocks BBEdit.
>>>
>>> Is there a way of having that dialog non-blocking? Or is there another 
>>> way of running that script (at the moment I am running it from a different 
>>> terminal)?
>>>
>>> Thanks.
>>>
>>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/e3fd0184-252f-4a89-adf9-7be6cc415343n%40googlegroups.com.

Reply via email to