How to get automator to trigger folder action when file is downloaded by Google Drive Sync

I have an Apple Automator Folder Action that takes files placed in a "Process" folder, makes a copy of them, modifies the contents and then places them in a "Modified" folder. It works just as expected when I use finder to put files in the "Process" folder, but I also need it to process files when Google Drive Sync downloads a file into the "Process" folder as well. When I tried using Google Sync to download in files the Folder Action never got triggered. It didn't seem to matter how many files got downloaded in by Google Drive Sync it didn't trigger the Folder Action. I know the script is working because if I then added a file to the folder manually with Finder it would run the Folder Action on all the files in the folder even the ones that Google Sync added. For some reason the downloading of the file into the folder by Google Sync just isn't triggering the Folder Action.

Is there a way to set this up so that when Google Drive Sync finishes downloading the a file into the folder it also triggers the Folder Action I created?


Solution 1:

I just tested this process and it works for me. First I would not have Google Drive sync files directly into your “Process Folder”. Let Backup and Sync download and sync everything to and from the Google Dive folder on your computer.

To do this, quit the Backup and Sync app. Then go to Finder and temporarily move the current folder it is synching to, to a different location. Then launch Backup and Sync app and in your menu bar Click —> Backup and Sync and then Locate. Find your Google Drive folder and click Open.

After that is all set up and working correctly, go back and move that folder that you temporally moved, back to its original location.

Next, we will create a Folder Action to attach to your Google Drive folder. Now, when files are added to that Google Drive folder and after they are finished synching, the Folder Action will move the synched files to your “Process Folder”. Once that happens, those files should trigger your already existing Folder Action attached to the “Process Folder”.


After inserting the path to your “Process” Folder (between the quote marks in this line)…
property processFolder : alias ""

Save this following AppleScript code in Script Editor.app to your /Users/YOUR_SHORT_NAME/Library/Workflows/Applications/Folder Actions. folder

property processFolder : alias "" — insert path to your “Process” Folder

on adding folder items to theFolder after receiving theNewItems
    --  Called After Items Have Been Added To A Folder
    --
    --  theFolder is a reference to the modified folder
    --  theNewItems is a list of references to the items added to the folder 
    repeat with thisItem in theNewItems
        tell application "Finder"
            (move thisItem to moveToFolder) as alias
        end tell
    end repeat
end adding folder items to

if you don’t know how to properly get the path to your “Process” folder, run this following one line of code in a separate document. It will let you choose the “Process” Folder and the correct path will be stored in your clipboard. Then you can paste that (between the quote marks in this line)…
property processFolder : alias ""

set the clipboard to (choose folder) as text

Now all you need to do is go to Finder and right click on the Google Drive Folder and select Services/Folder Actions Setup… and attach the Folder Action script you just created