EF Applescript tries to reimport library into itself

I’m trying to write an Applescript which tells EF to file something based on parameters passed to it. It adapts this previous forum entry EagleFiler - Hazel Script Integration… Import into EF and let EF check duplicates with just a few changes.

on hazelProcessFile(_file, _inputAttributes)
	
	-- Get the parent folder, subfolder, and library that you set in Hazel	
	set _parentFolderName to item 1 of _inputAttributes
	set _folderName to item 2 of _inputAttributes
	set _efLibrary to item 3 of _inputAttributes
	
	-- Change these to the library that you want to use
	set _libraryName to _efLibrary & ".eflibrary"
	set _libraryFolder to "/Users/jeep/Library/Mobile Documents/com~apple~CloudDocs/EagleFiler/" & _efLibrary
	set _libraryFile to POSIX file _libraryFolder & "/" & _libraryName
	
	tell application "EagleFiler"
		try
			open _libraryFile
			tell library document _libraryName
				set _folderRecord to library record _folderName of library record _parentFolderName of root folder
				set {_record} to import files {_file} container _folderRecord
			end tell
		on error errStr number errorNumber
			display dialog errStr & " : " & number & " : " & errorNumber
			error errStr number errorNumber
		end try
	end tell
end hazelProcessFile

For completeness, here’s the Applescript I use in Hazel to set the parameters

set efLibrary to "General"
set efParentFolder to "TestFolder"
set efFolder to "TestSubFolder"
return {hazelOutputAttributes:{efLibrary, efParentFolder, efFolder}}

It works… up to a point. The file is correctly loaded into the right subfolder. However… then it goes a bit haywire :frowning:

Screenshot 2020-08-30 at 3.39.49 PM

… and it hangs for a bit. If a duplicate file is then thrown into the mix, EF has to be forced quit. Hope someone can explain why my beyond-rudimentary Applescript and EF knowledge is breaking! Many thanks.

The errors mean that EagleFiler was asked to import a folder that contains the library itself, i.e. an ancestor of the library’s own folder. Of course, that doesn’t make sense.

Looking at the script, it seems like the order of attributes is not consistent when you pack them and unpack them.

Yes, sorry, that’s a little confusing. I return them from the first script in one order, then send them to the faulty script in a slightly different order. Apologies for not making that clear.

To troubleshoot this, I would try to separate what the script is doing from the actual import operation. For example, you could add a display dialog to show what the _file being imported is, and make sure that looks right. It looks like somehow it’s being passed a folder.

And then, if it does look like it’s being passed the right path, you could try manually importing that file via drag and drop and see if that works.