How does Applescript run an Applescript that runs an Applescript?

I’m a bit confused about the hierarchies regarding ‘run script’.
If you just want to go straight to the point, the gist is in the box.

I’ve been making .app files for years now, and because I didn’t know any better, quite a few scripts had references to external dialog icons, sound effects, or script apps that were stored elsewhere on the disk. This of course is an awful habit, because I lose track of which files are being referenced by a script, and if any folder structures change, everything is ruined.

Recently I ‘graduated’ to copying subscripts in the “Scripts” folder found from the .app package, and learned how to create a Custom folder to the same directory, so I could store all the other resources there and reference to them. Now none of these scripts contain hardcoded paths to references, and it therefore doesn’t matter even if I wanted to rename the .app or move it to a different folder.

I had usually just had one .app run a contained .scpt file, but I just built a pretty massive app and ran into a phenomenon I didn’t know of. Here’s an example of the logic:

The reason why I would like to keep all these branches of the script as separate files is that the project mainly consists of choose from list dialogs, which easily makes a script swell into proportions that makes it very difficult to work with. Also, several deduction paths in multiple “Children” reference to the same set of “Grandchildren”, which will further reference to the same set of “Grand-grandchildren”, so it just doesn’t make sense to me to copy-paste all that stuff multiple times to the “Child” scripts. It’s a lot of work, and if I encounter a bug from such part (which, with something this big is very likely), it’s even more work to have to fix the same bug for all those repeats…

Okay I got it working eventually, and the problem wasn’t what I thought it was.
But what the problem was, I still don’t understand.

Could someone explain, what’s the functional difference between these two?
Why and when should one choose one or the other?

set TheScriptToRun to alias ((ScriptPath) & "MyScript.scpt")
run script TheScriptToRun
set TheScriptToRun to ((ScriptPath) & "MyScript.scpt")
run script file TheScriptToRun

When I was writing the script, testing it in isolation, the first format was working fine. I hadn’t spontaneously used aliases before, but it looked simple enough so I just copied that format when I quickly googled how the syntax for running a script was…
And turns out, that format doesn’t work when you have more than one level of “child/parent” relationships in the script series.
But removing alias and adding file made it work.

You tried concatenate alias (which is special number type, it is one address in the memory, pointer) with string. In the proper script you concatenate HFS path (which is string type) with other string.

The run-script entries in both the AppleScript Language Guide (ASLG) and the AppleScript dictionary state that either aliases or file specifiers can be used. So, functionally there is not (or at least should not be) any difference between them in this particular case. From the AppleScript dictionary:

The ASLG makes the following recommendation regarding the use of aliases and file specifiers:

In the last few versions of macOS, aliases have not always worked as expected, so I tend to use file specifiers. None of the above would explain the exact issue you have encountered, though.

@peavine,

the issue is obvious. I explained it already. It isn’t problem of aliases here, but how the AppleScript concatenates operands:


set anAlias to path to desktop folder

-- CORRECT
-- APPLESCRIPT automatically converts anAlias to text (HFS) here,
-- because the left operand "" is string
set concatanatedHFSPath to "" & anAlias & "myDesktopScript.scpt"
--> "HARD_DISK:Users:123:Desktop:myDesktopScript.scpt"

-- WRONG
set concatanatedHFSPath to anAlias & "myDesktopScript.scpt"
--> {alias "HARD_DISK:Users:123:Desktop:", "myDesktopScript.scpt"}

-- CORRECT
-- APPLESCRIPT automatically converts PI to text here,
-- because the left operand "" is string
set concatanatedHFSPath to "" & pi & "myDesktopScript.scpt"
--> "3.14159265359myDesktopScript.scpt"

-- WRONG
set concatanatedHFSPath to pi & "myDesktopScript.scpt"
--> {3.14159265359, "myDesktopScript.scpt"}

KniazidisR. In my post I was responding to a specific question raised by the OP’s, which was:

At the end of my post I made clear that the issue he had encountered was not related to the use of aliases or file references.

If you want run script with concatenated alias, then following should work. I will repeat, the OP concatenated wrong way, and this was the only issue. The script, of course should be existing.


set anAlias to path to desktop folder
set concatanatedAlias to ("" & anAlias & "myDesktopScript.scpt") as alias
run script TheScriptToRun

NOTE: @peavine correctly pointed out that in some applications of the latest OS, the aliases do not work (for example, in System Events and Image Events). In tell application blocks, it is better to use the file specification with HFS.

If I understand Riku’s post correctly, he wants to place a script within an AppleScript app’s resources folder, and he wants that script to call a second script in the same folder. I’ve never done this before and thought I’d give it a try. The following is a bit kludgey but does work.

Mother.app

set theChildScript to (path to resource "Child.scpt" in directory "Scripts")
run script theChildScript

Child.scpt

set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set theFolder to text 1 thru text item -2 of (path to me as text)
set theGrandchildScript to (theFolder & ":Grandchild.scpt") as alias
set AppleScript's text item delimiters to ATID
run script theGrandchildScript

Grandchild.scpt

display dialog "ok"

The above code aside, it is not clear to me if his variable ScriptPath is an alias, an HFS path, a path-to command that returns an alias? Perhaps Riku could clarify this.

@KniazidisR. I understand that you have already answered Riku’s question. This is a topic of interest to me, and I was just hoping for some discussion of how this might best be done.