Automatically sending changed files from BBEdit over SCP

If you use BBEdit on a local copy of code that you want to send to a remote server upon saving, here’s one way to do that:

  1. Create a file bbedit_docsave.scpt somewhere with the following contents:
    on documentDidSave(doc)
    set p to file of doc
    do shell script  "/Users/you/bin/ '" & p & "'"
    end documentDidSave

    and compile it with this command:

    osacompile -o Document.documentDidSave.scpt bbedit_docsave.scpt

  2. Create the directory ~/Library/Application Support/BBEdit/Attachment Scripts if it doesn’t exist.
  3. Move the compiled file Document.documentDidSave.scpt to the Attachment Scripts directory you just created (or that already existed).
  4. In /Users/you/bin (or somewhere else, but remember to adjust the path in the .scpt file above), create (and chmod 755) a file called with the following contents. Note the check for */projectname/* in the path. This is important, because BBEdit will trigger the script for all files you’ll ever edit, and you don’t want to copy all files to your remote server. Pick any marker in the file’s path that indicates it’s part of a project that you want to send to your remote server:
    # Change colons to slashes in path:
    p=`echo $1 | tr ":" "/"`
    # Check whether this is a file you want to copy
    if [[ $p == */projectname/* ]]; then
         # tweak this to match your path and server
         cmd=`echo "$p" | sed 's;^.*/projectname/\(.*\)$;scp /Users/you/devhome/projectname/\1 you@server\:~/you/projectname/\1;'`

That’s it.  This will require tweaking to match your situation.  Works in BBEdit 10.x, I haven’t tested with others version.

One thought on “Automatically sending changed files from BBEdit over SCP

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s