On Nov 01, 2014, at 11:56, jgill <[email protected]> wrote:
> I'm using an AppleScript to generate a web page which needs to be saved to a
> specific local folder. I can't figure out how to access BBEdit's "Save as..."
> operation.
______________________________________________________________________
Hey Joe,
There's not a save-as command per se.
Are you saving an unsaved document?
Are you saving a previously saved document to a new location?
What exactly are you doing?
An unsaved document is easy to handle:
----------------------------------------------------------
set destFolderPath to path to downloads folder as text # HFS path.
set newFileName to "A Test File.html"
set savePath to destFolderPath & newFileName
tell application "BBEdit"
tell front text document
save to savePath
end tell
end tell
----------------------------------------------------------
If you're dealing with a previously saved file then the story is a bit
different. Handling that improperly can cause you to lose data in the original
file if it's unsaved.
Here's one way to deal with that:
----------------------------------------------------------
set destFolderPath to POSIX path of (path to downloads folder as text)
set newFileName to "A Test File.html"
set savePath to quoted form of (destFolderPath & newFileName)
tell application "BBEdit"
tell front text document
if on disk = true then
if modified of its window = true then
save
end if
set _file to quoted form of (POSIX path of (get its file))
tell AppleScript
do shell script "cp " & _file & " " & savePath
end tell
end if
end tell
end tell
----------------------------------------------------------
I've used the shell, since I can copy and rename the file in one operation.
If I wanted to be safer I could copy the file with the Finder and then rename
it. The Finder will balk if there is an existing file.
Or I could deliberately check to see if there's going to be a collision and
throw an error.
Or I could duplicate the document in BBEdit and use the first method to save it.
It really depends upon what you need to be done.
--
Best Regards,
Chris
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://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].