Apple Automator: where does it store a new filename

applescriptautomatorfinder

I have a line of code (that I can run successfully in Terminal) I'd like to incorporate into an Automator workflow but I can't work out how to reference the filename. I've set up my workflow as a Folder Action and applied it to the correct folder so dragging a new file to that folder triggers the workflow (this part is working correctly).

My line of code is

sudo xattr -rd com.apple.quarantine [PATHNAME_TO_FILE]

It sets the preferences on the file to obviate Apple's quarantine process run by the Logic program, allowing a third-party file to pass muster.

What does Automator want me to use as [PATHNAME_TO_FILE]? I've tried "$@", "$#", "$0", "$1", "$2", etc, etc. but had no luck.

Best Answer

If you've set up an Automator workflow as a Folder Action and have added a Run Shell Script action, you'd set Shell: [/bin/bash] and Pass input: [as arguments] and use the following example shell script code:

for f in "$@"
do
    xattr -rd com.apple.quarantine "$f"
done

Note: You should not need to use sudo as you've shown in your OP.


Update to address comment:

If the target of the watched folder is /Library/Audio/Plug-Ins/Components, as in the root of the Macintosh HD, then you'll need to take a different approach.

Set up an Automator workflow as a Folder Action adding a Run AppleScript action, replacing the default code with the example AppleScript code shown below.

Testing under macOS Catalina 10.15.6 the Automator workflow Folder Action, described immediately above, worked for me when adding file(s)/folder(s) to /Library/Audio/Plug-Ins/Components, as in the root of the Macintosh HD.

  • Note: Upon manually placing file(s)/folder(s) into the target watched folder and authenticating that action, I was then prompted to re-enter my credentials so the do shell script command would run as if using sudo on the command line in Terminal on the xattr command .

Example AppleScript code:

on run {input}
    set itemList to {}
    repeat with aItem in input
        set end of itemList to quoted form of (POSIX path of aItem) & space
    end repeat
    set shellCMD to "xattr -rd com.apple.quarantine " & itemList as string
    do shell script shellCMD with administrator privileges
end run