Finding path from variable containing the name.

In the Finder, this will return the path to an application (using Safari as an example):

tell application "Finder" to set mP to path to "Safari"

but this will not:

set myApp to "Safari" -- with or without "as Unicode text"
tell application "Finder" to set mP to path to myApp

For myApp → “Safari” this returns the error: Finder got an error: Can’t make application “Safari” into type constant.

What gives?

Hi, Adam.

Firstly, ‘path to’ is StandardAdditions. The Finder’s not involved.

Secondly, you need to use the keyword ‘application’ to specify “Safari” as such.

set mP to (path to application "Safari")

set myApp to "Safari"
set mP to (path to application myApp)

set myApp to application "Safari"
set mP to (path to myApp)

Thank you, Nigel

Mea culpa: I have “application” in the script, but I typed my example rather than cut and paste something more complex and left it out.

BUT: removing ‘tell application “Finder” to’ does cure my problem - my script now works, but still contains a dreadful workaround to capitalize the first letter of each of the items in MB (because, I suspect I need ASCII and have Unicode or vice versa)

to getDefaults()
	set MB to {word 5, word -1} of (do shell script "defaults read com.apple.LaunchServices | grep -C2 public.html")
	set M to (do shell script "python -c \"import sys; print unicode(sys.argv[1], 'utf8').title().encode('utf8')\" " & quoted form of (item 1 of MB))
	set B to (do shell script "python -c \"import sys; print unicode(sys.argv[1], 'utf8').title().encode('utf8')\" " & quoted form of (item 2 of MB))
	return {B, M}
end getDefaults

set MP to (path to application (item 1 of getDefaults()))
set BP to (path to application (item 2 of getDefaults()))