C-Command Software Forum

Script to set title

I’m trying to replicate a facility in DevonThink that I miss in EF: the ability to highlight a string in a library document and set it as the title of the library record ('Set Title As…" in DT).

But I’m not much of a scripter. The script below works most of the time. I’m sure several Forum users could do this a lot better.

The ‘clean up’ sub-routine eliminates CRs and multiple spaces from the titles of PDF files.


-- EagleFiler (v. 1.2) Script
-- Set the Title of the currently selected record
-- to the string highlighted in the record viewer
-- No rights claimed. Your mileage may vary.
-- 

---  Replace non-alphanum and non-punctuation chrs
---  on clipboard with spaces and concatenate
on cleanup()
	set myScript to ("usr/bin/pbpaste |  tr -Csu ':alnum:]:punct:]' ' ' | pbcopy")
	do shell script (myScript)
end cleanup

---  Title string should be selected in the viewer
---  or in any frontmost window before running.
---  Will set the Title of all records higlighted
---  in the library window; selecting just one
---  record is recommended ;-)
tell application "EagleFiler"
	set the clipboard to ""
	tell application "System Events"
		keystroke "c" using command down
	end tell
	tell me to cleanup()
	set newClip to the clipboard -- as text
	set theRecords to the selected records of browser window 1
	repeat with theRecord in theRecords
		set theRecord's title to newClip
	end repeat
end tell
--
-- ends
--

Cool! I’ve been planning to add this as a built-in feature, but this should tide people over. Beware that running the script will clobber the clipboard contents.

Yes… silly of me. I use JumpCut so I didn’t think about that (wish JumpCut could be scripted). There’s an easy fix that takes advantage of the un-restricted (except by memory) size of a temporary Applescript variable to suck up the clipboard contents:

-- EagleFiler (v. 1.2) Script
-- Set the Title of the currently selected record
-- to the string highlighted in the record viewer
-- No rights claimed. Your mileage may vary.
-- www.petergallagher.com.au

---  Replace non-alphanum and non-punctuation chrs
---  with spaces and concatenate
on cleanup()
	set myScript to ("usr/bin/pbpaste |  tr -Csu ':alnum:]:punct:]' ' ' | pbcopy")
	do shell script (myScript)
end cleanup

---  String should be selected in the viewer
---  or in any frontmost window.
---  Will set the Title of all records higlighted
---  in the library window; selecting just one is 
---  recommended ;-)
tell application "EagleFiler"
	-- save the clipboard
	set oldClip to the clipboard
	set the clipboard to ""
	tell application "System Events"
		keystroke "c" using command down
	end tell
	tell me to cleanup()
	set newClip to the clipboard -- as text
	set theRecords to the selected records of browser window 1
	repeat with theRecord in theRecords
		set theRecord's title to newClip
	end repeat
	set the clipboard to oldClip
end tell
--
-- ends
--

This is awesome. Thanks so much.

:slight_smile:

EagleFiler 1.4 has this built into its contextual menus.