Reputation: 55
I am working on an Automator Application (drag and drop) to rename some files. One of things I want to do is strip out the "where from" of the zip file. This script works, except it asks for the file when run vs allowing me to just drag/drop the file on top of the app icon.
What am I doing wrong? How do I make the application drag/droppable?
on deleteWhereFrom(fileToClean)
try
set posixPath to quoted form of POSIX path of fileToClean
do shell script "xattr -d com.apple.metadata:kMDItemWhereFroms " & posixPath
end try
end deleteWhereFrom
on open zip
repeat with i in zip
deleteWhereFrom(i)
end repeat
end open
on run
set zip to choose file with multiple selections allowed
repeat with i in zip
deleteWhereFrom(i)
end repeat
end run
Upvotes: 0
Views: 840
Reputation: 3422
In an AppleScript application, the open handler is used to get items dropped onto the droplet. In an Automator application however, items dropped onto the application are passed on to the first action in the workflow, which does whatever it does and passes its result to the next action in the workflow, and so on.
For the Run AppleScript
action, its input is in the input
parameter to the run handler, which is a list of items passed from the preceding action, and when the run handler finishes doing whatever it does, the result returned is what gets passed on to the following action.
In your original sample, the problem is that the Run AppleScript
action is not using any of the items that are being passed along in the workflow, but is instead using choose file
to ask for the items to use (again). Your script should be:
on run {input, parameters}
repeat with i in input
deleteWhereFrom(i)
end repeat
return input -- return the input items to any following actions
end run
on deleteWhereFrom(fileToClean)
try
set posixPath to quoted form of POSIX path of fileToClean
do shell script "xattr -d com.apple.metadata:kMDItemWhereFroms " & posixPath
end try
end deleteWhereFrom
Note that depending on any previous actions you are using, you may need to use a Set Value of Variable
action at the beginning of the workflow to save the original items (the ones dragged onto the application), and then use a Get Value of Variable
action (setting its "Ignore this action's input" option as needed) to get those original items in order to pass them on to the Run AppleScript
action.
Upvotes: 1