C-Command Software Forum

Script to convert hashtags to EagleFiler tags

Here is a script that searches the Text Content of selected EagleFiler records for hashtags (’#’ followed by other characters) and adds them as EagleFiler tags without the ‘#’. ‘#’ by itself or ‘##’, ‘###’, etc. are ignored.

-- find hastags in text file and add as tags to eaglefiler
-- C. Dunn 5/29/19
-- Based on Tag Examples
-- https://c-command.com/scripts/eaglefiler/tag-examples
-- Summary: converts hashtags to EagleFiler tags
-- Requires: EagleFiler
-- Install Location: ~/Library/Scripts/Applications/EagleFiler/
-- Last Modified: 2011-09-23

tell application "EagleFiler"
	set _theSelection to selected records of browser window 1
	repeat with _record in _theSelection
		set _text to text content of _record
		-- the 'sed' call gets rid of the '#' symbol. 
		set grepResults to do shell script "grep -o " & quote & "#\\S*" & quote & " <<< " & quoted form of _text & ¬
			"| sed " & quote & "s/#//g" & quote
		-- the lines below are a trick to get rid of blank items resulting from, e.g., "###", etc.
		set grepResultsList to paragraphs of grepResults
		set AppleScript's text item delimiters to " "
		set _theString to grepResultsList as string
		set AppleScript's text item delimiters to ""
		set grepResultsList to words of _theString
		set _tagNames to _record's assigned tag names
		set _record's assigned tag names to _tagNames & grepResultsList
	end repeat
end tell