Get Folderitem from NSAppleScriptMBS

  1. 4 weeks ago

    Beatrix W

    Jun 27 Pre-Release Testers Europe (Germany)

    I have a rather simple AppleScript which works fine

    with timeout of 10000 seconds
    set AccountDirectories to {}
    tell application id "com.apple.mail"
    set theAccounts to (get name of accounts whose enabled is true)
    repeat with currentAccount in theAccounts
    set the end of AccountDirectories to {account directory of account currentAccount as string}
    end repeat
    return AccountDirectories
    end tell
    end timeout

    This gives me the directories of accounts in Mail like

    {{"Macci:Users:beatrixwillius 1:Library:Mail:V5:3B5B0A3E-CB7F-42D6-AE86-B22CE46C56AA:"}, and so on.

    Before my favourite macOS Catalina I can get a Xojo folderitem out this with

    currentAccountDirectory = GetFolderItem(AccountDirectory, FolderItem.PathTypeAbsolute)

    In Catalina this is nil even with full harddisk access. If I omit "as string" I get a list of files as result. But how do I make folderitems out of these? Here is my code to get a result out of the script:

    dim theResult as NSAppleEventDescriptorMBS = theScript.execute(theError)
    
    if theResult <> nil then
      dim ResultString as string = theResult.stringValue
      if ResultString <> "" then ScriptResult = ResultString
      
      'result is array
      dim count as integer = theResult.numberOfItems
      for i as integer = 1 to count
        dim keyword as string = theResult.keywordForDescriptorAtIndex(i)
        dim item as NSAppleEventDescriptorMBS = theResult.descriptorAtIndex(i)
        
        if item <> nil then
          dim value as NSAppleEventDescriptorMBS = item.descriptorForKeyword("seld")
          if value <> nil then
            ScriptResultArray.Append value.stringValue
          ElseIf item.fileURLValue <> "" then
            ScriptResultArray.Append(item.fileURLValue)
          elseif item.stringValue <> "" then
            ScriptResultArray.Append item.stringValue
          end if
          
        else
          break
        end if
        
        if UBound(ScriptResultArray) = 0 then ScriptResult = ScriptResultArray(0)
      next
    end if

    I can get the fileURLValue of the item. But the value is also available if there is no file. If I get the accounts, then the fileURLValue is "file://iCloud". How do I get the "real" files?

  2. Beatrix W

    Jun 28 Pre-Release Testers Europe (Germany)

    I've found another solution to my main problem with accessing the files in the Mail folder. I get a shellpath to the Mail folder in the user library. Then I get a folderitem child with the name of the account directory.

    Nevertheless, I'd be interested to get a folderitem out of an AppleScript directly.

or Sign Up to reply!