How to monitor contents of sub-folders in a Folder Action?

Hello. I am wondering how I might read a folder's contentModDate within Terminal, i.e. from the command line and/or within a Folder Action.
This is the situation: I am running Periscope Pro (PP) for motion-detected videos, which by default, places them within the user's ~/Movies/com.zipzapmac.Periscope-Pro folder. Within that folder, PP creates a folder with it's name based upon (a) machine name and (b) primary MAC address. For example, we'll pretend this folder is called MacPro(001122334455). Then within that folder, as PP is running in motion-detection mode, it creates a new folder based on the current date and then, within that, places videos when motion is detected. Very straight-forward and it works just fine.
What I would like to do is have a folder action that (a) detects when any new folder or file is created within MacPro(001122334455) and (b) sends me a text-message via Apple Mail.
If the MacPro(001122334455) folder is empty, I can create a Folder Action that will detect the creation of a sub-folder when the first motion-detected video is created and that successfully sends me a text-message, BUT if a second video is created later within the same date-named folder, I will not get a message. I would get a text-message on the following day as a new folder is created within MacPro(001122334455) that signals the first motion-detected video of the day, but again not subsequent videos on the same day.
The text-message via Apple Mail I have easily scripted via Applescript and it works flawlessly.
Since Folder Actions only work upon a single pre-defined folder and not on sub-folders, I can never get automatically notified via text-message of second/third/fourth/etc. motion-detected videos as they're created... only the first one of each day.
So, I'm wondering whether there's a different way, perhaps through launchd that I might script this process. I'm thinking that if the contentModDate value of the MacPro(001122334455) folder could be read, compared with the last known value, and then---if different---execute the Applescript. OR PERHAPS I'm going about this all wrong and you might have another, better idea?
I'm open to suggestions.
-- David (da2357)

Well, I found a solution that does not use a Folder Action. Since Folder Actions will only work upon the specified folder and not upon the contents of any sub-folders, I needed a different solution.
First, I launched Terminal and created a new file called monitorPeriscope. I set executable permissions (chmod 700 monitorPeriscope). The contents of the file:
#!/bin/bash
# monitor the size of a specified folder and
# when the size increases, run an applescript
# copyright 2013, david dot allie at me dot com
# you are welcome to use this script, but please attribute authorship.
# CONSTANTS
WATCHFOLDER="/users/xadmin/movies/com.zipzapmac.Periscope-Pro"
SIZEFILEONE="/users/xadmin/.bin/foldersizeone"
SIZEFILETWO="/users/xadmin/.bin/foldersizetwo"
MYAPPLESCRIPT="/users/xadmin/documents/dropbox/programming/applescript/motion_de tected_text.scpt"
# START
# calculates current size of watchfolder, saves to sizefiletwo, then
# performs a diff operation, result which is evaluated in if statement,
# and if different, runs applescript, and copy sizefiletwo to sizefileone
du -h -k -d3 -c $WATCHFOLDER | awk 'END{print}' | awk '{print $1}' > $SIZEFILETWO
diff --brief $SIZEFILEONE $SIZEFILETWO
if [ $? -eq 1 ]
  then
    osascript $MYAPPLESCRIPT
    cp -f $SIZEFILETWO $SIZEFILEONE
fi
exit 0
Next, I created the following Applescript, replacing Some User, [email protected] and the text address of [email protected] below with my real values.
using terms from application "Mail"
tell application "Mail"
set theName to "Some User"
set theAddress to "[email protected]"
set theContent to "Motion detected in OFFICE."
set newMessage to make new outgoing message
tell newMessage
make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
set visible to true
set sender to "[email protected]"
set subject to "ALERT "
set content to theContent
send newMessage
end tell
end tell
end using terms from
Next, using the touch command, I created /users/xadmin/.bin/foldersizetwo and /users/xadmin/.bin/foldersizetwo as needed for the bash shell script (touch /users/xadmin/.bin/foldersizeone and touch /users/xadmin/.bin/foldersizetwo).
Next, still in Terminal, I navigated to ~/Library/LaunchAgents and created the following plist using nano, which I named com.xadmin.monitorPeriscope.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
          <key>Disabled</key>
          <false/>
          <key>Label</key>
          <string>com.xadmin.monitorPeriscope</string>
          <key>ProgramArguments</key>
          <array>
          <string>/users/xadmin/.bin/monitorPeriscope</string>
          </array>
          <key>RunAtLoad</key>
          <true/>
          <key>StartInterval</key>
          <integer>900</integer>
