MacOS – How to make an AppleScript app locate itself

applescriptmacos

I've been messing around with this cool AppleScript scripting language and I have yet another question. How to make an AppleScript app locate itself?

Like something like this (that obviously doesn't work):
get info of myself
set variable to "location"

So the output, "variable," would be for instance /home/Desktop/MyEpicApp.app.

Is there any script or a sequence of them to get the location of the app and store it in a variable?

Many thanks in advance, even a tiny bit of help is appreciated.

Best Answer

To set the path of an AppleScript script or app to a variable use the following code:

set thePath to POSIX path of (path to me as text)

Example:

set thePath to POSIX path of (path to me as text)
display dialog "The path to me is: " & thePath

enter image description here

If you want the path up to the script or app set to a variable use the following code:

set thePath to POSIX path of ((path to me as text) & ":")

Example:

set thePath to POSIX path of ((path to me as text) & ":")
display dialog "The path to me is: " & thePath

enter image description here