Re: Warn when file type is NOT unix (or Mac)?

59 views
Skip to first unread message

Christopher Stone

unread,
Oct 23, 2012, 8:33:33 PM10/23/12
to bbe...@googlegroups.com
On Oct 23, 2012, at 18:16, Drew Schatt <dsc...@fonality.com> wrote:
> Is there any way to configure BBEdit to warn when the file type is NOT the default?
______________________________________________________________________

Hey Drew,

I don't believe there's a built-in method, but BBEdit is attachable - so it should be possible to script this.

Look in the manual under "Attaching Scripts to Menu Items".

--
Best Regards,
Chris


Rich Siegel

unread,
Oct 23, 2012, 8:50:43 PM10/23/12
to bbe...@googlegroups.com
On Tuesday, October 23, 2012, Christopher Stone
<listm...@suddenlink.net> wrote:

>I don't believe there's a built-in method, but BBEdit is attachable -
>so it should be possible to script this.
>
>Look in the manual under "Attaching Scripts to Menu Items".

In this case I would actually recommend using a script
attachment point, rather than trying to hook on to a menu item;
you'll get better behavior.

Enjoy,

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>

Someday I'll look back on all this and laugh... until they
sedate me.

John Delacour

unread,
Oct 24, 2012, 11:17:20 AM10/24/12
to bbe...@googlegroups.com
On 24/10/2012 01:50, Rich Siegel wrote:

> In this case I would actually recommend using a script attachment
> point, rather than trying to hook on to a menu item; you'll get better
> behavior.

Rich,

Could you please post a working example of Document.scpt containing the
two handlers
documentShouldSave and documentWillSave.

I have tried to follow the instructions given in the manual and am
clearly missing something, since nothing happens.

JD


Christopher Stone

unread,
Oct 25, 2012, 2:55:48 AM10/25/12
to bbe...@googlegroups.com
On Oct 24, 2012, at 10:17, John Delacour <johnde...@gmail.com> wrote:
Could you please post a working example of Document.scpt containing the two handlers
documentShouldSave and documentWillSave.
______________________________________________________________________

Hey John,

using terms from application "BBEdit"
  on documentShouldSave()
    beep
  end documentShouldSave
  on documentWillSave()
    beep
  end documentWillSave
  on documentDidSave()
    beep
  end documentDidSave
end using terms from

Using the same handler-set:

~/Library/Application Support/BBEdit/Attachment Scripts/Document.scpt

Beeps 3 times on Cmd-S or 'Save' menu selection.

~/Library/Application Support/BBEdit/Attachment Scripts/Document.documentDidSave.scpt

Beeps 1 time on Cmd-S or 'Save' menu selection.

Using BBEdit 10.5 (3221).

The attachment was live - i.e I did not have to restart BBEdit for it to start working.

--
Take Care,
Chris

rowen

unread,
Oct 31, 2012, 1:28:55 PM10/31/12
to bbe...@googlegroups.com
Here is the script I use for this purpose:

on documentDidOpen(myDoc)

tell application "BBEdit"

if class of myDoc is not text document then

return

end if

if line breaks of myDoc = Unix then

return

end if

if line breaks of myDoc = Mac then

set lineBreakName to "old style Mac"

else

set lineBreakName to "Windows"

end if

set fn to name of myDoc

set lineEndingDialog to display dialog "File \"" & fn & "\" has " & lineBreakName & " line endings" buttons {"Convert to Unix", "Preserve"} default button 1

set answer to button returned of lineEndingDialog

if answer = "Convert to Unix" then

set properties of text document 1 to {line breaks:Unix}

end if

end tell

end documentDidOpen


To install: name the script "Document.documentDidOpen.scpt" and put it in "~Library/Application Support/BBEdit/Attachment Scripts"
Some kind person at BareBones tech support gave this to me (unfortunately I can't find the email to give proper credit); I made a few tweaks.

-- Russell

On Tuesday, October 23, 2012 4:16:28 PM UTC-7, Drew Schatt wrote:
Is there any way to configure BBEdit to warn when the file type is NOT the default? I typically use Unix (LF) as my file type, and I'd find it helpful if BBEdit would warn me when I'm saving a file that has Windows linebreaks instead.
Is there some option that I'm missing?
-Drew
Reply all
Reply to author
Forward
0 new messages