</dict>
</plist>
Finally, all that was needed was to log out and then log back in. Once I launched the Periscope Pro app and started the motion-detection mode, I left my office... and within fifteen minutes I received a text message indicating that motion had been detected in my office. In the plist above, I set a StartInterval of 900 seconds, which corresponds to 15 minutes. I can reduce it down to 300 seconds (5 minutes) without it adversely affecting performance, but I'm going to leave the setting where it is for now.
So, I solved my own problem and I'm pleased with the results.
-- David

Similar Messages

  • How can I get the sub folders in room structure?

    Hi guys,
    I have a quesion: in KM-Collaboration-roomstructure, if I have a folder A, how can I get its sub folders like A.1,A.1.1,A2.
    I mean of course  how code can realize: using context folder=(IPcdContext) ictx.loopup(path) ?
    Please give me some hint!
    Thanks so much!
    Regards,
    Liying

    The phone number format as well as the date language and format and the time format are controlled by the Region Format setting. Go to Settings > General >International > Region Format.  When you change a region format, you can go back one page (to International) and see an example of the date/time/phone number format that your selected region format will produce.

  • Jsp code (js code) to display(tree) the files and sub folders in a folder

    Hi all
    plz can any one send me the source in jsp or js to display in tree structure for files and sub folders in a folder.

    There are dozens of Javascript tree widgets available on the Internet. Some are free. Some are good. Google will find them for you.
    (The only relevance of JSP to your question is that yes, you can generate HTML that uses one of those Javascript tree widgets.)

  • How to restrict access to sub folders (apart from Manual settings)?

    Hi,
    Is there any method to stop the  group traverse from main Folder to sub folder when user group has access to main folder?
    So that no need to give no access to sub folders manually for given group.
    Manual access settings have become tedious due to large number of sub folder and user groups.
    Scenario:-
    There is a main Folder F1 and it has 100 Sub Folder SF1 to SF100. And these sub folders has child folders.
    Group G1 should have access only  F1, and should not have the access its child folders.
    How can we eliminate manual work to remove access for each group at each sub-folder level?
    Thanks,
    Anu

    Access restrictons by default are inherited from parent folders downward.
    You can break the inheritance, but you'll still need to manualy setup initial security.
    Details are in the Admin guide.

  • Coping folder contents and sub folders

    So, I'm working on a little practice folder sync project (fun with my mac)...
    ...and I'v gotten hung up a bit because my little copying app doesn't seem to count folders and sub folders (which I suppose makes sense).
    My initial idea was to take just the date of modification and compare it to the last date that the app was run, inorder to only copy changed files. But this seems problematic on a few levels, so...
    So, my two part question is:
    1. Is there a simple command to copy folder contents and sub-folder contents, or do I need to tell the script to do each sub-folder individually?
    2. I imagine that a better way to manage which files/folders need to be updated is to create a file with a list of the contents, and dates of modification, and compare the new folder list and the old folder list to each-other... ok.. so, um. yeah. that sounds tricky.

    >1. Is there a simple command to copy folder contents and sub-folder contents, or do I need to tell the script to do each sub-folder individually?
    There are two common solutions to this.
    The first is to use the Finder's 'entire contents of...' command to get a list of everything in the folder, including sub-folders, the second is to make your script recursive - that is, it calls itself several times over.
    In the first case it's as simple as:
    tell application "Finder"
    set allItems to entire contents of folder "path:to:source:folder:"
    -- rest of code goes here
    end tell
    This can have problems, though, especially on very large directories since the Finder is not very efficient at building a list of hundreds or thousands of files.
    The recursive path is a little trickier, but you write a handler to process a folder then repeatedly call that handler, like:
    <pre class=command>on run
    set sourceFolder to (choose folder)
    processAFolder(sourceFolder)
    end run
    on processAFolder(theFolder)
    tell application "Finder"
    set allItems to items of folder theFolder as alias list
    repeat with eachItem in allItems
    if class of eachItem is folder then -- we have a subfolder
    processAFolder (eachItem)
    else
    -- code here to compare the file and back it up
    end if
    end repeat
    end tell
    end processAFolder</pre>
    So here you walk through the folder, each time you find a new folder, you walk through that until you're done. The code takes care of keeping track of where you are in the folder hierarchy.
    >2. I imagine that a better way to manage which files/folders need to be updated is to create a file with a list of the contents, and dates of modification, and compare the new folder list and the old folder list to each-other... ok.. so, um. yeah. that sounds tricky.
    There's no need to keep a file. Assuming you have two folders you can just walk through one of them checking to see if each item exists in the other, then copy the newer file to the other directory, like:
    <pre class=command>on processAFile(fileName, sourceDir, destDir)
    tell application "Finder"
    -- check if the files exist
    set sourceFileExists to (file fileName of folder sourceDir exists)
    set destFileExists to (file fileName of folder destDir exists)
    -- now comes the logic
    if sourceFileExists and not destFileExsits then
    duplicate file fileName of folder sourceDir to folder destDir
    else if destFileExists and not sourceFileExists then
    -- assuming you want a two-way synch
    duplicate file fileName of folder destDir to folder sourceDir
    else -- both files exist, so check mod dates
    if (modification date of file fileName of folder sourceDir) > (modification date of file fileName of folder destDir) then
    duplicate file fileName of folder sourceDir to folder destDir
    else if (modification date of file fileName of folder destDir) > (modification date of file fileName of folder sourceDir) then
    duplicate file fileName of folder sourceDir to folder destDir
    end if
    end if
    end tell
    end processAFile</pre>
    If you're not planning a two-way synch an even simpler option is to just keep track of the last time the synch was run. Then all you need to do on subsequent runs is ask the Finder for 'every file of folder sourceFolder whose modification date is greater than lastRunDate'.

  • [Mac OSX / JS] How to find images inside sub folders using getFiles?

    Hi,
    My script uses the variable myFolder to store the path for the images Folder. But when I try to use myFolder.getFiles() to retrieve images that are in sub folders the script fails. The result is null. What can I do to force myFolder.getFiles() to search inside all sub folders?
    var myFolder = Folder().selectDlg("Select images Folder");
    var myFiles = myFolder.getFiles();
    I will appreciate any help.
    Thanks,
    Candido

    Hi John,
    Thanks for your help.
    I'm rushing to my work  so I don't have enough time to sort it out at the moment.
    If I understand you correctly, it should be something like so:
    var files;
    var folder = Folder.selectDialog( "Select a folder with images" );
    if (folder != null) {
         files = GetImages(folder);
         if (files.length > 0) {
              alert("Found " + files.length + " image files");
         else {
              alert("Found no image files");
    function GetImages(theFolder) {
         var imageFiles = [],
         fileList = theFolder.getFiles(),
         i, file;
         for (i = 0; i < fileList.length; i++) {
              file = fileList[i];
              if (file instanceof Folder){
                   GetImages(file);
              else if (file instanceof File && file.name.match(/\.(jpg|psd|tiff|pdf|eps)$/i)) {
                   imageFiles.push(file);
         return imageFiles;
    But it doesn't work.
    Regards,
    Kasyan

  • Need help in creating multiple sub folders in new folder

    hi all,
    need to seek some expert advise.
    i need to create an automator work flow as once launch, it will show a dialog asking user for the new folder name to be created, and asking user how many sub folders to be created.
    i have done the following and got stuck...
    requirement is user ket in foldername upon dialog for example "test" and no of sub folders to create exp "5"
    it will create a folder call "test" on desktop n 5 subfolder as: test1 , test2, test3, test4, test5.
    Apple script

    Automator gets a bit unweildy when trying to vary things outside of what the actions provide.  Since you are already using an AppeScript in your workflow, might as well do the whole thing:
    set baseFolder to (path to desktop) -- the location to create the folder
    display dialog "Please provide a new folder name:" default answer "test"
    set folderName to text returned of the result
    repeat -- keep repeating until a number is returned
      display dialog "How many subfolders?" default answer "5"
      set theNumber to text returned of the result
        try -- test the result
          set theNumber to theNumber as integer
          exit repeat -- success
        end try
    end repeat
    tell application "Finder"
      try -- make new folder
        set newFolder to (make new folder at baseFolder with properties {name:folderName})
      on error number -48 -- skip errors if the folder is already there
        set newFolder to ((baseFolder as text) & folderName) as alias
      end try
      repeat with X from 1 to theNumber
        try -- make new subfolder
          make new folder at newFolder with properties {name:folderName & X}
        on error number -48 -- skip errors if the folder is already there
        end try
      end repeat
    end tell

  • Sub-Folders in applications folder

    Hi,
    I have accumulated a large amount of apps in my apps folder and I want to know if it will cause system problems if I create sub-folders to group them for ease of finding.
    What do you think?
    Thanks in advance.
    SR

    Before proceeding you might want to look at the advice in This thread.
    In a nutshell, for non Apple apps - should be no problem. For Apple apps - leave them where they are but create aliases to them. The aliases can go where you like. In a folder in the sidebar of Finder would be convenient…
    Have fun,
    Adrian

  • Automator - Filter Finder Items filtering contents of sub folders

    I have an external hard drive and I want to keep my iTunes music library automatically backed up on it. I am using automator to copy my most recent files to the external (run the script once a week). I let iTunes manage all my audio files, etc so I figured the created, modified, opened dates would be the best way to filter the items I want to copy over. The workflow is as follows.
    1) Get Specified Finder Items (iTunes Library Music folder)
    2) Get Folder Contents (All artist directories (Repeat for each subfolder found is NOT checked)
    3) Filter Finder Items (ANY of Date Last Modified, Date Created, Date last opened in the last week)
    4) Copy finder items (to my external hard drive)
    I am having two problems.
    1) If I play a song from my second hard drive iTunes copies it into it's directory when it opens... iTunes Music > Artist > Album > Song.mp3. The mp3's modified date, created date, and last opened date is the same as the file that got copied. The new Artist and Album directories that were created by itunes have current created dates (makes sense). However, the filter is still not catching it. Only if the mp3 is current will the filter catch it. I DON'T have 'Repeat for each subfolder found'... shouldn't the filter check for the folder's modified, created and last opened dates?
    2) If everything works the way I want it to I see this to be a problem in the future. If I add an album by an artist that I already have an album for, the filter will skip it. Any suggestions on how I could handle this problem?
    Thanks.

    Found out that since Hebrew was set up first in the language option the filter on textual was failing. After I changed the order of the languages in the language preferences the file filter by name, extension etc… worked O.K.
    Nati

  • How to alphabetically sort albums and folders within a folder

    Much to my dismay, I discovered that iPhoto will not alphabetically sort folders or albums that are within a folder. It will only sort folders and albums (in separate groups) that are at the "root" level beneath the ALBUMS label. I used "iPhoto Folder Import 1.0" to import multiple clip art and stock photo files which resulted in many nested folders and albums that did not stay in alphabetical order (because iPhoto often randomize them when you add them to an existing folder).
    Here's how to get around the problem.
    Albums: 1. Select all the albums in a folder. 2. Drag the albums to the ALBUMS label so they end up on the root level. 3. Right click on any of the selected albums and choose "Sort Albums." 4. Drag the still selected albums back into their original folder. They should retain their alphabetical order.
    Folders: 1. Close all the folders that you want to alphabetize. 2. Follow steps 1-4 above with "folders" in place "albums."
    I cannot understand why sorting won't work within folders. I also do not understand why we don't have the option to alphabetically interleave folders and albums. The only way to achieve this is to create folders for just one album, which seems silly.

    crossrulz wrote:
    CSmith8 wrote:
    Thank you for a quick response.
    How do you suggest i resolve the issue of different data types in order to use this function? I have tried a few different ways and have whenever I adjust, it wont run through my sub VI's correctly due to being different data types.
    You have to READ THE FILES.  Jeff just showed you how to use a FOR loop to go through the files.  You still need to open the files, read them and then process the data.
    I had assumed from CSmith8's original post that the text file processing vi worked.  just drop that vi into the for loop and wire the file name in!
    Alternately, attach the code that processes the file and a sample file.  I bet we can show you a thing or two about how to do it cleaner and faster  then point you to the right learning resources so one day you can show us some new tricks.
    -Old Dog Jeff·Þ·B
    (Why does everyone forget the commas?  alt+0183 alt+0222 alt+0183) 

  • Solved: how to delete those pesky "require" folders in Home folder

    I was bummed that OS X now tries to "require" you to have folders like Sites, Downloads and so on in the home folder. Force Delete 1.2 will make short work of these, in case anyone else is stumped about how to delete the folders.
    Download it at http://mac.softpedia.com/get/System-Utilities/Force-Delete.shtml

    I have attached a vi. Is this the one that you need?
    Anand kumar SP
    Senior Project Engineer
    Soliton Technologies Pvt Ltd
    Attachments:
    plot selector modified.vi ‏14 KB

  • How do I delete file extensions on files in sub folders?

    I want to delete all file extensions on the files I have in several sub folders.
    If I highlight the files themselves in a folder and run "Get Selected Finder Items", then "Replace Text in Finder Item Names", then it works. However, how can I have Automator choose ALL files in ALL sub folders of a folder and then do it's magic on all those files at once?
    Thanks.

    Does the Notebook software accept aliases? If so, you could rename aliases instead of the main file, so that the original extensions are preserved.
    For your original question, you can use an action to get the folder contents, and adding a filter action will just give you the file names - for example:
    1) *Get Selected Finder Items*
    2) *Get Folder Contents* (repeat for each subfolder found)
    3) *Filter Finder Items* -- remove items that are folders
    4) *Replace Text in Finder Item Names*

  • How to search all files in folders/subfolders for one or more strings?

    I have a list of files (full path and file name) in Column D of my worksheet.  I'm trying to figure out how to run some code to open each file in this array (starting on D14 and going down), search for one or more strings, and then put an "X"
    in Column I, in the same row as the file name.
    How can I do that?
    I experimented with a few samples of code.  It seems pretty easy to do it in one folder, but not all sub folders.  The folder/subfolder is setup a specific way for a specific purpose.
    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Below is an example that allow you to search a directory and its subdirs txt files(you can change this), read its lines and search for specific word:
    using System;
    using System.IO;
    using System.Linq;
    class Program
    static void Main(string[] args)
    try
    var files = from file in Directory.EnumerateFiles(@"c:\", "*.txt", SearchOption.AllDirectories)
    from line in File.ReadLines(file)
    where line.Contains("Microsoft")
    select new
    File = file,
    Line = line
    foreach (var f in files)
    Console.WriteLine("{0}\t{1}", f.File, f.Line);
    Console.WriteLine("{0} files found.", files.Count().ToString());
    catch (UnauthorizedAccessException UAEx)
    Console.WriteLine(UAEx.Message);
    catch (PathTooLongException PathEx)
    Console.WriteLine(PathEx.Message);
    https://msdn.microsoft.com/en-us/library/dd997370%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
    Fouad Roumieh

  • How to configure the permission between folders and groups programlly?

    Hi guys,
    I am developing extension for permission, here I have a question:
    I have a template which contains more sub folders, for each folder the corresponding group should be assigned by certain permission. for example: group g1 has "write" permission to folder f1; group g2 has "read" permission to folder f2 and so on. I assign these permissions by extension programlly. But now I have to provide the possibility (to user) to configure these permissions, that means if in future instead of group g1 has "write" permission to folder f1, group g1 has "read" permission to folder f1. This  kind of change should be allowed by extension. Should I set folders and groups as input parameter in an extension, and give the user possibility to input permission type? In another word, my program is supposed to get the permission from GUI and then create ACL. But where can I set the possibility for user to define the permission? And how can I read this permission?
    I hope I explained it clearly enough.
    Any help is greatly appreciated!
    Regards,
    Liying

    Hi jennifer,
    Find this usefull, follow steps at PAGE 3,
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/419b479b-0801-0010-f8a1-c26208b4b209
    Regards
    Juan

  • FOLDERS, On/Off sub-folders pre-view issue  (what do you think?)

    Yes, I see the benifit of how LRv1 is showing all the subfolders in the Main Folder. and Yes, tomrock has a solution that works.
    My problem is ... as LRv1 is now ... Folders as a File organizer does not show what is truely there. and can be somewhat confusing.
    The other issue is for those that already have there folders organized.
    What is logical ... and what you would "expect" to see in a Folders listing is exactly what is listed on Disk. (a true veiw).
    Now for more power (choice) ... yes, a On/Off for "show all sub-folders" in this folder is great and useful ... but it should be a choice, NOT a requirement.
    * In fact how I think it should work ... is you should be able to just go to ANY folder ... Right click and choose from a drop down menu ... turn On/Off the "show all sub-folders".
    It's all about choice. (not that one way is better)
    But, imho in order to File manage ... you NEED to at least start with the "true" veiw of what is on the your Disk (and be able to quickly and easily go back to it ... if you changed it)
    * When is ever a actual view of your folders on your Hard Disk a bad thing? or should not be "at the very lesst" A CHOICE?
    my little rant lol
    HG
    tomrock's work around ... it works ... I like it ... I just don't want to have to do it with all my folders I have aleady created.
    tomrock - 1:40pm Feb 22, 07 PST (#14 of 18)
    It is weird that Adobe turned this off after the beta. Another "solution" is to make your folders like this:
    Top level folder
    --Raws
    --Tiffs
    --Jpegs
    Of course, when you click the "Top level folder" you see everything and you have to open the triangle thingy to see the lower folders. I like this better than color coding files.
    And at least you can do this in LR.

    Brian,
    GREAT TIP ... and easy ... love it.
    Only two issues with LRv1 making you do it this way.
    1) there "should" be a Quick and FAST way for you to SEE exacly what is there ... like an ON/Off switch that you can get to from "just" right clicking on the Folder
    * at some point you just might want to see what is truly in your folders on your HD.
    2) If LR is not going to do this ON/Off switch ... which I think would not be logical ... Adobe should at least put the MetaData browser sort on a Menu choice ... that drops when you Right mouse click on the Folder.
    With that being said:
    "Props" to Adobe, ... as I learn more about Stacking and Versions, Ctrl+E, and Export w/Actions within LRv1 ... I am "Seeing" the Logic of what they are doing.
    It "will" change the way I work ... but, it will be for the better (I must admit) AND, I might "not" have changed if it was not for LRv1 forcing me to do so.
    HG
    Changing for the better ... kicking and screaming
    Brian Witter - 12:19am Feb 24, 07 PST (#20 of 20)
    Here is one more option if the top level is only raw or DNG and the sub folders are TIF and/or JPG.
    Select the top level folder
    Go to the Metadata Browser>File Type
    Ctrl(Cmnd) click Raw or DNG
    If you want to see more than one file type, but not all, just Ctrl click on the desired file type to add. To switch, repeat the Ctrl click on the file type you're done with.
    I'm hoping they'll add a switch to control viewing sub folders again so I plan to do it this way for now rather than add a new empty folder at the base of each branch in my folder tree.

Maybe you are looking for