I have an AppleScript that calls another script (a perl script in this case) which resides in the same folder as the AppleScript.
Now I'm trying to put the script into a variable like this:

tell application "Finder"
    set scriptPath to POSIX path of (container of (path to me) as text)
    set perlScript to (do shell script "find " & quoted form of scriptPath & " -name myscript.pl")
end tell

But the result that I get from the find shell command has two slashes before the file name: /path/to/folder//myscript.pl
Anyone any idea what I'm doing wrong?

While I don't quite understand the double slash I managed to resolve the problem by not invoking the Finder at all and doing the following:

set scriptPath to POSIX path of (path to me) -- path to AppleScript
set scriptFolder to do shell script "dirname " & quoted form of scriptPath -- path to folder with AppleScript
set perlScript to (do shell script "find " & quoted form of scriptFolder & " -name myscript.pl") -- path to PerlScript

Don't know if that's the best way to do it but it works for me.

1 Answer 1


Here is an answer to get right the pathname of .. from AppleScript:

Get Current Path to Script within AppleScript and Append Subdirectory

Anyway, the actual construct you got: /path/to/folder//myscript.pl is a correct pathname to your Perl script. The 1st / is coming from the terminal one coming from container: /path/to/folder/.

Hence your built find command is very similar to this one you might try to experiment:

find ~/ -name "Documents" -print

Hint: work directly in Perl, it is many times more efficient than any AppleScript.

  • I had looked at that answer but it gives me a Can’t make quoted form of alias "Macintosh HD:path:to:folder:" into type Unicode text. error. I am trying to incorporate the perlscript into an applescript because I want to eventually set up a watched folder ... I wouldn't know how to do that with perl directly. -- But you say that the /path/to/folder//myscript.pl form is correct? Why the two slashes?
    – jan
    May 21, 2016 at 14:09
  • It actually does work with the two slashes! True (but funny). As does your other solution. I resolved it differently, however (see edits), looks "prettier" to me (but I don't know whether it could run into other problems).
    – jan
    May 21, 2016 at 15:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .