Applescript to capture the URL of a PDF file from Safari

A while back I made a script to (re)set the title of library record to selected text from the PDF file itself.

I capture a lot of PDFs from Safari and need the URL for citation purposes. But the F1 key doesn’t do that (I wish it would).

Here’s an straightforward little script that you can run after EF has captured the file and assuming that the URL of the file is still in the front window of Safari. It places the URL in the ‘From name’ field of the Library Record (visible in the Info dialog or by mousing over the record in the browser) in the format I use for MLA-style URL citations. Reverse the order of the %m and %d formatting strings if you prefer American-style dates.

It could be combined with the script referenced above, if you regularly re-name captured PDFs, as I do, to make a combination rename+citation script.

-- EagleFiler (v. 1.2) Script
-- Set the 'from name' of the currently selected record
-- to the string highlighted address window of the 
-- current Safari tab
-- No rights claimed. Your mileage may vary.
-- www.petergallagher.com.au


tell application "Safari"
	set theURL to URL of the document of window 1
end tell
set thisDay to do shell script "date +%d/%m/%Y"
set citeString to "Retrieved " & thisDay & " from " & theURL
tell application "EagleFiler"
	activate
	set theRecords to the selected records of window 1
	repeat with theRecord in theRecords
		set theRecord's from name to citeString
	end repeat
end tell

The capture key has always saved the URL. It’s accessible from the source URL scripting property and also as a tooltip in the records list or by using the Edit > Copy Source URL command. There’s also a date added scripting property that you can use for your citation date.

When I save a PDF from Safari to EF the ‘Source URL’ (Edit > Copy Source URL) is always the ‘localhost’ URL of the file on my disc and not the URL of the source of the document in Safari. That’s why I found I had to use this script.

I was not aware of the ‘date added’ scripting property. Thanks.

Sorry about that. I’ll try to fix this for the next release.

EagleFiler 1.3 can automatically set the source URL for files that were imported by URL.