You are not logged in.
The following works as expected:
Applescript:
tell application "Finder"
set sortedFiles to sort selection by name
end tell
Why doesn't the following work?
Applescript:
tell application "Finder"
set sortOrder to name
set sortedFiles to sort selection by sortOrder
end tell
Also, I'd like to specify the sort order at the beginnng of the script outside the Finder tell block, as in the following. Is this possible?
Applescript:
set sortOrder to name
tell application "Finder"
set sortedFiles to sort selection by sortOrder
end tell
I spent significant time googling this and researching the ALG but could find nothing. Thanks for the help.
Last edited by peavine (2019-11-14 08:17:04 am)
2018 Mac mini - macOS Catalina
Offline
Hi peavine.
'name' is a term common to lots of things. When you use it in a script, it's evaluated in context. So in your second script, sortOrder gets set to "Finder", in the third it's set to the name of the script. The only way I can see to do what you want is to set sortOrder to a reference to 'name' in a Finder context. This sets the variable to the Finder's enum for 'name' instead of an actual name:
Applescript:
tell application "Finder" to set sortOrder to a reference to name
tell application "Finder"
set sortedFiles to sort selection by sortOrder
end tell
NG
Offline
Hi, Peavine.
Your question is answered, but as I see, you want to provide to user choose sort order method from list. To do that you should map sort properties to its names (string representation, as choose from list works with simple AppleScript values):
Applescript:
set aChoice to choose from list {"Name", "Kind", "Creation Date", "Modification Date", "Locked", "Name Extension", "Owner", "Group", "Size"} with prompt "Choose Method to Sort By"
tell application "Finder"
if aChoice is "Name" then
sort selection by name
else if aChoice is "Kind" then
sort selection by kind
else if aChoice is "Creation Date" then
sort selection by creation date
else if aChoice is "Modification Date" then
sort selection by modification date
else if aChoice is "Locked" then
sort selection by locked
else if aChoice is "Name Extension" then
sort selection by name extension
else if aChoice is "Owner" then
sort selection by owner
else if aChoice is "Group" then
sort selection by group
else
sort selection by size
end if
end tell
NOTE: exists many other properties to sort items of selection. See ITEM properties in the Finder's dictionary.
Last edited by KniazidisR (2019-11-14 12:09:32 pm)
Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB
Offline
Thanks Nigel and KniazidisR for the responses. The operator, "a reference to", is just what I was looking for.
2018 Mac mini - macOS Catalina
Offline