On 03/29/2021, at 10:20, Steve Weiss <[email protected]
<mailto:[email protected]>> wrote:
> What I would like to do, is take all of these unsaved, untitled documents and
> save them all out to a folder so that I can just grep through them without
> having to use the Find feature in BBEdit - and then close all of the
> documents so I don't have to keep reopening all of them.
>
> How can I do this without having to press save on every single file
> individually? I've seen applescripts but they all seem to assume the files
> have already been saved once.
Hey Steve,
"Easily" done.
I've commented-out the commands that close the documents after saving, so you
can verify everything before closing them. (I'm confident it works on my
system, so I am no longer concerned about this โ but on first run especially on
a newer system I'd want to verify.)
--
Best Regards,
Chris
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2016/10/18 03:00
# dMod: 2021/03/29 10:33
# Appl: BBEdit
# Task: Save unsaved text documents and shell documents to a date-stamped
folder in the Finder.
# : Then close those documents and open the folder in the Finder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Finder, @Save, @Unsaved,
@Text_Documents, @Shell_Documents
--------------------------------------------------------
set saveFolderWasCreated to false
tell application "BBEdit"
set unsavedDocList to text documents whose on disk is false
if length of unsavedDocList > 0 then
set saveFolderPath to makeSaveFolder() of me
set saveFolderWasCreated to true
repeat with theDoc in unsavedDocList
set docName to name of theDoc
set docName to findReplTIDS(":", ";", docName) of me
set docID to ID of theDoc
save theDoc to (saveFolderPath & docName) & ".txt"
# close document id docID
end repeat
end if
set unsavedShellDocList to every shell document whose on disk is false
if length of unsavedShellDocList > 0 then
if not saveFolderWasCreated then
set saveFolderPath to makeSaveFolder()
set saveFolderWasCreated to true
end if
repeat with theDoc in unsavedShellDocList
set docID to ID of theDoc
save theDoc to (saveFolderPath & (name of theDoc)) & ".worksheet"
# close document id docID
end repeat
end if
end tell
if saveFolderWasCreated then
tell application "Finder"
activate
open (alias saveFolderPath)
end tell
end if
--------------------------------------------------------
--ยป HANDLERS
--------------------------------------------------------
on findReplTIDS(_find, _replace, _string)
set oldTIDS to AppleScript's text item delimiters
set AppleScript's text item delimiters to _find
set _string to text items of _string
set AppleScript's text item delimiters to _replace
set _string to _string as text
set AppleScript's text item delimiters to oldTIDS
return _string
end findReplTIDS
--------------------------------------------------------
on makeSaveFolder()
set newFolderName to do shell script "date \"+%Y-%m-%d %H.%M\""
set newFolderName to "BBEdit โ Untitled Docs โ Saved " & newFolderName
tell application "Finder"
set newFolder to make new folder at (path to desktop folder) with
properties {name:newFolderName}
return newFolder as text
end tell
end makeSaveFolder
--------------------------------------------------------
--
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/0C713B1E-AAEE-4DDA-B45B-4D12B3A594BE%40gmail.com.