On 04/14/2019, at 15:49, Brandon Schneider <[email protected]
<mailto:[email protected]>> wrote:
> That was really helpful Chris, it occurred to me I completely forgot to try
> using a shortcut instead.
>
> This gets me 90% of the way there (posting the small script for time
> travelers):
> tell application "BBEdit" to activate
> tell application "BBEdit" to tell document 1 to save
> tell application "System Events" to keystroke "k" using command down
Hey Brandon,
I'd write that something like this:
------------------------------------------------------------
try
tell application "BBEdit"
-- No need for activate, since the script originates in BBEdit.
tell document 1 to save
end tell
tell application "System Events"
-- Isolate the keystroke to BBEdit – not required but is better
practice.
tell application process "BBEdit"
keystroke "k" using command down
end tell
end tell
on error e number n
stdErr(e, n, true, true) of me
end try
------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
set e to e & return & return & "Num: " & n
if beepFlag = true then
beep
end if
if ddFlag = true then
if n ≠ -128 then
try
tell application (path to frontmost application as text) to set
ddButton to button returned of ¬
(display dialog e with title "ERROR!" buttons {"Copy Error
Message", "Cancel", "OK"} ¬
default button "OK" giving up after 30)
if ddButton = "Copy Error Message" then set the clipboard to e
end try
end if
else
return e
end if
end stdErr
------------------------------------------------------------
> The ordering of the save seemed to cause a race condition, so this doesn't
> obviously meet the criteria of not saving if there's an error, but it
> certainly helps run it each save instead of me forgetting and giving me a
> nice big window.
Note the error handler in the above script. Perhaps you can use one to
mitigate this.
> I bound the script to command + s and it all works great!
Excellent!
--
Best Regards,
Chris
--
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 to the group.
Follow @bbedit on Twitter: <https://www.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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.