Right... I finally got it. It's much more than I described, but it covers
all of my needs, since sometimes I edit the same file today with Sublime,
tomorrow with BBEdit. :)
Here's the script:
*tell* *application* "BBEdit"
*set* w *to* *text window* 1
*set* the_file *to* *file* *of* active document *of* w *as* *text*
*set* filePath *to* POSIX path *of* the_file
*end* *tell*
*set* parentDirectory *to* *POSIX file* (*do shell script* "dirname " & quoted
form *of* POSIX path *of* the_file) *as* *alias*
*set* wantedExtensions *to* {"tex", "pdf", ".ist", "tags", "eps",
"bbprojectd", ".sublime-project", "sublime-workspace", "txt", "html", "xml"}
*tell* *application* "Finder"
*delete* (*every* *file* *of* *folder* parentDirectory *whose* name
extension *is not* *in* wantedExtensions *and* name *is* *not* "tags" *and*
name *is* *not* "indices.ist" *and* name *does not* *end* *with*
".sublime-project" *and* name *does not* *end* *with* ".sublime-workspace")
*display dialog* "Folder cleaned." buttons {"OK"}
*end* *tell*
On Sunday, February 26, 2017 at 3:22:47 PM UTC+2, Adrian Manea wrote:
>
> OK, I'm pretty sure this is an easy one, but since I have close to zero
> experience with AppleScript, I have to ask:
>
> Could anyone please help me with a script that gets the path to the
> containing folder of the current (open, frontmost) text file of BBEdit?
>
> Concrete use: I would then add to the script the command to delete from
> that folder files by extension. When running pdflatex, I get lots of
> auxiliary files that are not needed, so I intend to use such a script for
> "cleaning up" the folder, to be left only with .tex and .pdf files in that
> folder.
>
> I would add to the script something like:
>
>
> *tell* *application* "Finder"
>
> *delete* (*every* *item* *of* *folder* (*path to* filePath) *whose* name
> *does
> not* *end* *with* ".tex" *or* ".pdf" *or* ".eps" *or* ".bbprojectd" *or*
> "tags" *or* ".ist")
>
> *end* *tell*
>
> But the hardest part is getting that filePath...
>
> Thank you!
>
--
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].
Visit this group at https://groups.google.com/group/bbedit.