What I've got will run to the first 'asecho ' command and not reach the second.
What I'd like to do is create a backup of any file being edited on my local host even if it is a remote document. I'm quite sure that the fault is in my script and not in BBEdit. I searched the archives here and found nothing related to this problem.
Anyone smarter about AppleScript (and almost everyone here would fit that statement) care to point out the error of my ways?
Thanks
David
-- text document doc
on documentDidSave(doc)
-- do shell script "~/asecho 1 running"
set fromFTP to doc is FTP
-- do shell script "~/asecho 2 post fromFTP"
if fromFTP then
-- set path to URL of doc
set _ftpinfo to FTPInfo of doc
set _path to path of _ftpinfo
set _host to host of _ftpinfo
do shell script "~/asecho 3 " & quoted form of _host
set u to URL of doc
do shell script "~/asecho 4 " & u
set p to POSIX path of _path
do shell script "~/UnixEnvironment/src/script/backuptext " & p
else
set f to file of doc
set p to POSIX path of f
do shell script "~/UnixEnvironment/src/script/backuptext " & p
end if
end documentDidSave
Jean, your script works when run as an osascript, however I'm trying to run the script as a BBEdit OnDocumentSave
In that case I've fixed the syntax errors (as best I can, probably incorrectly) and it only runs to the first 'do shell script', nothing after that executes.
$HOME/asecho is just "echo $* >> $HOME/Desktop/trace" for logging purposes.
David
-- text document doc
on documentDidSave(vDocument)
do shell script "$HOME/asecho run"
if vDocument is FTP then
do shell script "$HOME/asecho is FTP file"
set vFTPInfo to FTPInfo of vDocument
set vFile to vFTPInfo's file
set vHost to vFTPInfo's host
-- set vURL to vFTPInfo's URL -- WARNING: triggers an error even though the property exists and is visible in the results pane.
set vURL to vDocument's URL
log {vHost, vURL}
do shell script "$HOME/asecho is FTP file" & vHost & " " & vURL
else
do shell script "echo is NOT FTP file"
if vDocument's modified then
save vDocument
end if
set vFile to vDocument's file
set vPosixPath to POSIX path of (vFile as string)
do shell script "$HOME/asecho is NOT FTP file" & the quoted form of vPosixPath
end if
log vFile
set vPosixPath to POSIX path of (vFile as string)
log vPosixPath
do shell script "$HOME/asecho run ls on " & the quoted form of vPosixPath
do shell script "ls -al" & space & the quoted form of vPosixPath
end documentDidSave