Craig,

I remembered I have a script I use for checking if the cursor is in a string, 
and realized it would be easy to change it for your needs. At least as I 
understand them.

Here is a script that will follow a path that is in between back-ticks.

It will open the file or folder according to your systems defaults as it is 
just using the bash command ‘open’.
The ‘open’ command doesn’t need an escaped URI, a quoted path will do.

You can ⌘-drop a file into a markdown file, the path will be selected. Type a 
back-tick and it should wrap the path in back-ticks. 
If you have ‘Insert matching delimiters while typing’ & ’Surround selected text 
when typing matching delimiters’ set in you preferences under ‘Completion'.

When you want to open the path just place the cursor on it (inside the 
back-ticks) and run the script.

If the path is incorrect it will beep, same if your cursor isn’t between 
back-ticks.

It would be cool to be able to hold a modifier key and click a path like a 
link, but there isn’t a way I know of to do that. You can set the script to a 
keyboard shortcut of your choosing though.

Open Ticked Path.applescript
-----------------------------------

on isPath()
        tell application "BBEdit"
                tell text window 1
                        set output to {hover:false}
                        set cursor to (characterOffset of selection) - 1
                        set cursorLine to startLine of selection
                        set searchStart to (characterOffset of line cursorLine)
                        set searchEnd to searchStart + (length of line 
cursorLine) - 1
                        if searchStart ≥ searchEnd then return output
                        set searchRange to characters searchStart thru searchEnd
                        set filePath to "`[^><|:&]+`"
                        set go to true
                        repeat while go
                                set filePathMatch to find filePath searching in 
searchRange options {search mode:grep}
                                if found of filePathMatch then
                                        set match to found object of 
filePathMatch
                                        set matchStart to (characterOffset of 
match)
                                        if cursor < matchStart then set go to 
false
                                        set matchEnd to matchStart + (length of 
match) - 1
                                        if cursor = searchEnd and matchEnd = 
searchEnd then set go to false
                                        if cursor ≥ matchStart and cursor < 
matchEnd then
                                                set output to {hover:true, 
str_start_char:matchStart, str_end_char:matchEnd}
                                                set go to false
                                        else
                                                try
                                                        set searchRange to 
characters (matchEnd + 1) thru searchEnd
                                                on error
                                                        set go to false
                                                end try
                                        end if
                                else
                                        set go to false
                                end if
                        end repeat
                        return output
                end tell
        end tell
end isPath

tell application "BBEdit"
        tell text window 1
                if hover of my isPath() is false then return beep
                set pathStart to (str_start_char of my isPath()) + 1
                set pathEnd to (str_end_char of my isPath()) - 1
                set rawPath to characters pathStart thru pathEnd as text
                try
                        do shell script "open " & the quoted form of rawPath
                on error
                        beep
                end try
        end tell
end tell

______________________


— Chris(topher)?



-- 
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/5AF6D954-6F6A-4E14-A562-56EB7E8FA96B%40rustydogink.com.

Reply via email to