AppleScript to append filename to tag

Hi There,

I am new to Eaglefiler and loving the software but loving my crappy file organisation so trying to clean that up a bit!

I have imported the MBOX files for all my old emails and would like to now append those filenames (wihtout the extension) as tags so I can then amalgamate all the MBOX files into a single one later without losing this metadata.

I had a crack at writing the following script and added to the Eaglefiler Applescript directory thinking it might work its way through the records and do the append. But alas it does not seem to work! I keep getting the error that no records are selected even though I have 12 records selected in the Eaglefiler window.

I have looked at the other example scripts to make sure I have the calls right, etc but can’t figure it out! Can someone help me untangle myself?

tell application "EagleFiler"
	try
		set _records to selected records of browser window 1
		if _records is {} then
			display dialog "No records selected." buttons {"OK"} default button 1
			return
		end if
	on error
		display dialog "Could not access selected records." buttons {"OK"} default button 1
		return
	end try
	
	repeat with _record in _records
		try
			set _filename to _record's filename
			set _fileBaseName to my removeExtension(_filename)
			set _existingTags to assigned tag names of _record
			
			if _fileBaseName is not in _existingTags then
				set assigned tag names of _record to (_existingTags & {_fileBaseName})
			end if
		end try
	end repeat
end tell

-- Helper to remove file extension
on removeExtension(theName)
	set AppleScript's text item delimiters to "."
	set nameParts to text items of theName
	if (count of nameParts) > 1 then
		set AppleScript's text item delimiters to "."
		return (text 1 thru ((offset of "." in theName) - 1)) of theName
	else
		return theName
	end if
end removeExtension

Thanks heaps in advance!

Cheers
Supersimmo

selected records will give you the mailboxes selected in the records list (at the right), not in the source list (at the left). You probably want current records, which will get the selection from either the source list or the records list, depending on which pane has focus.

Here’s how I would write the script:

tell application "EagleFiler"
    set _records to current records of browser window 1
    repeat with _record in _records
        tell _record
            set assigned tag names to assigned tag names & {basename}
        end tell
    end repeat
end tell

There’s a built-in property to get the base filename, and if you assign a tag that’s already there EagleFiler will automatically skip it.

But I’m not sure this script will actually solve your problem because it tags the mailboxes, not the messages. Messages are currently not scriptable in EagleFiler.

I’m curious why you want to merge the mailboxes if it also matters to you which mailbox each message came from.

Hi Michael,

Thanks for your replies and great to e-meet you.

So it seems I am out of luck with the direction I was trying to head!

To answer your curiosity, I have imported a large number of past email messages (different sources, formats, etc), adding up to 400,000 records. As a result, I have a few hundred MBOX files now in various nested directories with specific names relating to the topic/tag the messages contained. My thinking, based on reading the optimisation notes in your EF manual, is that I am better off merging these MBOX files. But in doing so, I would lose the MBOX name (and hence tag) relating to it. So my plan was the tag ewach record with the name of the MBOX if is currrntly in so when I merge I still have that reference.

I can imagine there are a few use cases for tagging records from the filename, so perhaps that is something that could be considered for the future - perhaps an automation like the MP3 tagging software of the 90’s.

Thanks again for your help and very speedy response!

I think for that number of mailboxes and messages you may be fine without additional merging, but please let me know if you run into any issues.

I’m also working on rewriting EagleFiler’s core so that messages can be scriptable, and at that point the script above should do the job.