BBEdit 12.6 'File Save As' Issue


#1

With the new release of BBEdit a couple of Keyboard Maestro macros I rely on hiccupped. I've found a workaround and thought I'd detail here in case it helps anyone else with the same problem.

These macros all open a master text file from a master directory and save that master file in the working directory with the same name (so I don't overwrite the master text file). They call a separate macro that uses the Finder's Go to Folder command using date variables for the working directory whose name includes the current year and month.

The new version of BBEdit didn't wait for the Go to Folder macro to actually change directories. Instead, the working name was overwritten in the File Save As prompt with the working directory name.

So instead of going to "MyDisk/MyStuff/Masters/2019/02" and then displaying that directory in the File Save As dialog with the default file name "master.txt" I would see "MyDisk/MyStuff/Masters/2019/02.txt" in the dialog. (The directory name created by the Go to Folder macro replaced the selected root filename leaving the extension alone.)

The workaround was to insert a 1.5 second pause after the action that selects Save As from the BBEdit File menu and before jumping to the Go to Folder macro.

Here's an illustration of the workaround:

ss-901


#2

Hey Mike,

Generally when working with a master-file and copying it elsewhere I'll copy and rename the file before opening it it BBEdit โ€“ but what you describe can easily be done with BBEdit alone.

-Chris

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2019/03/01 14:38
# dMod: 2019/03/01 14:38 
# Appl: BBEdit
# Task: Open a Master-File and Save it to a Different Path.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Open, @Master-File, @Save, @Different, @Path
----------------------------------------------------------------

set masterTextFile to expandTilde("~/test_directory/BBEdit_Test_Dir/bbedit_test_file.txt") of me
set newDocPath to expandTilde("~/Downloads/New_File_Name.txt") of me

tell application "BBEdit"
   set masterDoc to open masterTextFile
   save masterDoc to newDocPath
end tell

----------------------------------------------------------------
--ยป HANDLERS
----------------------------------------------------------------
on expandTilde(pathStr)
   if pathStr is "~" or pathStr is "~/" then
      set pathStr to POSIX path of (path to home folder as text)
   else if pathStr starts with "~/" then
      set pathStr to (POSIX path of (path to home folder as text)) & text 3 thru -1 of pathStr
   else
      error "Bad path string!"
   end if
end expandTilde
----------------------------------------------------------------

#3

Thanks, Chris. I was just hunting around for just such an AppleScript this morning because the pause (which I moved around, duplicated and otherwise tried to spiderman) wasn't working reliably.

Increasing the pause resolved the issue temporarily but not definitively. And 'Pause Until' the OK button appeared didn't work at all but the OK is on a sheet.

Your solution is much faster than the macro I had been using that worked reliably with earlier versions of BBEdit. Scary faster. But I can adapt .

Thanks again!


#4

Hey Mike,

:sunglasses:

Just for fun โ€“ here's one way to do this with the shell.

#!/usr/bin/env bash

newFileName="New File Name.html"
targetDir=~/Downloads
masterFile=~/'test_directory/BBEdit_Test_Dir/Master-File.html'

# The `bbedit` command line tool MUST be installed.
bbedit "$(cp -v "$masterFile" "$targetDir/$newFileName" | sed -E 's!^.+-> *!!')"

I'm using the --verbose switch with cp โ€“ extracting the actual destination path with sed โ€“ and feeding that to the bbedit command line tool.

This method is also very fast.

-Chris


#5

Nice -- and it brings the new document to the front, too.

I did have to add:

#!/usr/bin/env bash -l

to the top of the action so KM can find bbedit's command line tools.


#6

Whups. Good catch.

I thought that looked funny when I posted it... :smile:

I was testing in a BBEdit shell worksheet which doesn't require the shebang line, and I forgot to add it back in.

-Chris