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:
- 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/copy2remote.sh '" & p & "'" end documentDidSave
and compile it with this command:
osacompile -o Document.documentDidSave.scpt bbedit_docsave.scpt
- Create the directory ~/Library/Application Support/BBEdit/Attachment Scripts if it doesn’t exist.
- Move the compiled file Document.documentDidSave.scpt to the Attachment Scripts directory you just created (or that already existed).
- 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 copy2remote.sh 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;'` $cmd fi
That’s it. This will require tweaking to match your situation. Works in BBEdit 10.x, I haven’t tested with others version.