try
tell application "BBEdit"
tell first window
tell first document
if not (its on disk) then
error "BBEdit's front document is not saved on disk."
end if
set vName to (its name) as string
set vLanguage to (its source language) as string
ignoring case
if not (vName ends with ".tex" or vLanguage is "TeX") then
error "BBEdit's front document is not a TeX document."
end if
end ignoring
set vFile to its file
end tell
end tell
set vFilePath to POSIX path of vFile
set vDirectoryPath to do shell script "dirname" & space & the quoted form of vFilePath
set vScriptPath to vDirectoryPath & "/build.sh"
do shell script the quoted form of vScriptPath
end tell
on error aMessage
display alert aMessage as critical
end try
Name it and copy it to BBEdit's Scripts folder and in the menu Window > Palettes > Scripts palette you can assign it a keyboard shortcut.