BBEdit + AppleScript

78 views
Skip to first unread message

John Love

unread,
Apr 10, 2020, 11:01:08 PM4/10/20
to BBEdit Talk
Using an external Script, I am trying to select a pre-named BBEdit file in the left Pane, so that the selected file opens in the right Pane. 
Here is my small Script module:

tell application "BBEdit"
activate

tell application
"Finder" to set theFile to "Macintosh HD:Users:johnlove:Sites:www.lovetoteach.dev:Web_Site_Storage:lovesongforever.com:coronavirus:Coronavirus_Support/Compiled_Output_scss=css:compiled_corona_virus.html"

open file theFile  
-- select file theFile bombs with an error

end tell



It opens the file and shows it in your right Pane, but does not select it in your left Pane.

FWIW, I can go the choose File approach, but I still don't get the selection in the left Pane.

ASAMOF, what I’d really like to do is to use

select file theFile


but as noted, this bombs with an error.

John Love

Christopher Waterman

unread,
Apr 11, 2020, 8:12:15 PM4/11/20
to BBEdit Talk
I apologize I accidentally posted, then made a mistake. 
select text document 1 of poject window 1.

Christopher Waterman

unread,
Apr 11, 2020, 8:12:15 PM4/11/20
to BBEdit Talk
Try this:

tell application "BBEdit"
activate
tell application "Finder" to set theFile to "Macintosh HD:Users:johnlove:Sites:www.lovetoteach.dev:Web_Site_Storage:lovesongforever.com:coronavirus:Coronavirus_Support/Compiled_Output_scss=css:compiled_corona_virus.html"
open file theFile
select text document 2 of project window 1
end tell


Also you can set a path to a file with alias, I don't think you have to call into Finder
set theFile to alias "Macintosh HD:path:to:file"


Christopher Waterman

unread,
Apr 11, 2020, 8:12:15 PM4/11/20
to BBEdit Talk
So when I set this scenario up it works the way you want. Meaning the doc that was opened is selected in the left pane.
But, you can manipulate what file is selected.
I'm making at least one assumption. 

1. This isn't a project style window where you have two panes in the left column. One labeled Project the other labeled "Current Open Documents". Like when you make a .bbprojectd file of open a folder in BBEdit.  It IS a window with a left column marked "Currently Open Documents"

Select doesn't work on files or file paths.

Select does work on "items" of "project window" (all windows with documents are project windows).

Take a look at your window with:
tell application "BBEdit"
   
get documents of project window 1
end

You should get an output like: "{text document 1, project document "untitled project}"
So, "text document 1" is the most recently opened item.

Try this.

Rich Siegel

unread,
Apr 12, 2020, 6:31:19 PM4/12/20
to bbe...@googlegroups.com
On 4/10/20 at 8:32 PM, bbe...@googlegroups.com ('John Love' via
BBEdit Talk) wrote:

>Using an external Script, I am trying to select a pre-named
>BBEdit file in the left Pane, so that the selected file opens
>in the right Pane.

The "open" command refers a reference to the document just opened.

The "select" verb is not appropriate for use on files; it will
only work on "document" objects.

This (or something like it) ought do what you want:

tell app "BBEdit"

set openedDocument to (open POSIX file
"/path/to/some/file.txt") -- substitute your actual file path here

select openedDocument

end tell

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <https://www.barebones.com/>

Someday I'll look back on all this and laugh... until they
sedate me.

Reply all
Reply to author
Forward
0 new messages