Getting the current script Path/folder?

Hi

I notice something interesting about “path to”.
Usually if you do “path to me” you got the path to the script.
Now if you have a shell script that call the same applescript using osascript.
The return path is "/usr/bin’. (they got the path of osascript. bug?!?!?)

Now is there anyway I can get the real script path when I am calling from shell?

I’m confused. Don’t you need the path to issue the shell command to the script? I mean, don’t you already know the path?

The applescript actually sit in the same folder as the shell script. But they may both move to another machine. In the shell script, I can just do “pwd” to get the path no matter where I move it. I can’t see anyway to get the path in the applescript tough. :?

OK. AppleScript’s ‘path to me’ command doesn’t care where a document is: it gives the path to the application (or command-line program) running the script. So, if FileMaker runs an AppleScript, path to me returns FileMaker’s path.

However, as you pointed out, the command-line will give you your current directory using ‘pwd.’ You can then send that within the AppleScript by getting the POSIX file of the string returned by pwd.

Basically, though, I’m not sure what you wanted. The ‘path to me’ returned the path to the osascript command-line program. Did you have it running an AppleScript file somewhere? If so, you KNOW the path, since you needed it to call it.

Perhaps the original poster could explain exactly what he wanted…

Here is the whole story.
I have a sendmail applescript that will send mail to me with all the text files in the current folder as attachments. The script as you have guess use “path to” to get the current folder. Everything is good.

Now I have a shell script that will do a long overnight compile process. So I thought, well, lets have it send a email to me with all the log files as attachment. So I call the applescript within the shell script and the applescript fail to get any text files because the “path to” return “/usr/bin” as current path.

I like your idea of sending the path from shell to applescript but there is no way to send parameter from shell to applescript. osascript does not support parameter passing.

The only other options I have is to dynamically generate the applescript or passing the path using a text file. :rolleyes:

Hmm. Sounds like you are right, but one other possibility is to have the shell script:

make a directory in /tmp (or empty it if it exists)
copy the log files there
run a special saved AppleScript that looks for the directory in /tmp

This would work on any Mac, unless there are files in the directory in /tmp that are locked and/or in use.[/list]