tell application "Finder"
set folderLocation to choose folder
make new folder at folderLocation with properties {name:"Folder"}
end tell
tell application "Finder"
set folderLocation to choose folder
get name of folderLocation
end tell
Now looking at the first example I would assume the object hierarchy for the folder would be: Folder->Properties->Name
but when you look at the second script it tends to be just: Folder->Name
I don’t understand. is properties a sub object of folder?. I would have assumed (going by the first example) that to get the name of folderLocation of script 2 I would have to enter the following:
tell application "Finder"
set folderLocation to choose folder
get name of properties of folderLocation
end tell
properties is listed as a properties in the finders dictionary. or is this a reserved word for all objects?
Sorry. it might be a bit of a mind bender question for people that know applescript second nature.
I am not the expert in this, but the form above (notice that I added AppleScript tags so clicking on the “Open this Scriptlet…” will open it in your Script Editor - you don’t need to copy it) is the form required for creating a new folder with a name other than “New Folder”.
while this is really shorthand for:
tell application "Finder"
set folderLocation to choose folder
get name of (info for folderLocation)
end tell
In other words - you can set the name properties of a folder, but you use “info for” to retreive them and the Finder understands that you can leave out the “info for”. Don’t know why.
mcshaman1, some applications have a “properties” property; it returns a record containing all the other of the specified object. This could be useful if you aren’t sure what properties an object has, or if you don’t know what the values for the properties would look like.
I’m not aware of any practical use for the “properties” property in a script. However, when I started looking into AppleScript, I would occasionally use something like this:
choose file without invisibles
tell application "Finder" to return properties of result
Actually, I don’t believe it is. “info for” is a command in Standard Additions, which has some code inside it that can get info about a file. The Finder also has some code inside it that can get info about a file, and it has support to use AppleScript to access some of that code. However, Standard Additions and Finder have nothing to do with each other.
I declared non-expertise, but when you “get info” in the Finder isn’t it just returning a set of properties/attributes of the selected Finder object? Do you think the distinction of which dictionary it’s in is important in this case?
choose file without invisibles
set theFile to result
tell application "Finder"
return info for theFile
end tell
The tell Finder block is pointless, because “info for” is part of Standard Additions.
Any of the following scripts will give the name of a file, but they each use different methods of getting to it.
choose file without invisibles
name of (info for result without size)
choose file without invisibles
tell application "Finder" to return name of result
choose file without invisibles
do shell script "/usr/bin/basename " & POSIX path of result
choose file without invisibles
set theFile to result
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theFileName to last text item of (theFile as Unicode text)
set AppleScript's text item delimiters to ASTID
return theFileName
Oh… so it has nothing to do with the properties class? I dont like how in applescript functions and objects can be made up of multiple words… especially when some of those words conflict with other reserved words.
Agree there. I’ve been trapped by many of them. It’s a misguided (in my view) attempt to use only English nouns and verbs in a normal fashion even when it can confuse, like this time.
Yes it is confusing. Property is not a class. Properties are charecteristics of objects belonging to a certain class. Each class has at least one property, class.