I'm reviving this thread to post some more updates and also ask for
some help.

1. As mentioned previously I've used ascarter's script as a
Document.documentDidSave. After doing it BBEdit started to freeze even
if I wasn't just navigating through a project.

The reason for BBEdit freezing was exactly the tags generation script.
BBEdit is performing autosaves and so it was triggering it very often.
In fact it was so often that made BBEdit almost unusable with decently
sized projects.

Lesson learned: don't use the tags generation script as a
documentDidSave event, except you can filter an actual source file
save.

2.  The conclusion above made me think that a better event to attach
the tags generation would be the Save action. So I've transformed it
into a File • Save script.

This approach has solved the above issue, but the script in the
current form was not able to make the difference between a real
project (with a folder structure) and a bunch a separate files opened
in the current window.

3. This is the part where I'm asking for help. The script in the
current form can be found at the end of the post. What I'd need help
with is:

3.1 Is there a way to determine if the current window belongs to a
real project vs a set of random files?

3.2. Could someone validate the following code snippet which tries to
get the parent folder if the main script result is a file:


                if kind of (info for theFile) is "folder" then
                        -- Run the maketags script
                        set thePath to POSIX path of theFile
                else
                        set thePath to POSIX path of (container of theFile)
                end if
                set cmd to "cd " & thePath & "; /usr/local/bin/bbedit 
--maketags"

3.3 Is there a way to install this script and trigger it through a
menu item/shortcut against the current project instead of having it
automatically triggered by the Save action?

on menuselect(menuName, itemName)
        if menuName = "File" and itemName = "Save" then
                -- must return false to let the application do the work
                return false
        end if
end menuselect
on postmenuselect(menuName, itemName)
        -- this is called after the application has processed
        -- the command
        if menuName = "File" and itemName = "Save" then
                my makeTags()
        end if
end postmenuselect

on makeTags()
        set theFile to missing value

        tell application "BBEdit"
                set activeWindow to front window

                if (class of activeWindow is project window) then
                        set projectDocument to project document of activeWindow

                        if ((count of items of projectDocument) > 0) then
                                set firstFileItem to item 1 of projectDocument 
as alias
                        else
                                set firstFileItem to file of document of 
activeWindow as alias
                        end if

                        if (on disk of projectDocument) then
                                set theProjectFile to file of projectDocument 
as alias

                                tell application "Finder"
                                        set theProjectDir to container of 
theProjectFile
                                        set firstFileDir to container of 
firstFileItem
                                end tell

                                if (firstFileDir is equal to theProjectDir) then
                                        -- Use project file
                                        set theFile to theProjectDir as alias
                                else
                                        -- External project file -> use first 
item to set context
                                        set theFile to firstFileItem
                                end if
                        else
                                -- BBEdit doesn't provide direct access to the 
Instaproject root
                                -- Use the first node from the project list
                                set theFile to firstFileItem
                        end if
                end if
        end tell

        if theFile is equal to missing value then
                -- No base file found for reference
                -- Signal error by beep and end
                -- beep
        else
                if kind of (info for theFile) is "folder" then
                        -- Run the maketags script
                        set thePath to POSIX path of theFile
                else
                        set thePath to POSIX path of (container of theFile)
                end if
                set cmd to "cd " & thePath & "; /usr/local/bin/bbedit 
--maketags"
                do shell script cmd
        end if
end makeTags

Many thanks in advance for the help,

A://

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
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>

Reply via email to