Input Text Without Seeing It Typing?

So, unpacking the line of code:

set rootFolder to "" & (path to home folder) & "Backups:"

Yes, that's a variable called "rootFolder". The stuff to the right of "to" takes precedence over the variable assignment, as you would expect.

AppleScript does its best to implicitly coerce types. "path to home folder" will return an alias -- a file/folder reference, the "&" is the concatenation operator. By starting with the empty string "" it is saying "We're building a string, so coerce everything that follows to a string wherever necessary". The long form, with brackets to show you precedence, would be:

set rootFolder to ( ( (path to home folder) as text) & "Backups:")

Every scriptable application has an AppleScript dictionary which you can view in Script Editor with File->Open Dictionary... then choosing from the list. "Special" folders can be found in the System Events dictionary, listed in "user domain object". Have a look in the Finder dictionary, specifically "Finder window" in "Window classes" to see what the script line containing "target" is all about.

To properly target a folder inside "Backups" you should finish with ":", just as a *nix path to a directory should finish with a "/". It doesn't matter if you're going to resolve that text string to a file system alias, your Mac is smart enough to work things out, but it's good practice that will stop you making mistakes when building paths with text concatenation (you don't have to remember to keep adding the ":" before adding a file/folder name).

The clarification bit... If you only ever want to go to one folder on one computer with your script you can use an explicit reference, eg "Macintosh HD:Users:danny:Desktop:Backups:". If you wanted to use it on multiple computers, which might have different disk names or user short names, you could build the path starting "path to desktop folder" so the script would work on whichever computer you were at, eg '(path to desktop folder) as text)) & "Backups"'. And you can also use KM variables within your AppleScript, there's an example here, so you could make a decision earlier in your KM macro and use the result of that to create your path.

2 Likes