Duplicate only visible files - assistance please

The challenge:
Insert any Cd and run the script located on it. This script will copy from the CD all VISIBLE files to the user HD.

I used the count of items in the CD location folder and looped through them.
I used the “duplicate file”…“with replacing” to copy each found file during the loop (repeat) over to the user’s Start Disk in a folder I had created.

This process was working swimmingly until I came across a machine with the hidden and system files made visible by Tinkertools. Suddenly, my item repeat loop was tripping over files that “duplicate” could not handle.

I could work around this with a “Try” block except for one thing…There are intentionally hidden files on the CD that need to remain there. Some of these files are being located during the loop and copied over. (double doh)

Apparently, and I AM guessing here, the “duplicate” command is seeing whatever the finder can see and Tinkertools has let the finder see everything thus causing my cute lil script to implode.

To make a long story short…
How do I allow a machine to see whatever there is to see and still be able to copy (with replacing) on the fly, regradless of CD contents, only those files that are either visible or that I explicitly request?

If I haven’t explained this well, please holler. I’ve been looking online for solutions for a while now (I even bought a book…heh) but my brain is going spagetti-ish.

Ps…this script needs to run on 10.2.8 thru current. (yes I know there was an upgrade of Applescript for version 10.3 but…there you have it…a girl’s gotta do what a girl’s gotta do.)

Thank you for any help you can give me!

Do the visible “invisibles” start with “.” (a period)? If so, then filter.

This works in Tiger (and may well work with a period in place of the “I” in the example):

set P to {}
tell application "System Events" to set L to files of (choose folder)
repeat with F in L
	if name of F does not start with "I" then set end of P to contents of F
end repeat

Thank you for the quick response!

Not all of the files/folders that are invisible start with a period. In fact, not all of the items on the CDs are even files, in so much as Applescript returns a count of files in folder as a different number than count of items.

Obviously, I am very new to applescripting. (Take one Microsoft DBE, put her in a rural area where she takes what jobs she can get and stir in a few Macs gulp). Honestly, many things are confusing me. Like, why can I use “starting from” when I write to a file but not when I read from one. :frowning:

But, I digress…

Basically, what I’m going for is a cheap and dirty installation script for programs (written by others, fortunately ;)) which require the CD to run. I intend to use one generic “installation” script that can be placed on every CD and dynamically read the visible files (whatever they may be as long as they are, indeed, files) and copy them to the user HD in locations I create and specify. The files and folders NOT to be copied are either hidden by their programmer assigned properties or begin with a period to get the same result. When my script runs, it should ignore these hidden files during the duplication process even if their Finder can see them.

I tried listing files of folder where visible is true (insert correct syntax here, heh) and was able to get the list to return my expected results. What I’m stuck on is getting duplicate follow the same guidelines.

I should also point out that the solution may not include “duplicate” at all. But “copy” doesn’t seem to have a “with replacing” option and some users may try to reinstall. Which is why I switched from “copy” to “duplicate” earlier in this process.

Yet another point of note…
I have been using TELL Application “finder”. I see you have “system events”. Perhaps the solution is to tell me to read more of my book before I harass nice, innocent forum users. heh

How about this?

set P to {}
tell application "System Events" to set L to files of (choose folder)
repeat with f in L
	if visible of f then set end of P to contents of f
end repeat

Would filtering by file type instead of visibility work?

set fileType to type identifier of (info for (choose file))


I dont think the OP is doing a choose file at all, rather looping through all contents of a specified directory/cd. So the question becomes not how to avoid choosing one of those files, but rather to avoid the processing of them.

I know they aren’t choosing a file. I could have given a better example. Building on yours… (hope I did this right, I didn’t double check)

set T to {list_of_acceptible_file_types}
set P to {}
tell application "System Events" to set L to files of (choose folder)
repeat with f in L
	set fileType to type identifier of (info for f)
	if fileType is in T then set end of P to contents of f
end repeat

I thought they could loop through the files and not process certain file types as a way around the visibility problem caused by Tinkertool.


So what’s the “correct syntax” that gets your expected results?

Ahh sorry the brain be sleepy =)

Not to worry. I should have been more clear.


One problem we have with your problem, Dabbler (or at least I do) is that TinkerTool has presumably set the visible of all the previously invisible files on your CD to true or the Finder wouldn’t show them. To filter those out, therefore, we’re going to have to go for attributes other than “visibility”. How do YOU know which files should go and which should not?

