How do I Watch a folder on a Mac using Powershell?

Hi All,

I am completely new to Powershell and would love to hear some advice.

I am setting up a network render for After Effects and my mac is the main machine. My system will automatically make an After Effects file and place it into a folder for rendering by a PC, however Powershell fails to recognize a new file in the watch folder on the Mac


I have set up a watch folder using the following code:

### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = "\\MARKS-MAC-PRO\Macintosh HD\Users\snaplash\Dropbox\AEP_PROCESSING_DO_NOT_DELETE"
    $watcher.Filter = "*.aep"
    $watcher.IncludeSubdirectories = $false
    $watcher.EnableRaisingEvents = $true  

### DEFINE ACTIONS AFTER A EVENT IS DETECTED
    $action = {$path = $Event.SourceEventArgs.FullPath
$name = [System.IO.Path]::GetFileNameWithoutExtension($path)
###New-Item -ItemType directory -Path C:\Users\PC2\Dropbox\PROCESSING_DO_NOT_DELETE\$name
start powershell.exe "cmd.exe /C 'C:\Program Files\Adobe\Adobe After Effects CC\Support Files\aerender.exe' -project $path -comp '$name' -s 0 -e 900 -output C:\Users\PC2\Dropbox\PROCESSING_DO_NOT_DELETE\$name\[#####].jpg"
timeout 2
start powershell.exe "cmd.exe /C 'C:\Program Files\Adobe\Adobe After Effects CC\Support Files\aerender.exe' -project $path -comp '$name'-s 901 -e 1800 -output C:\Users\PC2\Dropbox\PROCESSING_DO_NOT_DELETE\$name\[#####].jpg"
timeout 2
start powershell.exe "cmd.exe /C 'C:\Program Files\Adobe\Adobe After Effects CC\Support Files\aerender.exe' -project $path -comp '$name'-s 1801 -e 2888 -output C:\Users\PC2\Dropbox\PROCESSING_DO_NOT_DELETE\$name\[#####].jpg"
}


### DECIDE WHICH EVENTS SHOULD BE WATCHED + SET CHECK FREQUENCY  
    $created = Register-ObjectEvent $watcher "Created" -Action $action
     while ($true) {sleep 1}

It see's the folder on the mac, but will not recognize when a file is added. (although this is a Dropbox folder, syncing is turned off)

If I change the location to a local folder on the PC all works well, as does using Dropbox without networking

I can see the location on my PC and all read/write is enabled.

I have also Mapped that as a drive, but still to no avail.

I upgraded to Powershell 3 but cant figure where I an going wrong, any help and advice would be very very welcome!

Thank you All!

Mark

April 27th, 2015 1:13pm

I'm wondering if the Provider for your Dropbox "drive" exposes the necessary API/functionality for this to work.

try typing "get-psdrive | select *" and see if the provider and credential are the same for your other network drives. 

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 3:20pm

Hi Zargberg,

Thank you for your insight its truly appreciated!

However this problem still happens when I link to a folder on the desktop.

The issue seems to be in the code not being able to recognize changes on the mac.

Do I need to use .net do you think?

April 27th, 2015 4:43pm

I was actually able to get a trimmed down version of your code to function as you intended on my computer, I used this:

### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = "\\Server\Users\dnw\test\"
    $watcher.Filter = "*.txt"
    $watcher.IncludeSubdirectories = $false
    $watcher.EnableRaisingEvents = $true  

### DEFINE ACTIONS AFTER A EVENT IS DETECTED
    $action = {$path = $Event.SourceEventArgs.FullPath
$name = [System.IO.Path]::GetFileNameWithoutExtension($path)
start powershell.exe "cmd.exe /C 'C:\Program Files (x86)\Notepad++\notepad++.exe' -project $path -comp '$name'"
}


### DECIDE WHICH EVENTS SHOULD BE WATCHED + SET CHECK FREQUENCY  
    $created = Register-ObjectEvent $watcher "Created" -Action $action
     while ($true) {sleep 1}

It waited until I placed a .txt file in the folder noted, and then fired up notepad++

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 5:04pm

Once again thank you!

This works when I assigned the watch folder to another PC on the network, but not when I do it from the mac.

After some more delving, when I look at the properties of the shared mac folder, when I click on the network tab I get a warning

The Server XXXX does not accept remote requests.

Would you know how to fix that by chance?

Thank you again!


April 27th, 2015 5:35pm

The MAC does not participate in the Windows events structure (SENS).  It is a Windows only feature.

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 6:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics