On Apr 12, 2015, at 14:13, ascarter <[email protected]> wrote:
> I would like to create a clipping for my Go files that inserts the correct 
> package name. The package name can be inferred from the directory of the 
> current file.
> …
> I tried using osascript -e call but that creates some sort of weird loop with 
> BBEdit and hangs.
______________________________________________________________________

Hey Andrew,

I don't see a way to do it with a placeholder, but it's simple enough with an 
AppleScript.

Full path to script (~/ — home-folder-notation not respected).

---------------------------------------------------------------------
Your clipping:
---------------------------------------------------------------------
#SCRIPT /users/chris/Library/Scripts/Working Script { Global }.scpt#

More stuff…
---------------------------------------------------------------------

Tested with BBEdit 11.1 (3717) on OSX 10.9.5

---------------------------------------------------------------------
The script (to be saved as a compiled AppleScript):
---------------------------------------------------------------------

try
  
  tell application "BBEdit"
    tell front document
      if on disk then
        set AppleScript's text item delimiters to ":"
        return "package " & text item -2 of (get its file as text)
      else
        error "The front document is not saved!"
      end if
    end tell
  end tell
  
on error e number n
  set e to e & return & return & "Num: " & n
  if n ≠ -128 then
    try
      tell current application to button returned of ¬
        (display dialog e with title "ERROR!" buttons {"Copy Error Message", 
"Cancel", "OK"} ¬
          default button "OK" giving up after 30)
      if ddButton = "Copy" then set the clipboard to e
    end try
  end if
end try

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

I also had troubles when trying to run `osascript` from a #SYSTEM <script># 
token.

I've sent in a trouble-report, so we'll soon see if it's me or BBEdit who's the 
culprit.

In any case the compiled script is the better option in this case, because it 
runs far faster.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.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 post to this group, send email to [email protected].

Reply via email to