tell application "System Events" to set F to (files of desktop folder)
-- lists them all, including invisibles, in the format: 
-- file YourHD:Users:YourUName:Desktop:.DS_Store
set p to item 3 of F as alias -- converts it to alias form

tell application "Finder" to set G to files of (path to desktop folder)
-- gets there in one step, but slower. Finder "knows" more about the file too. No Invisibles
-- in the list unless you ask for them.
-- Without the 'as alias list' you get back this form:
-- document file "Name" of folder "Desktop" of folder "username" of folder "Users" of startup disk
-- which I guess you could call a "Finder path", which works as is for some Finder operations,
-- but more often needs to be an alias. (which is what you get with 'choose file')

Wow, I should have looked at this site over the weekend! You guys are great :slight_smile:

Answer: Process of elimination:

  1. The programmers hide some files on the CDs. (Either by adding a “.” to the beginning of the file name or by setting each item’s properties to hidden) The hidden files never need to be installed. So step one is to ignore hidden items.

  2. There are a couple of of visible files that do not need installation but they are always named the same. These 2 or 3 files (for example, the installer script itself) are filtered explicitly and not copied.

Basically, I do this…
Locate user hd and desired path (creating it as needed)
Run installer with “path to me”
Loop through path to me copying (using duplicate with replacing) only the files that are visible or NOT explicitly ignored

I thought I had this beat with a short and simple script until the Tinkertools machine showed all files as visible and burst my little bubble.

I wanted to post right away this morning out of consideration for your efforts. Now I am going to read these posts much more thoroughly and try some of the ideas. Also, on Monday morning, everyone is all chatty making a buttload of distracting noise so I’m going to kick old I-tunes to classical or waltz or jazz or some other such non-verbal music and crank the headset so I can concentrate properly. I’ll post my progress, with pasted code, once I’ve caught up on my homework from you guys.

I think I GOT IT!

This script copies all visible files from the currently loaded cd (which contains the installer itself) except for those files containing the words “installer” and “sampler” from the cd to the user’s harddrive. If the user’s “applications” directory can be found, I create the program folder there. If I cannot locate the “applications” directory, I create one on the user startup disk instead. The folder to be created is determined by reading a text file also located on the cd. That text file is creted by the programmer and burned to the cd with the program itself allowing the use of one Mac OSX installer for an unlimitted number of programs.

As I said before, I am really new to AS. I won’t be offended if you see potential issue with this script and point them out. In fact, I would appreciate it!

(I use szi as a precursor to my variables in applescript…long story heh)

tell application "Finder"
	--set cd path
	set sziCDPath to (container of (path to me)) as string
	--obtain  current useruser startup disk
	set sziInstallTo to startup disk as string
	--Determine where to install and populate sziInstallTo
	if not (exists folder "applications" of folder sziInstallTo) then
		-- There is no applications folder on this startup disk create folder on the root hd
		set sziInstallTo to startup disk as string
		set sziInstallTo to sziInstallTo & "Applications:" as string
	end if
	--read text file on cd to obtain programmer defined installation folder from text file
	set sziConfigFile to sziCDPath & ".installer.config" as string
	set sziProgramFolder to read file sziConfigFile
	--Determine if Program Folder already exists and create as needed
	if not (exists folder sziProgramFolder in folder sziInstallTo) then
		--create program folder
		make new folder at sziInstallTo with properties {name:sziProgramFolder}
	end if
	set sziInstallTo to (sziInstallTo & sziProgramFolder & ":" as alias)
	--Get selected files from CD and copy to installation folder on user hd
	set sziItemList to list folder sziCDPath without invisibles
	repeat with i from 1 to count of sziItemList
		set sziThisItem to (sziCDPath & ((item (i) of sziItemList) as string)) as string
		if sziThisItem contains "Installer" then
			--Do not copy
		else if sziThisItem contains "Sampler" then
			--Do not copy
			duplicate file sziThisItem to sziInstallTo with replacing
		end if
	end repeat
	--open new szi installed folder window for user
	make new Finder window to folder sziInstallTo
end tell

Thank you SO much for your input! I often trip over this forum doing my google searches. Also, this site is listed in the book I bought which has also helped a ton.

I’m sure to be back! Thank You!