Getting list of recent files in folders and subfolders

Hi again

I have a shell script question. How do I make the shell script in the above find ONLY visible files. It is throwing errors as currently phrased when pointed at volumes (it searches trash, spotlight etc folders)

Cheers

hi, Just noticed this.

Using Log is a way to debug. It lets me see the value of the variable so I know I am getting what I expect.
I see this info when I click on 'Events at the bottom of the Applescript Document.

The events pane shows the calls and replies from execution of the script. logged info will show up as grey and encapsulated in (* *)

Also did you see my last post.

Cheers Mark

I guess I can remove the log command then.

On the foo.pages, foo.numbers issue - the script you wrote (when run multiple times) will produce multiple aliases for such files (but not for others). Maybe the problem is not in the exist test… But the result is that multiple aliases appear for pages/numbers documents. Hence my hack to delete them:)

Cheers

…Just following up on the shell script find query - trying to avoid invisible files.

I have this:

set theFiles to paragraphs of (do shell script "find " & quoted form of POSIX path of theFolder & " -type f -not -name \".*\" ;true")

This at least completes (slowly). But it returns a bunch of results that I do not want - including spotlight files etc.

Still trying to work out how to exclude invisible folders/files…

Any suggestions anyone?

this part in your original script

! -name '.*'

actually excludes invisible files (starting with a dot)

Hello / Bonjour

I tried to create aliases and had no problem of duplicates with this piece of code.
J’ai fait un essai de création d’alias et je n’ai eu aucun problème de doublon avec ce bout de code :


tell application "System Events"
	set theFile to name of (eachfile as alias)
	log theFile
	if not (exists item (AliasFolder & theFile)) then
		tell application "Finder" to make alias to (alias eachfile) at AliasFolder
	end if
end tell


Yvan KOENIG (VALLAURIS, France) lundi 17 décembre 2012 21:03:04

Hi Stefan

That is what I thought. So why do I get multiple results like this:

The Spotlight file begins with a dot - but it is still “found”

I have theFolder set to

And if I do not have the

at the end of the shell script, I get an execution error:

This all says to me that the find script fails to ignore invisible files…

Puzzled:)

Yvan

Can you post whole script. I am getting errors with your code.

Merci

I just used a subset of your own script.


set AliasFolder to "Macintosh HD:Users:yvankoenig:Desktop:Jobs.:"

set eachfile to "Macintosh HD:Users:yvankoenig:Desktop:Ellington, Side by Side.numbers:"

tell application "System Events"
	set theFile to name of (eachfile as alias)
	log theFile
	if not (exists item (AliasFolder & theFile)) then
		tell application "Finder" to make alias to (alias eachfile) at AliasFolder
	end if
end tell

Here is the complete edited one.


set FilestoCopy to {}
set theFolder to ((path to home folder as text) & "Downloads:Applications" as alias)
set AliasFolder to (path to desktop folder as text) & "Aliases:"

set theFiles to paragraphs of (do shell script "find " & quoted form of POSIX path of theFolder & " -type f ! -name '.*'")

repeat with oneFile in theFiles
	try
		if modification date of (info for (oneFile as POSIX file)) > ((current date) - 14 * days) then set end of FilestoCopy to oneFile as POSIX file
	end try
end repeat

repeat with eachfile in FilestoCopy
	tell application "System Events"
		# set theFile to name of (eachfile as alias)
		set theFile to name of disk item eachfile # When I speak to System Events my best choice is disk item
		log theFile
		if not (exists item (AliasFolder & theFile)) then
			tell application "Finder" to make alias to (alias eachfile) at AliasFolder
		end if
	end tell # System Events
end repeat


Yvan KOENIG (VALLAURIS, France) lundi 17 décembre 2012 21:28:51

Odd. I do not get that on my system !

Thanks Yvan

I am afraid I get the same result here - multiple aliases on multiple runs for Pages documents. I have no idea what is going on. Maybe I think I will restart my Mac.

Restarted my Mac.

Ran script

