Babs weekly Script Question- regarding lists {} {""}

Hello,

In this script, I am taking the contents of the front finder window and placing the names of the files in a text document. I have a few questions that I do not understand and hopefully someone can explain them to me :wink:

tell application "Finder"
	set these_items to sort (get every document file of the front Finder window) by physical size
	set these_names to {}
	repeat with i from 1 to the count of these_items
		set the end of these_names to the name of (item i of these_items)
	end repeat
end tell
set AppleScript's text item delimiters to return
set the item_list to these_names as string
set AppleScript's text item delimiters to {""}
tell application "TextEdit"
	activate
	make new document
	set text of document 1 to the item_list
end tell

Question 1- in these lines:
set the item_list to these_names as string
set AppleScript’s text item delimiters to {“”}

Can someone please tell me, why the “” are necessary? It seems if I remove them, it still works? I assume it has to do with line above it, as string? but I am just not sure about these 2 lines.

Question 2- I Sorted the list by physical size as indicated, and then I tried name, which worked fine, but when I try modification date or creation date, the order changes, but it is not correct. This is not the first time I have tried to do something with date order that made a different order than it should of. Is there a logical reason for this?

Question 3-right now I am just getting the files in the front finder window, if there were a mix of files and folder’s, how might I ask for that? I tried “get every document file of the front Finder window and every folder of the front Finder window”, but of course that didn’t work :wink:

If someone could explain any of these, It would be helpful :wink:
thanks
babs

Hi,

  1. I already answered the question here
    The default value of text item delimiters is an empty string “” as list → {“”}, which just concatenates the list elements in case they are strings.

  2. no idea

  3. item is the parent class of file and folder. You could write


.
every item of something whose class is document file or class is folder
.

Hi Stefan!!

Thank you for putting up with the senile folks…I swear I am losing my mind!!!

just thought I would ask…it’s very weird…

perfect!

thanks!!!
babs

  1. The Finder’s ‘sort’ command has always (when it’s worked at all) sorted dates from youngest to oldest. It’s the default order when arranging by date in a Finder window. You can easily reverse the order if you want:
tell application "Finder"
	set these_items to reverse of (sort every document file of the front Finder window by modification date)
end tell

You don’t need ‘get’ after ‘sort’. It only slows things down.

Hi Nigel,

I tried that, but I get the following error message:

Finder got an error: every document file of Finder window 1 doesn’t understand the sort message.

Actually the problem isn’t the order in reverse or not, but that, the dates would in fact be out of order?

any thoughts?
thanks
babs

No. You’ve got me. I’ve tried everything I can think of and haven’t been able to reproduce either problem. :expressionless: