Trying to debug fileURLWithPath problem

In the Debugger, I’m executing the script below using ‘open’ and passing in a PDF.
The thePDFDoc var always ends up as missing value.
The debugger shows me the line before returns the URL with – file:/// appended

e.g.

(NSURL) Macintosh%20HD/Users/sphil/SomeDoc.pdf – file:///

Is this malformed? If yes, how do I get a well-formed URL?
If no, how do I prevent thePDFDoc from being ‘missing value’?

TIA

use scripting additions
use framework "Foundation"
on open these_items
	local thePDFDoc
	local this_file1
	local this_file2
	local this_file3
	local this_path
	local pdfURL
	
	set this_file1 to item 1 of these_items
	set this_file2 to (POSIX file this_file1) as text
	set this_file3 to text 2 thru -1 of this_file2
	set this_path to current application's NSString's stringWithString:this_file3
	set pdfURL to current application's NSURL's fileURLWithPath:this_file2
	
	set thePDFDoc to current application's PDFDocument's alloc()'s initWithURL:pdfURL
end open

Your problem is this line:

	set this_file2 to (POSIX file this_file1) as text

If you look at this_file2, it will begin with ":Macintosh HD/.... You use POSIX file when you have a POSIX path, not an alias. I suspect you meant this:

	set this_file2 to POSIX path of this_file1
1 Like

Ah, yes, of course. Thanks a lot!