1

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.

0
0

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
6
  • Thanks for this. I had come to the same conclusion regarding the "sudo" command. Unfortunately this code is still not having the desired effect. The workflow is successfully triggering and showing a "working" wheel in the upper menu bar: when I click on this I see progress and then a "failed" message. – LigetiFan Oct 17 '20 at 15:43
  • @LigetiFan, Please provide the particulars of your Folder Action in an edited update to your question. What folder is being watched and where that folder located? How are the files been placed in the watched folder? Also add a screenshot of the Folder Action as shown in Automator. what version of macOS are you running? Without this additional information there is no way for us to troubleshoot the issue. – user3439894 Oct 17 '20 at 15:53
  • Folder being watched is located at /Library/Audio/Plug-Ins/Components. Files would usually be placed by either dragging into the folder or unzipping a .zip file to that location (both methods are successfully triggering the workflow). Running macOS Catalina 10.15.7. I'm not sure how to attach a screenshot but so far my workflow is just your shell script code attached to that folder! – LigetiFan Oct 18 '20 at 21:12
  • @LigetiFan, Are the files going into /Library/Audio/Plug-Ins/Components, as in the root of the Macintosh HD, or are they going into ~/Library/Audio/Plug-Ins/Components as in one's Home folder? If the former, then that's going to be an issue. Which is it, and are individual files, folders or both being adde to watched folder? – user3439894 Oct 18 '20 at 22:09
  • @LigetiFan, Please see the Update to address comment: section of my updated answer. – user3439894 Oct 18 '20 at 23:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .