Backing up files on save

23 views
Skip to first unread message

David Barto

unread,
Jul 15, 2026, 1:35:41 PM (23 hours ago) Jul 15
to bbe...@googlegroups.com
I have the script (appended) that successfully backs up files I edit on each save.
When I run this script on files opened via FTP however I don’t get the vPosixPath set to anything. Duh it’s not a local file
What I’d like is to have the script see that the document is not local and extract the remote host name (if possible) and the path on that host. Passing them along to my shell script replacing ‘localhost’ with the host name and the quoted path as seen.

Any help?

David

-- text document doc
-- put this script into ~/Library/Application Support/BBEdit/Attachment Scripts/Document.documentDidSave.scpt
use AppleScript version "2.7"
use scripting additions
--
on trace(aMessage)
set vDesktopFolder to POSIX path of (path to desktop folder as string)
set vTraceFile to vDesktopFolder & "trace.txt"
do shell script ("echo" & space & (the quoted form of aMessage) & ">>" & (the quoted form of vTraceFile))
end trace
--
on documentDidSave(vDocument)
try
tell application "BBEdit"
if class of vDocument is text document then
set vFile to vDocument's file

set vPosixPath to POSIX path of (vFile as string)
set quotedPath to the quoted form of vPosixPath
do shell script "~/UnixEnvironment/src/script/backuptext localhost " & quotedPath & " " & quotedPath
-- my trace(vPosixPath)
-- my trace("")
end if
end tell

on error aMessage
display alert aMessage
end try
end documentDidSave

GP

unread,
Jul 15, 2026, 2:42:58 PM (22 hours ago) Jul 15
to BBEdit Talk
BBEdit documents have AppleScript properties "FTP info" and "is FTP".

"is FTP" is a boolean indicating "was this document opened from (or saved to) an FTP server?" (Description from Script Debugger's BBEdit Dictionary listing.)

"FTP info" is a record with "information about a file residing on an FTP server". Script Debugger's BBEdit Dictionary listing of properties for "FTP info" is:

Property : Access : Type : Description

binary transfer : get : boolean : was the file transferred as raw binary?
file : get : file : the disk file in which this file is stored locally
host : get : text : name of the FTP server
passive : transfer : get : boolean : was the file transferred using passive FTP
password : get : text : login password for the server
path : get : text : path to the file on the server
port : get : integer : TCP connection port to the server
secure : transfer: get : boolean : was the file transferred securely?
user : get : text: login ID for the server

From what I can gather from internet searching and AI querying, you can use those properties in an AppleScript to get/construct your desired information.
Reply all
Reply to author
Forward
0 new messages