As already discussed here and demonstrated there, you can easily use Quick Look to instantly preview files downloaded from the Internet.
But in my opinion the shell script presented on Mac OS X Hints is too complicated. It works well, no question, and it’s an excellent idea, but still I think we can do it better. Hey, we already have Folder Actions on the Mac, so let’s make good use of this existing technology! Consequently I just wrote a very simple and short Folder Action script that, when attached to a folder of your choice, will display the added items using Quick Look.
Just imagine attaching this script to your Drop Box! As soon as your colleagues drop files to your public folder, you instantly see them on your screen (if the dropped files are supported by Quick Look)!
This AppleScript requires Mac OS X 10.5, simply because of the use of the newly introduced «qlmanage» command.
-- When installed as a Folder Action, this script will display all
-- items added to the watch folder using Quick Look.
-- Can be very useful when attached to the Drop Box
-- or Downloads folder.
property mytitle : "Looky"
on adding folder items to watchfolder after receiving newitems
try
set strfilepaths to ""
repeat with newitem in newitems
set itemfilepath to (newitem as Unicode text)
-- ignoring partly downloaded files
if itemfilepath does not end with ".download:" then
set strfilepaths to strfilepaths & quoted form of (POSIX path of itemfilepath) & space
end if
end repeat
if length of strfilepaths is not 0 then
set cmd to "qlmanage -p" & space & strfilepaths & ">& /dev/null"
set cmd to cmd as «class utf8»
do shell script cmd
end if
on error errmsg number errnum
tell me
activate
display dialog "Sorry, an error occured:" & return & return & errmsg & " (" & errnum & ")" & return & return & "Folder action at:" & return & (watchfolder as Unicode text) buttons {"OK"} default button 1 with icon stop with title mytitle
end tell
end try
end adding folder items to
Of course you can easily modify the script code, so that it, for example, only previews PDF or certain image files:
repeat with newitem in newitems
set itemfilepath to (newitem as Unicode text)
-- preview PDF files only
if itemfilepath ends with ".pdf" then
set strfilepaths to strfilepaths & quoted form of (POSIX path of (itemfilepath)) & space
end if
end repeat