There is the license.pdf file in the bundle of my application.
To open it, what is the best solution (the three work)?
current application’s NSWorkspace’s sharedWorkspace()'s openURL:(current application’s NSURL’s fileURLWithPath:((current application’s NSBundle’s mainBundle()'s pathForResource:“License” ofType:“pdf”) as string))
or
set licensePath to ((current application’s NSBundle’s mainBundle()'s pathForResource:“License” ofType:“pdf”) as string)
set licenseURL to current application’s NSURL’s fileURLWithPath:licensePath
current application’s NSWorkspace’s sharedWorkspace()'s openURL:licenseURL
or
try
do shell script "open " & quoted form of ((current application’s NSBundle’s mainBundle()'s pathForResource:“License” ofType:“pdf”) as string)
end try
Titanium. The first two options are functionally equivalent, and which you use is a matter of personal preference. There doesn’t appear to be any reason for the as string coercion, but perhaps there is and it’s not immediately evident. I would not use the shell.
FWIW, you might consider the following, which is a bit simpler.
use framework "AppKit"
use framework "Foundation"
use scripting additions
current application's NSWorkspace's sharedWorkspace()'s openURL:(current application's NSBundle's mainBundle()'s URLForResource:"License" withExtension:"pdf")
From the documentation:
URLForResource:withExtension:
Returns the file URL for the resource identified by the specified name and file extension
pathForResource:ofType:
Returns the full pathname for the resource identified by the specified name and file extension.