Hello
I thought I had written my first applescript without anyone helping but I was wrong, I’m having problems with this script
Script should be passing each of the files that is added or dropped into target folder desktop and run sheelscript with the if statement.
Files can be added by drag and dropping to targetfolder or firefox saving downloads to targetfolder.
set TargetFolder to "/Users/(*USER NAME*)/Desktop/"
on adding folder items to TargetFolder after receiving DroppedItems
set fileList to items of DroppedItems
repeat with i from 1 to (count of fileList)
set itemToScan to item i of fileList as alias
try
do shell script "echo " & "| /usr/local/clamXav/bin/clamscan --quiet --stdout -"
on error errMsg number exitCode
if (exitCode = 1) then
tell application "Finder"
move itemToScan to trash
end tell
end if
end try
end repeat
end adding folder items to
on adding folder items to TargetFolder after receiving DroppedItems
set fileList to items of DroppedItems
repeat with i from 1 to (count of fileList)
set itemToScan to item i of fileList as alias
try
do shell script "echo " & "| /usr/local/clamXav/bin/clamscan --quiet --stdout -"
on error errMsg number exitCode
if (exitCode = 1) then
tell application "Finder"
delete itemToScan
end tell
end if
end try
end repeat
end adding folder items to
Now about your second comment “2 - Folder actions are using HFS pathnames so the way you define yours may fool it.”
I believe POSIX has something do with comment 2 right?
If so would I have to set POSIX
as well as use POSIX in shell script?
AppleScript always works with colon delimited paths (e.g. Macintosh HD:Users:)
Only path arguments in a do shell script command must be a POSIX.
I really don’t know, what the shell script line does, but probably you can
simplify your script:
on adding folder items to TargetFolder after receiving DroppedItems
repeat with itemToScan in DroppedItems
try
do shell script "echo " & "| /usr/local/clamXav/bin/clamscan --quiet --stdout -"
on error errMsg number exitCode
if (exitCode = 1) then tell application "Finder" to delete itemToScan
end try
end repeat
end adding folder items to
There’s some potentially confusing advice in this thread.
The folder parameter in a Folder Actions handler is an alias, not a path of any description. Since it’s not used within the handler, it’s pretty academic what it is anyway.
move to trash has always been an acceptable substitute for delete in the Finder. Admittedly, though, I too prefer the latter version.
Stefan’s version of the script, while better written, doesn’t do anything different from virustrapp’s original, which apparently doesn’t work. I’m not familiar with clamscan either. At a guess, I’d say it was necessary to get the POSIX path of the current file into the shell script string somewhere. Since the string presently contains two literal values needlessly concatenated together (they could have been written as just one literal value), perhaps the POSIX path has been inadvertently omitted from the concatentation point:
do shell script "echo " & (quoted form of POSIX path of itemToScan) & " | /usr/local/clamXav/bin/clamscan --quiet --stdout -"
As Nigel said, it looks like you should use the item dropped, in your do shell script after you changed it to posix path.
Here’s some other things. You should try to make it work with one file first. Use the ‘choose folder’ command to get a reference first:
set itemToScan to choose file
Drop the repeat loop and whatever else you don’t need especially the open handler. After you get this to work with one item, then change to droplet or folder action. Another thing that doesn’t looke right is the error handler. If an error occurs, the error number returned will be an error from the system or AppleScript and not from the shell command. If you want error from the command to return to the script, you need to do something else. I really don’t understand it very well myself, but the info in the Apple article explains it a little:
It seems like myscript is not working becuase clamscan is not detecting the file as malicious when clamxav is.
NG what you typed help explained better on what I had to do but like I said before the problem is with clamscan, so untill I fix this problem script will never work:)
So till then this thread is done and I appreciate your help every one
BTW clamscan is apart of clamav.net virus package
If curious just install clamxav at clamxav.com to find out what command does.