Hi David,
`try ... on error` blocks are very useful for debugging scripts.
Before porting it to a Document Script, test your logic in the Script
Editor where you can use the `log` and `display alert/dialog` commands to
debug.
Use `the quoted form of` for paths included in your `do shell script`
commands, otherwise any space in the path will break your command.
This example snippet run from the Script Editor might help you.
tell application "BBEdit"
try
set vDocument to first text document
if vDocument's is FTP then
set vFTPInfo to (vDocument's FTP Info) as record
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}
else
if vDocument's modified then
save vDocument
end if
set vFile to vDocument's file
end if
log vFile
set vPosixPath to POSIX path of (vFile as string)
log vPosixPath
do shell script "ls -al" & space & the quoted form of vPosixPath
on error aMessage
display alert aMessage
end try
end tell
HTH,
Jean Jourdain
On Saturday, May 7, 2022 at 11:00:19 PM UTC+2 [email protected] wrote:
> 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
>
>
--
This is the BBEdit Talk public discussion group. If you have a feature request
or need technical support, please email "[email protected]" rather than
posting here. Follow @bbedit on Twitter: <https://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 view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/b9fa8c36-d5c8-450d-88fb-ca0a7a76c657n%40googlegroups.com.