Still get duplicates of Pages and Numbers files.

Gonna pass on this for tonight.

Please let me repeat. :wink:

Even if the Finder politely accepts the syntax, the AppleScript class of a Finder alias is alias file


tell application "Finder" to make alias file to (alias eachfile) at AliasFolder

Thanks, Stefan

Changed to your suggested syntax.

Still produces multiple copies of Pages/Numbers documents:(

Still tries to search invisible files:(

Here is script in current form:

set theFolders to {((path to home folder as text) & "Downloads:Applications" as alias), ((path to home folder as text) & "Downloads:Documents" as alias)}
set AliasFolder to (path to desktop folder as text) & "Aliases:"


repeat with n from 1 to number of items in theFolders
	set FilestoCopy to {}
	set theFolder to item n of theFolders
	
	set theFiles to paragraphs of (do shell script "find " & quoted form of POSIX path of theFolder & " -type f -not -name \".*\" ;true")
	
	repeat with oneFile in theFiles
		try
			if modification date of (info for (oneFile as POSIX file)) > ((current date) - 14 * days) then set end of FilestoCopy to oneFile as POSIX file
		end try
	end repeat
	
	tell application "System Events"
		
		repeat with eachfile in FilestoCopy
			set theFile to name of (eachfile as alias)
			--log theFile
			if not (exists item (AliasFolder & theFile)) then
				tell application "Finder" to make alias file to (alias eachfile) at AliasFolder
			end if
		end repeat
		
		(*set aliasList to every item in folder AliasFolder
		
		repeat with eachfile in aliasList
			if name of (eachfile as alias) contains "alias" then
				my deleteFile(eachfile as alias)
			end if
		end repeat*)
		
	end tell
	
end repeat

on deleteFile(filename)
	do shell script "rm -Rf " & quoted form of POSIX path of filename
end deleteFile

of course you get an error, because the pure find command (without sudo) considers only files you have permission for.
Is it necessary to search on the root folder of a disk (where are a few system owned files) ?

The ! -name '.*’ syntax should work in your home folder or in other folders you own or you are a member of their group

Hi Stefan

Understood.

But how is it that I get spotlight files in search result - files which begin with a dot?

I have two hard disks mounted on USB - “TV Series” and “TV Series 2”. Both have exactly same permissions when I look at Finder Info. But one throws read errors, while the other returns spotlight files, despite being dot files.

I could of course create a single root folder on each drive and dump everything into that, then just search that folder. I guess that may be the practical answer…:slight_smile:

I just like to understand, if that is possible:)

Thank you for your and others’ time on this.

Cheers

I ran the original subset 10 times.
It didn’t created duplicate.

Here is the complete script which I edited because I dislike some points (mainly the use of the deprecated info for)


set FilestoCopy to {}
#set theFolder to ((path to home folder as text) & "Downloads:Applications" as alias)
#set AliasFolder to (path to desktop folder as text) & "Aliases:"
set theFolder to ("Macintosh HD:Users:yvankoenig:Downloads:") as alias
set AliasFolder to (path to desktop folder as text) & "Jobs.:"
set theFiles to paragraphs of (do shell script "find " & quoted form of POSIX path of theFolder & " -type f ! -name '.*'")
set curDateMinus14days to ((current date) - 14 * days)
log curDateMinus14days
tell application "System Events"
	repeat with oneFile in theFiles
		log oneFile
		try
			if (modification date of disk item oneFile) > curDateMinus14days then
				set end of FilestoCopy to oneFile as POSIX file
			end if
		end try
	end repeat
end tell
repeat with eachfile in FilestoCopy
	tell application "System Events"
		set theFile to name of disk item (eachfile as text) # When I speak to System Events my best choice is disk item
		if not (exists item (AliasFolder & theFile)) then tell application "Finder" to make alias to (eachfile) at folder AliasFolder
	end tell # System Events
end repeat

Yvan KOENIG (VALLAURIS, France) lundi 17 décembre 2012 22:32:13

Thanks, Yvan

Je suis à jour:)