Project collection object in BBEdit applescript

99 views
Skip to first unread message

Neil Faiman

unread,
Jun 3, 2022, 1:26:59 PM6/3/22
to BBEdit Talk Mailing List
BBEdit 14.1.2, Mac OS Monterey 12.4

Using AppleScript, I want to navigate into a folder in a collection in a project window. I have the following script:

tell application "BBEdit"
try
set project to project document "ZBA.bbprojectd"
on error
display alert ¬
"The ZBA project is not open in BBEdit" as warning message ¬
"Open the ZBA project and try again" buttons "OK" default button "OK"
return
end try
set site to project's project collection "Site"
set cases to site's first project item whose name is "cases"
end tell

Debugging it in ScriptDebugger, the "set project” command successfully accesses the project, and sets project to a BBEdit project document object. When I examine it  in the debugger, it contains a dozen project collection elements. project collection 10 is named “Site” and represents a folder on disk. However, after executing the “set site” command, site is not a BBEdit project collection object — it is a file reference to the folder represented by the collection ( «class file» "Macintosh HD:Users:neil:Library:Mobile Documents:com~apple~CloudDocs:zba:Web Site:wiltonzba.org:" ).

Can anyone explain this behavior, or, even better, how to get at the project collection (and its contents0 as I intended?

Thanks,
Neil Faiman



jj

unread,
Jun 3, 2022, 3:11:14 PM6/3/22
to BBEdit Talk
Hi Neil,

This AppleScript snippet might help you understand how BBEdit sees the project document hierarchy.

    set v4Spaces to "    "
    tell application "BBEdit"
        set vProjectDocument to first project document
        set vProjectCollections to project collections of vProjectDocument
        repeat with vProjectCollection in vProjectCollections
            my logProjectCollection(vProjectCollection, space)
        end repeat
    end tell

    on logProjectCollection(aProjectCollection, aIndent)
        tell application "BBEdit"
            set vClass to (class of aProjectCollection) as string
            if class of aProjectCollection is project collection then
                log (aIndent & vClass & " 🗄: " & (name of aProjectCollection) as string) & space
                repeat with vSubProjectCollection in aProjectCollection
                    my logProjectCollection(vSubProjectCollection, aIndent & my v4Spaces)
                end repeat
                return
            else if class of aProjectCollection is project item then
                set vPath to POSIX path of ((file of aProjectCollection) as string)
            else if aProjectCollection is not missing value then
                set vPath to POSIX path of ((aProjectCollection) as string)
            end if
            if vPath ends with "/" then
                set vType to "📁"
            else
                set vType to "📄"
            end if
            if vClass is "«class furl»" then
                set vClass to "url"
            end if
            log aIndent & vClass & " " & vType & ": " & vPath & space
        end tell
    end logProjectCollection

HTH,

Jean Jourdain

Neil Faiman

unread,
Jun 3, 2022, 6:15:14 PM6/3/22
to BBEdit Talk Mailing List
Well, it confirms what I had already seen. That is, even though the, according to ScriptDebugger, the project collections of the project document really are project collections (and ScriptDebugger lets me zoom in and look at their contents), when I get one of those project collections in an AppleScript, what I actually get is a file reference, not a project collection.

Neil Faiman

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" 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 bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/00f1b217-7a97-4ce7-a874-3e5ae8d3cc36n%40googlegroups.com.

Neil Faiman

unread,
Jun 3, 2022, 6:17:27 PM6/3/22
to BBEdit Talk Mailing List
Well, it confirms what I had already seen. That is, even though the, according to ScriptDebugger, the project collections of the project document really are project collections (and ScriptDebugger lets me zoom in and look at their contents), when I get one of those project collections in an AppleScript, what I actually get is a file reference, not a project collection.

Neil Faiman
On Jun 3, 2022, at 3:11 PM, jj <goo...@mixio.com> wrote:

jj

unread,
Jun 4, 2022, 5:36:58 AM6/4/22
to BBEdit Talk
The question here is that the file/directory project items of the first level project collection of a project document are returned as «class furl» objects instead of the expected project item objects.
I have sent a mail to Bare Bones technical support concerning this.

Jean Jourdain

Reply all
Reply to author
Forward
0 new messages