Script to create a new text record - and then print it?

Hello everyone,

I have been using a script cobbled together from various examples on here, which prompts me for a few bits of information, then creates a record in EagleFiler based on that information. This has been very helpful for the last little while; I use it to make work orders to give to my maintenance team. However, I print every single one of these, and so far the best I’ve been able to figure out is to just go to EagleFiler and manually print the record that I just created.

Is there a way to automatically print this with my default printer?

Here’s my script:


-- set date in wanted format
set theDate to current date
set dm to month of theDate as number
set dd to day of theDate
set dy to year of theDate
set fDate to do shell script "date '+%Y.%m.%d'" as string

set _location to {}
try
	display dialog "Where is the problem? (e.g. SSB1 or CCG4)" default answer ""
	set _locAnswer to text returned of result
	if _locAnswer is not "" then
		set _location to _locAnswer
	end if
end try

set _problem to {}
try
	display dialog "What's the matter? (e.g. The sink is inflatable)" default answer ""
	set _probAnswer to text returned of result
	if _probAnswer is not "" then
		set _problem to _probAnswer
	end if
end try

set _whofix to {}
try
	display dialog "Who should handle this? (e.g. Richard, or D&D)" default answer ""
	set _whoAnswer to text returned of result
	if _whoAnswer is not "" then
		set _whofix to _whoAnswer
	end if
end try

set _tags to {_location, fDate, "open", "workorder", _whofix}
set _noteName to fDate & " — " & _location & " — Work Order"
set _noteBody to _noteName & return & return & "Work Order for: " & _whofix & return & return & "Date: " & fDate & return & "Location: " & _location & return & return & "Description: " & return & _problem & return & return & "Solution:"

tell application "EagleFiler.app"
	tell «class LibD» 1
		«event WashImpr» given «class pTxt»:_noteBody, «class pTag»:_tags
	end tell
end tell

Extra credit: I’ve got another computer on the same network that I’d like to be able to create work orders from. I can’t even begin to fathom how to do this. I can obviously just create an RTF in the Eaglefiler library folder, shared via Dropbox… but then I’m afraid those will never get printed reliably. Anyway, that’s not too big a deal, just another thought in case you know something obvious.

Thank you very much for any help you can provide.

EagleFiler doesn’t currently support printing via AppleScript, but you could try something like:

tell application "EagleFiler"
    tell library document 1
        set {_record} to import text "The text"
        set _file to _record's file
    end tell
end tell
tell application "Finder"
    print _file
end tell

How about creating the RTF files in a “To Print” folder in your library via Dropbox? Then you could periodically run a script that prints the records in that folder and moves them to a different folder.