         self.menuBuildingTask.cancel()
         self.scriptHandlersTable.removeAll()
         
+        guard let directoryURL = self.scriptsDirectoryURL else { return assertionFailure() }
+        
         let menu = MainMenu.script.menu!
         
         menu.removeAllItems()
         
-        self.addChildFileItem(in: self.scriptsDirectoryURL, to: menu)
+        self.addChildFileItem(in: directoryURL, to: menu)
         
         if !menu.items.isEmpty {
             menu.addItem(.separator())

    /// open Script menu folder in Finder
    @IBAction func openScriptFolder(_ sender: Any?) {
        
        NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: self.scriptsDirectoryURL.path)
    }
    
    

    
    private override init() {
        
        do {
            self.scriptsDirectoryURL = try FileManager.default.url(for: .applicationScriptsDirectory,
                                                                   in: .userDomainMask, appropriateFor: nil, create: true)
        } catch {
            assertionFailure("cannot create the scripts folder: \(error.localizedDescription)")
            self.scriptsDirectoryURL = nil
        }
        
        self.presentedItemURL = self.scriptsDirectoryURL
