Open a path in a text file

90 views
Skip to first unread message

@lbutlr

unread,
Mar 13, 2021, 6:47:57 PM3/13/21
to BBEdit Talk
Greetings and happy Coviversary:

So, I have a text file that has a path to a file, and I would like to open that file, or the directory containing that file.

Currently, I copy the path manually, then paste it into the terminal (or a shell worksheet in BBEdit), and prepend

open "

And append

"

(I can skip the quotes if there are no spaces, of course)

And hit return.

The "Open" service works, but it pops up a "Bbedit wants to use the restricted service 'open'" every single time, which is almost, but not quite, as annoying as the cope/paste.

The "Open in BBEdit is fine if the file needs to be opened in BBEdit itself, but neither open nor open in BBEdit has an option to open the enclosing folder, so I have to be careful about the selection instead of just the entire line, and then since I do not want to open the PATH in BBEdit, I have to jump through the restricted dialog.

It occurs to me there must be a better way to do this? I thought of automator, but rejected that since there is no flow-control for deciding if to grab the directory or the full path, but I suppose I cold do two services?

Before I spend a lot of time noodling, any suggestions?

--
How you have felt, o men of Athens, at hearing the speeches of my
accusers, I cannot tell; but I know that their persuasive words
almost made me forget who I was, such was the effect of the,; and
yet they have hardly spoken a word of truth.

Tom Robinson

unread,
Mar 14, 2021, 4:33:31 AM3/14/21
to BBEdit Talk
If I’m following you:

1. in any macOS Open dialog, you can type a / and a special input field will appear where you can type/paste a path (to a directory, not a file)

2. in BBEdit there’s an Open File by Name command, where you can type/paste in a path to a file.

Cheers

@lbutlr

unread,
Mar 14, 2021, 5:58:38 AM3/14/21
to BBEdit Talk
On 14 Mar 2021, at 01:33, Tom Robinson <barefo...@gmail.com> wrote:
> If I’m following you:
>
> 1. in any macOS Open dialog, you can type a / and a special input field will appear where you can type/paste a path (to a directory, not a file)

Sure, but I am in BBEdit in a file with many file paths. I want to open a file from that text file.

> 2. in BBEdit there’s an Open File by Name command, where you can type/paste in a path to a file.

And that is still copying and pasting the text as opposed to, for example, rclicking on a selected line and choosing "service -> Open" which brings up that restricted service dialog and doesn't save the "open enclosing folder" behavior that I also want.

NB: the file may not be (probably is not) a file that BBEdit can open, it is just a file where I have the path in a text file.

--
The quality of our thoughts and ideas can only be as good as the
quality of our language.

jj

unread,
Mar 14, 2021, 9:27:00 AM3/14/21
to BBEdit Talk
@lbutlr,

Here is an AppleScript that might solve your problem :


Copy it somewhere in ~/Library/Library/Application\ Support/BBEdit/Scripts.

After relaunching BBEdit, you will be able to use it from the Script Menu in BBEdit and set a keyboard shortcut to it in Window > Palettes > Scripts.

Let me know if that worked for you.

Best regards,

Jean Jourdain

jj

unread,
Mar 14, 2021, 9:32:53 AM3/14/21
to BBEdit Talk
* copy it to ~/Library/Application\ Support/BBEdit/Scripts

Sam Hathaway

unread,
Mar 14, 2021, 11:40:41 AM3/14/21
to BBEdit Talk

On 13 Mar 2021, at 18:47, @lbutlr wrote:

The "Open" service works, but it pops up a "Bbedit wants to use the restricted service 'open'" every single time, which is almost, but not quite, as annoying as the cope/paste.

I made this automator action that, as far as I can tell, does the same thing as the built in “Open” service, but doesn’t trigger the confirmation prompt.

Hope this helps!
-sam

PastedImage.png

Christopher Stone

unread,
Mar 17, 2021, 7:05:32 PM3/17/21
to BBEdit-Talk
On 03/13/2021, at 17:47, @lbutlr <kre...@kreme.com> wrote:
So, I have a text file that has a path to a file, and I would like to open that file, or the directory containing that file.


Hey Lewis,

This script will pop up a dialog giving you the choice of opening the file or folder of the path selected in the front BBEdit window.  All keyboard – no mouse needed.

--
Best Regards,
Chris

--------------------------------------------------------
# Auth: Christopher Stone <script...@thestoneforge.com>
# dCre: 2021/03/17 18:02
# dMod: 2021/03/17 18:03
# Appl: BBEdit, Finder
# Task: Open a File or its Parent Folder by a Path Selected in the Front Window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Finder, @Open, @File, @Folder, @Path
--------------------------------------------------------
property LF : linefeed
property openStatusList : {"File", "Folder"}
--------------------------------------------------------

tell application "BBEdit"
    set pathStr to selection's contents
    set pathStr to replace "\\A\\s+|\\s+\\Z" searchingString pathStr using "" options {search mode:grep}
end tell

set itemAlias to alias POSIX file pathStr

set openStatus to choose from list openStatusList ¬
    with title "Open File or Folder" with prompt ¬
    "Pleae Make Your Choice:" default items {"File"} ¬
    without empty selection allowed

if openStatusfalse then

    

    set {openStatus} to openStatus

    

    tell application "Finder"
        if openStatus = "File" then
            open itemAlias
        else if openStatus = "Folder" then
            activate
            open parent of itemAlias
        end if
    end tell
end if

--------------------------------------------------------

@lbutlr

unread,
Mar 19, 2021, 2:26:15 AM3/19/21
to BBEdit Talk
On 17 Mar 2021, at 17:06, Christopher Stone <listmei...@gmail.com> wrote:
> This script will pop up a dialog giving you the choice of opening the file or folder of the path selected in the front BBEdit window. All keyboard – no mouse needed.

Thank you, that is exactly what I wanted

--
NOTHING IS FINAL. NOTHING IS ABSOLUTE. EXCEPT ME, OF COURSE. SUCH
TINKERING WITH DESTINY COULD MEAN THE DOWNFALL OF THE WORLD.
THERE MUST BE A CHANCE, HOWEVER SMALL. THE LAWYERS OF FATE DEMAND
A LOOPHOLE IN EVERY PROPHECY. --Sourcery

Reply all
Reply to author
Forward
0 new messages