How do I add text to a new BBEdit document at creation?
I open a lot of new documents in Textwrangler/BBedit and I would like them to always have the date printed at the top. I would like this to be automatic so that I don't have to remember to run a script each time.
I'm new to BBEdit but I really like Textwrangler and have used it for years. I read some of the documentation on BB and I think that attaching some Applescript to an event might be the way to go. However, none of the listed events seem quite right, and I don't really want to add dates to existing documents.
I found the following page which was a good starting point:
http://bbeditextras.org/wiki/index.php?title=Scripting_and_Automation
I also found these relevant hooks from the BB docs:
App attachment points
- applicationDidFinishLaunching: called when the application has completed
startup. - applicationShouldQuit: called when you choose the Quit (or the application
receives a ‘quit’ event for any other reason). - applicationDidQuit: called when the application has finished shutting down and is about to exit.
- applicationDidSwitchIn: called when BBEdit has been brought to the foreground.
- applicationWillSwitchOut: called when BBEdit is being put into the background.
Document attachment points
- documentDidOpen: called when a document has been opened and is ready for use. (Since BBEdit supports multiple types of documents, your script should allow for the argument to be a document of any type.)
- documentShouldClose: called when the application is preparing to close a
document. - documentDidClose: called when the application has closed a document.
- documentShouldSave: called when the application is trying to determine whether a given document should be saved.
- documentWillSave: called when the application is about to begin saving a
document. (note that this will only be called after a successful return from a
‘documentShouldSave’. - documentDidSave: called after a document has been saved successfully.
- documentWillUnlock: called when BBEdit is going to make a document writeable. (For example, when you click the pencil to unlock a document)
- documentDidUnlock: called when BBEdit has successfully made a document
writeable. - documentWillLock: called when BBEdit is going to make a document read-only.
- documentDidLock: called when BBEdit has successfully made a document readonly.
I don't know if any of those really fit, though. I could also try adding some scripts into the startup folder, but I'm not sure how I would go about say, adding a date to all open documents. I've never done applescript before so it's a little trial and error.
I have this code that I've tried running by itself, and it works fine:
tell application "BBEdit"
tell text window 1
select insertion point after (last character)
set selection to ((current date) as string)
end tell
end tell
I'm just a little lost as to how to get the above code to execute on file creation.
applescript attachment bbedit
add a comment |
I open a lot of new documents in Textwrangler/BBedit and I would like them to always have the date printed at the top. I would like this to be automatic so that I don't have to remember to run a script each time.
I'm new to BBEdit but I really like Textwrangler and have used it for years. I read some of the documentation on BB and I think that attaching some Applescript to an event might be the way to go. However, none of the listed events seem quite right, and I don't really want to add dates to existing documents.
I found the following page which was a good starting point:
http://bbeditextras.org/wiki/index.php?title=Scripting_and_Automation
I also found these relevant hooks from the BB docs:
App attachment points
- applicationDidFinishLaunching: called when the application has completed
startup. - applicationShouldQuit: called when you choose the Quit (or the application
receives a ‘quit’ event for any other reason). - applicationDidQuit: called when the application has finished shutting down and is about to exit.
- applicationDidSwitchIn: called when BBEdit has been brought to the foreground.
- applicationWillSwitchOut: called when BBEdit is being put into the background.
Document attachment points
- documentDidOpen: called when a document has been opened and is ready for use. (Since BBEdit supports multiple types of documents, your script should allow for the argument to be a document of any type.)
- documentShouldClose: called when the application is preparing to close a
document. - documentDidClose: called when the application has closed a document.
- documentShouldSave: called when the application is trying to determine whether a given document should be saved.
- documentWillSave: called when the application is about to begin saving a
document. (note that this will only be called after a successful return from a
‘documentShouldSave’. - documentDidSave: called after a document has been saved successfully.
- documentWillUnlock: called when BBEdit is going to make a document writeable. (For example, when you click the pencil to unlock a document)
- documentDidUnlock: called when BBEdit has successfully made a document
writeable. - documentWillLock: called when BBEdit is going to make a document read-only.
- documentDidLock: called when BBEdit has successfully made a document readonly.
I don't know if any of those really fit, though. I could also try adding some scripts into the startup folder, but I'm not sure how I would go about say, adding a date to all open documents. I've never done applescript before so it's a little trial and error.
I have this code that I've tried running by itself, and it works fine:
tell application "BBEdit"
tell text window 1
select insertion point after (last character)
set selection to ((current date) as string)
end tell
end tell
I'm just a little lost as to how to get the above code to execute on file creation.
applescript attachment bbedit
add a comment |
I open a lot of new documents in Textwrangler/BBedit and I would like them to always have the date printed at the top. I would like this to be automatic so that I don't have to remember to run a script each time.
I'm new to BBEdit but I really like Textwrangler and have used it for years. I read some of the documentation on BB and I think that attaching some Applescript to an event might be the way to go. However, none of the listed events seem quite right, and I don't really want to add dates to existing documents.
I found the following page which was a good starting point:
http://bbeditextras.org/wiki/index.php?title=Scripting_and_Automation
I also found these relevant hooks from the BB docs:
App attachment points
- applicationDidFinishLaunching: called when the application has completed
startup. - applicationShouldQuit: called when you choose the Quit (or the application
receives a ‘quit’ event for any other reason). - applicationDidQuit: called when the application has finished shutting down and is about to exit.
- applicationDidSwitchIn: called when BBEdit has been brought to the foreground.
- applicationWillSwitchOut: called when BBEdit is being put into the background.
Document attachment points
- documentDidOpen: called when a document has been opened and is ready for use. (Since BBEdit supports multiple types of documents, your script should allow for the argument to be a document of any type.)
- documentShouldClose: called when the application is preparing to close a
document. - documentDidClose: called when the application has closed a document.
- documentShouldSave: called when the application is trying to determine whether a given document should be saved.
- documentWillSave: called when the application is about to begin saving a
document. (note that this will only be called after a successful return from a
‘documentShouldSave’. - documentDidSave: called after a document has been saved successfully.
- documentWillUnlock: called when BBEdit is going to make a document writeable. (For example, when you click the pencil to unlock a document)
- documentDidUnlock: called when BBEdit has successfully made a document
writeable. - documentWillLock: called when BBEdit is going to make a document read-only.
- documentDidLock: called when BBEdit has successfully made a document readonly.
I don't know if any of those really fit, though. I could also try adding some scripts into the startup folder, but I'm not sure how I would go about say, adding a date to all open documents. I've never done applescript before so it's a little trial and error.
I have this code that I've tried running by itself, and it works fine:
tell application "BBEdit"
tell text window 1
select insertion point after (last character)
set selection to ((current date) as string)
end tell
end tell
I'm just a little lost as to how to get the above code to execute on file creation.
applescript attachment bbedit
I open a lot of new documents in Textwrangler/BBedit and I would like them to always have the date printed at the top. I would like this to be automatic so that I don't have to remember to run a script each time.
I'm new to BBEdit but I really like Textwrangler and have used it for years. I read some of the documentation on BB and I think that attaching some Applescript to an event might be the way to go. However, none of the listed events seem quite right, and I don't really want to add dates to existing documents.
I found the following page which was a good starting point:
http://bbeditextras.org/wiki/index.php?title=Scripting_and_Automation
I also found these relevant hooks from the BB docs:
App attachment points
- applicationDidFinishLaunching: called when the application has completed
startup. - applicationShouldQuit: called when you choose the Quit (or the application
receives a ‘quit’ event for any other reason). - applicationDidQuit: called when the application has finished shutting down and is about to exit.
- applicationDidSwitchIn: called when BBEdit has been brought to the foreground.
- applicationWillSwitchOut: called when BBEdit is being put into the background.
Document attachment points
- documentDidOpen: called when a document has been opened and is ready for use. (Since BBEdit supports multiple types of documents, your script should allow for the argument to be a document of any type.)
- documentShouldClose: called when the application is preparing to close a
document. - documentDidClose: called when the application has closed a document.
- documentShouldSave: called when the application is trying to determine whether a given document should be saved.
- documentWillSave: called when the application is about to begin saving a
document. (note that this will only be called after a successful return from a
‘documentShouldSave’. - documentDidSave: called after a document has been saved successfully.
- documentWillUnlock: called when BBEdit is going to make a document writeable. (For example, when you click the pencil to unlock a document)
- documentDidUnlock: called when BBEdit has successfully made a document
writeable. - documentWillLock: called when BBEdit is going to make a document read-only.
- documentDidLock: called when BBEdit has successfully made a document readonly.
I don't know if any of those really fit, though. I could also try adding some scripts into the startup folder, but I'm not sure how I would go about say, adding a date to all open documents. I've never done applescript before so it's a little trial and error.
I have this code that I've tried running by itself, and it works fine:
tell application "BBEdit"
tell text window 1
select insertion point after (last character)
set selection to ((current date) as string)
end tell
end tell
I'm just a little lost as to how to get the above code to execute on file creation.
applescript attachment bbedit
applescript attachment bbedit
asked Dec 29 '18 at 2:45
CGanoteCGanote
264
264
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Open Script Editor and paste the following code in a new script document:
use BBEdit : application "BBEdit"
use scripting additions
on documentDidOpen(doc)
set n to the doc's name
set t to the doc's text as string
if n does not start with "untitled text" then return
if t's length > 0 then return
set the contents of the doc to (the (current date) as text) ¬
& linefeed & linefeed
end documentDidOpen
Save it as type script
(extension .scpt
), and name it Document.documentDidOpen.scpt
. Either save it directly, or move it subsequently, to the folder ~/Library/Application Support/BBEdit/Attachment Scripts/
; if the folder doesn't exist, create it.
Restarting BBEdit ought not to be necessary, but also couldn't hurt. Now, whenever you create a new document (of any type), it will be headed with the current date and time.
@CGanote, did this work for you ?
– CJK
Jan 1 at 17:17
I fear not; I created the folder and saved the code, but it doesn't look like it's invoking. Any advice on debugging?
– CGanote
Jan 1 at 20:50
Edit the script'sdocumentDidOpen
handler and insert a line at the very start of it that readsreturn display alert "Hello"
. You can edit the script from its current location, then simply save it. Now either open a document in BBEdit or create a new one. Does the alert appear ? Also, can you please tell me what versions of macOS and BBEdit you are using ?
– CJK
Jan 1 at 20:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53966284%2fhow-do-i-add-text-to-a-new-bbedit-document-at-creation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Open Script Editor and paste the following code in a new script document:
use BBEdit : application "BBEdit"
use scripting additions
on documentDidOpen(doc)
set n to the doc's name
set t to the doc's text as string
if n does not start with "untitled text" then return
if t's length > 0 then return
set the contents of the doc to (the (current date) as text) ¬
& linefeed & linefeed
end documentDidOpen
Save it as type script
(extension .scpt
), and name it Document.documentDidOpen.scpt
. Either save it directly, or move it subsequently, to the folder ~/Library/Application Support/BBEdit/Attachment Scripts/
; if the folder doesn't exist, create it.
Restarting BBEdit ought not to be necessary, but also couldn't hurt. Now, whenever you create a new document (of any type), it will be headed with the current date and time.
@CGanote, did this work for you ?
– CJK
Jan 1 at 17:17
I fear not; I created the folder and saved the code, but it doesn't look like it's invoking. Any advice on debugging?
– CGanote
Jan 1 at 20:50
Edit the script'sdocumentDidOpen
handler and insert a line at the very start of it that readsreturn display alert "Hello"
. You can edit the script from its current location, then simply save it. Now either open a document in BBEdit or create a new one. Does the alert appear ? Also, can you please tell me what versions of macOS and BBEdit you are using ?
– CJK
Jan 1 at 20:56
add a comment |
Open Script Editor and paste the following code in a new script document:
use BBEdit : application "BBEdit"
use scripting additions
on documentDidOpen(doc)
set n to the doc's name
set t to the doc's text as string
if n does not start with "untitled text" then return
if t's length > 0 then return
set the contents of the doc to (the (current date) as text) ¬
& linefeed & linefeed
end documentDidOpen
Save it as type script
(extension .scpt
), and name it Document.documentDidOpen.scpt
. Either save it directly, or move it subsequently, to the folder ~/Library/Application Support/BBEdit/Attachment Scripts/
; if the folder doesn't exist, create it.
Restarting BBEdit ought not to be necessary, but also couldn't hurt. Now, whenever you create a new document (of any type), it will be headed with the current date and time.
@CGanote, did this work for you ?
– CJK
Jan 1 at 17:17
I fear not; I created the folder and saved the code, but it doesn't look like it's invoking. Any advice on debugging?
– CGanote
Jan 1 at 20:50
Edit the script'sdocumentDidOpen
handler and insert a line at the very start of it that readsreturn display alert "Hello"
. You can edit the script from its current location, then simply save it. Now either open a document in BBEdit or create a new one. Does the alert appear ? Also, can you please tell me what versions of macOS and BBEdit you are using ?
– CJK
Jan 1 at 20:56
add a comment |
Open Script Editor and paste the following code in a new script document:
use BBEdit : application "BBEdit"
use scripting additions
on documentDidOpen(doc)
set n to the doc's name
set t to the doc's text as string
if n does not start with "untitled text" then return
if t's length > 0 then return
set the contents of the doc to (the (current date) as text) ¬
& linefeed & linefeed
end documentDidOpen
Save it as type script
(extension .scpt
), and name it Document.documentDidOpen.scpt
. Either save it directly, or move it subsequently, to the folder ~/Library/Application Support/BBEdit/Attachment Scripts/
; if the folder doesn't exist, create it.
Restarting BBEdit ought not to be necessary, but also couldn't hurt. Now, whenever you create a new document (of any type), it will be headed with the current date and time.
Open Script Editor and paste the following code in a new script document:
use BBEdit : application "BBEdit"
use scripting additions
on documentDidOpen(doc)
set n to the doc's name
set t to the doc's text as string
if n does not start with "untitled text" then return
if t's length > 0 then return
set the contents of the doc to (the (current date) as text) ¬
& linefeed & linefeed
end documentDidOpen
Save it as type script
(extension .scpt
), and name it Document.documentDidOpen.scpt
. Either save it directly, or move it subsequently, to the folder ~/Library/Application Support/BBEdit/Attachment Scripts/
; if the folder doesn't exist, create it.
Restarting BBEdit ought not to be necessary, but also couldn't hurt. Now, whenever you create a new document (of any type), it will be headed with the current date and time.
edited Dec 29 '18 at 13:16
answered Dec 29 '18 at 13:10
CJKCJK
2,5781216
2,5781216
@CGanote, did this work for you ?
– CJK
Jan 1 at 17:17
I fear not; I created the folder and saved the code, but it doesn't look like it's invoking. Any advice on debugging?
– CGanote
Jan 1 at 20:50
Edit the script'sdocumentDidOpen
handler and insert a line at the very start of it that readsreturn display alert "Hello"
. You can edit the script from its current location, then simply save it. Now either open a document in BBEdit or create a new one. Does the alert appear ? Also, can you please tell me what versions of macOS and BBEdit you are using ?
– CJK
Jan 1 at 20:56
add a comment |
@CGanote, did this work for you ?
– CJK
Jan 1 at 17:17
I fear not; I created the folder and saved the code, but it doesn't look like it's invoking. Any advice on debugging?
– CGanote
Jan 1 at 20:50
Edit the script'sdocumentDidOpen
handler and insert a line at the very start of it that readsreturn display alert "Hello"
. You can edit the script from its current location, then simply save it. Now either open a document in BBEdit or create a new one. Does the alert appear ? Also, can you please tell me what versions of macOS and BBEdit you are using ?
– CJK
Jan 1 at 20:56
@CGanote, did this work for you ?
– CJK
Jan 1 at 17:17
@CGanote, did this work for you ?
– CJK
Jan 1 at 17:17
I fear not; I created the folder and saved the code, but it doesn't look like it's invoking. Any advice on debugging?
– CGanote
Jan 1 at 20:50
I fear not; I created the folder and saved the code, but it doesn't look like it's invoking. Any advice on debugging?
– CGanote
Jan 1 at 20:50
Edit the script's
documentDidOpen
handler and insert a line at the very start of it that reads return display alert "Hello"
. You can edit the script from its current location, then simply save it. Now either open a document in BBEdit or create a new one. Does the alert appear ? Also, can you please tell me what versions of macOS and BBEdit you are using ?– CJK
Jan 1 at 20:56
Edit the script's
documentDidOpen
handler and insert a line at the very start of it that reads return display alert "Hello"
. You can edit the script from its current location, then simply save it. Now either open a document in BBEdit or create a new one. Does the alert appear ? Also, can you please tell me what versions of macOS and BBEdit you are using ?– CJK
Jan 1 at 20:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53966284%2fhow-do-i-add-text-to-a-new-bbedit-document-at-creation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown