Hello
My understanding is that you made several errors.
(1)
the variables NakedFiles and IconFiles are defined only if you RUN the script but in this case the script do only that.
(2)
The open handler is called when you drop a folder icon on it.
In this case, from the handler point of view, NakedFiles is a list containing the path to the folder and the pats to embedded items.
IconFiles is not defined.
As the first item of the passed list is a folder, this open handler does nothing.
(3)
in the iconizeFile handler, the file to iconize is defined (by the passed pathname F) but :
(a) the folder containing the pict files would not be visible if the handler was caller from the implicit Run handler, would not be defined (and would not be visible too) when the handler was called from the open handler
(b) even if the variable IconFiles was visible from the handler point of view, it would not be used because you wrote a wrong instruction :
set IconFile to “IconFiles & F” as alias
Here is an edited version :
on run
local NakedFiles, IconFiles
set NakedFiles to choose folder with prompt "Choose a folder of naked files"
set IconFiles to choose folder with prompt "Choose a folder of image files"
my main(NakedFiles, IconFiles)
end run
on open (sel)
local NakedFiles, IconFiles
set NakedFiles to sel's item 1
set IconFiles to choose folder with prompt "Choose a folder of image files"
my main(NakedFiles, IconFiles)
end open
on main(NF, picturesFolder)
local listeItems, FF
my iconizeItem(NF as text, picturesFolder)
tell application "Finder"
set listeItems to entire contents of NF as alias list
end tell
repeat with FF in listeItems
my iconizeItem(FF as text, picturesFolder)
end repeat
end main
(*
I renamed the handler because the passed item may be a file or a folder.
*)
on iconizeItem(F, P)
local ao, pictPath
(*
I encapsulate the code in a try block because it's not guaranteed that there is a picture file for every item.
*)
try
tell application "Finder"
get name of alias F
end tell -- to folder F then to Finder
set pictPath to ((P as text) & result & ".png") as alias
-- grab the file's icon
my CopyOrPaste(pictPath, "c")
my CopyOrPaste(F as alias, "v")
end try
end iconizeItem
on CopyOrPaste(i, cv)
tell application "Finder"
activate
open information window of i
end tell
tell application "System Events" to tell process "Finder" to tell window 1
keystroke tab -- select icon button
keystroke (cv & "w") using command down (* (copy or paste) + close window *)
--keystroke "w" using command down
end tell -- window 1 then process Finder then System Events
end CopyOrPaste
CAUTION:
I assumed that every picture files are png ones.
It’s easy to change the type of every picture files.
If you plan to use picture files of different type, it would be more complicated.
Yvan KOENIG (VALLAURIS, France) dimanche 29 juillet 2012 20:07:27