Folder action delay until done

I run a video encoding software called Episode Engine, and what it does is while encoding a video, it kicks out a temporary file in the output folder with a file size of 0. It does not actually update the filesize until encoding is complete.
What I want to do is set a folder action to an output folder (which receives up to 5 videos at a time from encoding) that uploads the file automatically to a Transmit (FTP Client) favorite. I also want to account for the fact that I may drop large files in this folder as well, which could take time, but dont stay at 0 file size until the transfer is done. The part I'm having trouble with is delaying the transmit action until the file is done encoding. What I currently have does not work. And I dont know any way to monitor a folder action workflow, so I'm not sure where it's failing. Any recommendations?
p.s. We're still running 10.6.8 on this computer (I know, I know...)
property DELAY_TIME_SECONDS : 5 -- How long to wait between checking file size.
on adding folder items to thisFolder after receiving theItems
     repeat with f in theItems
                         set currSize to 0
                         set oldSize to 0
                         set newSize to -1
                         repeat while currSize is 0
                                        delay 2
                                        set currSize to size of (info for f)
                         end repeat
                         repeat while newSize is not equal to oldSize
                                        -- Get the file size.
            set oldSize to size of (info for f)
            delay DELAY_TIME_SECONDS
             -- Sample the size again after delay for comparison.
                                        set newSize to size of (info for f)
                         end repeat
     end repeat
end adding folder items to

Folder Actions has some built in support for recognizing 'busy' files, but it's not too intelligent.  It works well with Finder moves and copies, not so well with other things.  There are three ways I can think of to solve this problem.
Tweak your script with a test for temp files so that it skips them.  This may cause secondary headaches (e.g. you skip a temp file, but Lightroom finishes the job in the ten second throttle period so the creation of the the file(s) you want to move is missed by folder actions), but there's no way to tell unless you try.
Drop Folder Actions and set up a QueueDirectories launch agent.  This would wait for items to be added to the folder then move and delete them - you write the script to idle until temp files are done processing.
Forget about immediate gratification and write a LaunchAgent that will sync the folders hourly using rsync.
Which would you prefer?

Similar Messages

  • Automator Folder Action

    I have an Automator Folder action attached to my Downloads folder which moves any .jpg file to another folder where I normally place my images. It works for a while (automatically moving the .jpg files whenever a file is placed in the Downloads folder) and then stops fopr no apparent reason. On occassion when I logoff and on or restart, the action will work for a limited time.
    I don't have much experience with Automator and even less with Applescript. Any help will be much appreciated.
    I use an iMac with OS X 10.9.2.
    Thanks.

    Sorry... this is not an answer to your problem. More like an addition to your question.
    How do you attach an Automator Workflow as a folder action?
    I've made a Workflow to copy all files from an iTunes' playlist to a USB device, I want it to automatically run whenever I plug in the USB device. I've left-clicked the icon for the USB device and then "attach folder action", but I don't see any script to run an Automator Workflow.

  • Delaying folder action until file creation is complete

    I'm trying to create a folder action that takes the output of a bounce from ProTools and then imports it into iTunes. The problem I'm having is that it takes real time (about 20 min) to create the complete ProTools file in the folder, however the script begins to execute immediately, before the bounce is complete. This gives me 1 second of audio garbage.
    Is there any way to delay the folder action until the file creation (bounce, upload, transfer, whatever) is done?
    Thanks.

    V.K. Thanks again for your help. When I look in my folder directory/library/scripts/folder action scripts, I see many scripts for images as well as scripts for closing subfolders, converting to pdf, open - show comments in dialog, and add - new item alert, however I don't see anything that was created recently (i.e. something that was created when I built my Automator workflow (folder action). The closest (to what I am looking for) Folder Action Script could find was "add - new item alert.scpt", which is an existing Apple written script, but this will not really help me. When I created my initial automator script, it created a folder and file and workflow in my homefolder/library/Workflows/Applications/Folder Actions/xxx.workflow, however I cannot open this workflow in applescript. I even tried changing the extension to .scpt. I'm not sure I can accomplish the desired result with Automator alone, but I don't think I am well versed enough in AppleScript. Thanks for your help.

  • DB -What action have been done by until cancel?

    ORALCE 8174/Hotbackup:
    SQL> SELECT TO_CHAR(CHECKPOINT_CHANGE#) DATAFILE_SCN, TO_CHAR(LAST_CHANGE#) DATAFILE_LASTSCN FROM V$DATAFILE;
    2 /
    DATAFILE_SCN DATAFILE_LASTSCN
    9220396163609
    9220396163791
    9220396163711
    9220396163711
    9220396163764
    9220396163764
    9220396163789
    9220396163611
    9220396163624
    9220396163791
    9220396163655
    DATAFILE_SCN DATAFILE_LASTSCN
    9220396163655
    12 rows selected.
    SQL> SELECT TO_CHAR(CHECKPOINT_CHANGE#) DATAFILE_HSCN FROM v$datafile_header
    2 /
    DATAFILE_HSCN
    9220396163609
    9220396163667
    9220396163687
    9220396163711
    9220396163748
    9220396163764
    9220396163789
    9220396163611
    9220396163624
    9220396163791
    9220396163640
    DATAFILE_HSCN
    9220396163655
    12 rows selected.
    SQL> recover database using backup controlfile;
    ORA-00279: change 9220396163609 generated at 07/28/2007 00:01:07 needed for thread 1
    ORA-00289: suggestion : /data1/newdb/orcl/arch/arch_1_13876.arc
    ORA-00280: change 9220396163609 for thread 1 is in sequence #13876
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    AUTO
    ORA-00279: change 9220396171447 generated at 07/28/2007 01:31:22 needed for thread 1
    ORA-00289: suggestion : /data1/newdb/orcl/arch/arch_1_13877.arc
    ORA-00280: change 9220396171447 for thread 1 is in sequence #13877
    ORA-00278: log file '/data1/newdb/orcl/arch/arch_1_13876.arc' no longer needed for this recovery
    ORA-00308: cannot open archived log '/data1/newdb/orcl/arch/arch_1_13877.arc'
    ORA-27037: unable to obtain file status
    SVR4 Error: 2: No such file or directory
    Additional information: 3
    SQL> SELECT TO_CHAR(CHECKPOINT_CHANGE#) DATAFILE_HSCN FROM v$datafile_header;
    DATAFILE_HSCN
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    DATAFILE_HSCN
    9220396171447
    12 rows selected.
    SQL> SELECT TO_CHAR(CHECKPOINT_CHANGE#) DATAFILE_SCN, TO_CHAR(LAST_CHANGE#) DATAFILE_LASTSCN FROM V$DATAFILE;
    DATAFILE_SCN DATAFILE_LASTSCN
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    9220396171447
    DATAFILE_SCN DATAFILE_LASTSCN
    9220396171447
    12 rows selected.
    SQL> SELECT TO_CHAR(CHECKPOINT_CHANGE#) DB_SCN,TO_CHAR(CONTROLFILE_CHANGE#) CONTROL_SCN FROM v$database;
    DB_SCN CONTROL_SCN
    9220396163608 9220396171447
    SQL>
    SQL> alter database open resetlogs;
    alter database open resetlogs
    ERROR at line 1:
    ORA-01113: file 1 needs media recovery
    ORA-01110: data file 1: '/data1/newdb/orcl/datafile/system01.dbf'
    *********why still show above error and can't open db?
    SQL>[color=Red] recover database using backup controlfile until cancel;[color]
    ORA-00279: change 9220396171447 generated at 07/28/2007 01:31:22 needed for thread 1
    ORA-00289: suggestion : /data1/newdb/orcl/arch/arch_1_13877.arc
    ORA-00280: change 9220396171447 for thread 1 is in sequence #13877
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    [color=Red]AUTO[color]
    ORA-00308: cannot open archived log '/data1/newdb/orcl/arch/arch_1_13877.arc'
    ORA-27037: unable to obtain file status
    SVR4 Error: 2: No such file or directory
    Additional information: 3
    [color=Red]SQL> recover database using backup controlfile until cancel;[color]
    ORA-00279: change 9220396171447 generated at 07/28/2007 01:31:22 needed for thread 1
    ORA-00289: suggestion : /data1/newdb/orcl/arch/arch_1_13877.arc
    ORA-00280: change 9220396171447 for thread 1 is in sequence #13877
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    [color=Red]CANCEL[color]
    Media recovery cancelled.
    SQL> alter database open resetlogs;[color=Red][color]
    Database altered.
    *********What action have been done by UNTIL CANCEL?
    Message was edited by:
    [email protected]

    I'll say it again in case you missed it the first time: V$ views are NOT part of the data dictionary. You can't read the data dictionary until the database is opened.
    If you've performed a recovery 'until cancel', your datafiles are all in synch with each other. They may even agree with checkpoint change number in the controlfile. But what about your redo logs? By definition, they will have changes in them from a time after the point in the redo stream you got to when you said 'cancel'.
    Therefore, the redo logs will be ahead of where the rest of the database has now gotten to.
    And that is why you HAVE to open the database with a resetlogs operation (that is, 'alter database open resetlogs;'). That causes the existing redo logs to be wiped clean and thus cleared of any redo from a time after the time the rest of your database has been recovered to.

  • Problem running multiple folder actions at the same time

    Hi,
    Does anyone have some experience running multiple folder actions at the same time?
    I've written a Applescript folder action that processes some files. When adding some files, the script starts and all goes well. The processing of each file takes a few minutes, but all files are processed correctly.
    However, when adding some new files to the dropfolder, while the folder action is all ready processing other files dropped a few minutes earlier, the process that is all ready running immediately aborts and the folder action is relaunched on the new files, leaving the old files for what they are...
    The same problem occurs with multiple folders, each having a folder action attached. When dropping files in "Folder A", the script starts processing. But if someone droppes files in "Folder B", The script of folder A aborts, and the script of folder B starts processing. When adding more files to the folders, the result is the same. In some casses, when the last dropped files are processed, the os continues where the operation was aborted on the previous files. But this not always happens. To make things worse, when you remove the items from the folders afterwords, the folder actions starts running again on items no longer present in the folder !!!!
    Does anyone know how I can prevent the folder action being aborted when new files are dropped and placing the new files in "Hold", until the previous files are processed? How can I prevent a folder action being aborted when a item is dropped into another folder?
    I've written a small script to test this behaviour. Just create one or more folders and attach the script below. Drop a item into the folder, wait a few seconds and drop another one in the same or another folder. To monitor what happens please check the console.
    on adding folder items to this_folder after receiving added_items
              set FolderName to this_folder as string
              set ItemName to added_items as string
              repeat with theIncrementValue from 1 to 15
      delay 2
                        do shell script ("logger \"Folder: " & FolderName & "  -  Item: " & ItemName & "  -  Step: " & theIncrementValue & "\"")
              end repeat
              do shell script ("logger \"Folder: " & FolderName & "  -  Item: " & ItemName & "  -  Done...\"")
    end adding folder items to
    Thanks for any feedback.

    That is pretty much the way Folder Actions work, especially since AppleScript is not multi-threaded.  If you are using them as some intermediate step in a workflow, you might rethink the way you are handling the files (for example, use a droplet instead).  Other options would be using launchd to watch a path or a shell script on a different thread.

  • Processing a File (From a Folder Action) Through an AppleScript

    I have a Folder Action enabled which automatically uploads images placed in a folder to a FTP server. It works great when I'm at home on my own network, but if I'm somewhere with a firewall that prohibits connecting to my FTP server (i.e. work) or if I am not connected to the internet, the folder action will still run but my images will never get uploaded.
    I've attached a screenshot of my workflow. The folder action gets the image added to the folder, copies the original to a different folder, and then scales the image down to a smaller size before uploading it. I'm using the upload workflow action from Transmit.
    I figured I could use an AppleScript to check whether or not my computer can reach the ftp server and then wait until it was connected to run the rest of the workflow if it can't reach the server:
    repeat with i from 1 to 86400
        try
            do shell script "ping -o ftp.examplewebsite.com"
            exit repeat
        on error
            delay 5
            if i = 86400 then error number -128
        end try
    end repeat
    The only problem is, I'm pretty inexperienced with AppleScript and am not really sure how or where to insert it into my workflow to get the image to "pass through" the AppleScript. Currently, whenever I include this AppleScript in my workflow, before the Upload action, for example, the image ends up not getting passed through the AppleScript and it doesn't get uploaded as a result.
    Hopefully this a fairly simple question and someone can help me out, or if there's an easier way to delay running a folder action until I can connect to the server someone will let me know. I can clarify anything if necessary.

    Good job
    I just saw this…
    applescript in automator - stop a workflow
    It kills the workflow based on a test, so I tried this…
    Here is the text if you want to copy & paste. It will fail on Apple.com & stop the workflow. Success should allow it to continue.
    on run {input, parameters}
      try
      set pinged to do shell script "ping -c 3 -q  apple.com "
      if pinged is equal to 0 then
      return input
      end if
      on error
      error number -128 -- exit by user-cancel
      end try
    end run
    on run {input, parameters}
       display dialog "Rest of script will now continue..."
      return input
    end run

  • Unzip/Unstuff Folder Action

    I wanted to set up a folder in which a file would automatically unzip/unstuff once it is done downloading from an FTP site, and V.K. in the Automator board showed me this applescript:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;" title="this text can be pasted into the Script Editor">
    property DELAYTIMESECONDS : 5 -- How long to wait between checking file size.
    on adding folder items to thisFolder after receiving theItems
    repeat with f in theItems
    set oldSize to 0
    set newSize to -1
    -- When newSize equals oldSize, it means the copy is complete because the size hasn't changed.
    repeat while newSize ≠ oldSize
    -- Get the file size.
    set oldSize to size of (info for f)
    delay DELAYTIMESECONDS
    -- Sample the size again after delay for comparison.
    set newSize to size of (info for f)
    end repeat
    -- Do your processing here on file f.
    tell application "Finder" to open f
    -- thats where my processing should start for each file
    end repeat
    -- Or start processing here to wait for all files to be complete.
    end adding folder items to</pre>
    I attached it to a folder, and it works, but only on the first file. If I let multiple files download concurrently, the script never kicks in for the second, third, etc. file. Can the applescript be modified so that it hits every file that is, eventually, saved to the folder?

    The problem is that the folder action gets triggered the minute something gets added to the folder. This works when everything is added at once, but if there is much of a time delay between adding items there can be a problem, since repeatedly firing off the same folder action script on the same folder with different items doesn't seem to work very well.
    Another thing to try would be to just look at the folder itself to stop changing size. After the folder has stopped changing size (presumably because the files have finished downloading), all of the files would then be processed. The items would need to be moved somewhere during the processing, so that the next time the folder action is triggered, it would just be processing the new items (if the processing just gets all of the files, a sub folder could be used).
    The following folder action is similar to what you were using, it just looks at the folder size.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #FFEE80;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on adding folder items to thisFolder after receiving theItems
    if (WaitForFilesToCopy into thisFolder for 60) then
    tell application "Finder"
    set theItems to (files of thisFolder) as alias list -- get a new item list
    end tell
    repeat with anItem in theItems
    -- do stuff with anItem
    end repeat
    else
    -- the downloads didn't happen in time
    end if
    end adding folder items to
    to WaitForFilesToCopy into TheFolder for TimeToWait
    waits up to the TimeToWait for files to be copied/downloaded to TheFolder
    the test is based on the size of the folder not changing after several seconds
    the rough TimeToWait may need to be adjusted if copying several files/folders
    parameters - TheFolder [mixed]: the folder to check
    TimeToWait [integer]: a maximum timeout value in seconds
    returns [boolean]: true if copy/download finished, false if timeout
    set {Possible, Interval} to {false, 3} -- change the check interval as desired
    set CurrentSize to size of (info for TheFolder) -- get initial size
    repeat (TimeToWait div Interval) times -- check every Interval seconds
    delay Interval
    set NewSize to size of (info for TheFolder) -- recheck size
    if (NewSize is equal to CurrentSize) then
    if Possible then -- no change since last time
    return true -- success
    else -- one more time...
    set Possible to true
    end if
    else -- update size & Possible switch
    set {CurrentSize, Possible} to {NewSize, false}
    end if
    end repeat
    return false -- fail (timeout)
    end WaitForFilesToCopy
    </pre>

  • Folder Actions will not work - tried everything

    Recently Folder Actions simply stopped working on 10.6.4. They worked fine before then recently just stopped working.
    I've tried everything I can think of, including:
    1. completely removing enabling & disabling & enabling folder actions through the setup app.
    2. trashing folder actions plist files in user domain and relaunching
    3. disabling related launchd processes with lingon
    4. trashing launch agents in user domain and also trying to unload them in terminal
    5. trying to kill the folder actions dispatcher process in activity monitor (just relaunches, as it should)
    6. emptying system caches including dyld shared cache using cocktail
    7. doing most of the above and restarting
    It's driving me nuts. Any other ideas?
    here's some entries from syslog:
    8/2/10 9:31:37 AM com.apple.launchd.peruser.501[269] (com.apple.FolderActions.folders) Throttling respawn: Will start in 6 seconds
    8/2/10 9:37:29 AM Folder Actions Setup[4403] * WARNING: Method selectedRowEnumerator in class NSTableView is deprecated. It will be removed in a future release and should no longer be used.
    8/2/10 9:43:37 AM com.apple.launchd.peruser.501[269] (com.apple.FolderActions.enabled[309]) Exited: Killed
    8/2/10 9:46:23 AM [0x0-0x3a03a].com.apple.systemevents[360] com.apple.FolderActions.enabled: Already loaded
    8/2/10 9:52:07 AM Folder Actions Setup[1083] * WARNING: Method selectedRowEnumerator in class NSTableView is deprecated. It will be removed in a future release and should no longer be used.
    8/2/10 9:52:16 AM com.apple.launchd.peruser.501[269] (com.apple.FolderActions.folders) Throttling respawn: Will start in 7 seconds
    8/2/10 9:53:02 AM com.apple.launchd.peruser.501[269] (com.apple.FolderActions.folders) Throttling respawn: Will start in 1 seconds
    8/2/10 9:56:18 AM com.apple.launchd.peruser.501[269] (com.apple.FolderActions.folders) Throttling respawn: Will start in 10 seconds
    8/2/10 10:00:58 AM Folder Actions Setup[2190] * WARNING: Method selectedRowEnumerator in class NSTableView is deprecated. It will be removed in a future release and should no longer be used.
    8/2/10 10:01:01 AM com.apple.FolderActions.enabled[2236] launchctl: Error unloading: com.apple.FolderActions.folders
    8/2/10 10:01:30 AM com.apple.launchd.peruser.501[269] (com.apple.FolderActions.folders) Throttling respawn: Will start in 10 seconds
    8/2/10 10:01:42 AM com.apple.launchd.peruser.501[269] (com.apple.FolderActions.folders) Throttling respawn: Will start in 9 seconds
    8/2/10 10:05:03 AM sudo[2622] lryter : TTY=ttys000 ; PWD=/Users/lryter ; USER=root ; COMMAND=/bin/launchctl unload -w /Users/lryter/Library/LaunchAgents/com.apple.FolderActions.enabled.plist
    8/2/10 10:10:25 AM Folder Actions Setup[676] * WARNING: Method selectedRowEnumerator in class NSTableView is deprecated. It will be removed in a future release and should no longer be used.
    8/2/10 10:10:27 AM com.apple.FolderActions.enabled[680] launchctl: Couldn't stat("/Users/lryter/Library/LaunchAgents/com.apple.FolderActions.folders.plist"): No such file or directory
    8/2/10 10:10:27 AM com.apple.FolderActions.enabled[680] nothing found to unload
    8/2/10 10:10:38 AM com.apple.launchd.peruser.501[268] (com.apple.FolderActions.folders) Throttling respawn: Will start in 8 seconds
    8/2/10 10:13:17 AM sudo[943] lryter : TTY=ttys000 ; PWD=/Users/lryter ; USER=root ; COMMAND=/bin/launchctl unload -w /Users/lryter/Library/LaunchAgents/com.apple.FolderActions.enabled.plist
    8/2/10 10:14:01 AM com.apple.launchd.peruser.501[268] (com.apple.FolderActions.folders) Throttling respawn: Will start in 4 seconds
    8/2/10 10:14:14 AM com.apple.launchd.peruser.501[268] (com.apple.FolderActions.folders) Throttling respawn: Will start in 1 seconds

    I finally go Folders Action to work, after being unable to use it even for a simple beep for years now.
    Here is what I did:
    1. Changed permissions to 755 for the following folder and two contained files (note that 775 didn't work for me)
    ~/Library/LaunchAgents/
    ~/Library/LaunchAgents/com.apple.FolderActions.enabled.plist
    ~/Library/LaunchAgents/com.apple.FolderActions.folders.plist
    2. Changed the following lines within ~/Library/LaunchAgents/com.apple.FolderActions.enabled.plist (using TextWrangler)
    from:
    <key>OnDemand</key>
    <false/>
    to:
    <key>OnDemand</key>
    <true/>
    Prior to the permissions changes within #1 above, the value of <true/> kept getting changed back to <false/> by something in the system... and though
    there was improvement by the permissions changes, the following console message appeared until false was changed to true.
    com.apple.FolderActions.enabled[4127] launchctl: Error unloading: com.apple.FolderActions.folders
    At this point true is staying true, and not being changed by unknown forces to false, and the above message is not appearing.
    3. The only other thing I did prior to #1 and #2 above, was to run the script (unsaved),
    tell application "/System/Library/CoreServices/Folder Actions Dispatcher.app" to tick
    This little tell line caused something to occur where my Folder Action surprised me and worked for the first time though it took about 30 seconds and was erratic,
    sometimes performing, sometimes not, though if I would do move something into the folder to trigger the action that should occur, and did not occur, then at the point
    running the above tell line or script would cause the action to occur.
    4. At this point I don't fool with the tell line or script from #3, and it seems that systemevents has gotten involved, as well as launchd, and with my simple Folder Action script
    I'm getting the folder action within 10 seconds compared to 30 to 45 if ever seconds.
    5. This is still too early to tell if this is the wonder pill I've needed since Leopard, and now Snow Leopard (and maybe Tiger as well: I forget when I even tried Folder Actions).
    There was a time when I moved things around, so that the items normally found in the former AppleScript folder, were placed elsewhere in subfolders, so I don't know if that lead to this...
    because I could get Folder Actions to work on Macs in the Applestore, but not my own Mac. Watching the console messages was helpful. I don't think it's a big concern that
    deprecated messages are found sometimes. That's a just a normal part of the constantly rebuilding of things that goes on. It's more like a reminder that we've got an upgraded
    OEM part were going to start using, and the older part won't be available after such and such date, so program accordingly, and in the meantime drive.

  • Folder Action + Move Finder Items = Zero KB files

    I've got a folder action set that is supposed to run the Automator Action "Move Finder Items" on any file that gets placed in a specific folder (called "Folder A") and move it to "Folder B". I'm having an issue with larger files though.
    As soon as I begin to transfer the file to "folder A" , the folder action runs and results in a "Zero KB" file in "Folder B".
    Is there any way to keep the Folder Action from triggering until the file has completely copied to the folder with the Folder Action attached ("Folder A")?
    A side note: I have this same folder action running on an iMac with Mac OS 10.6.3 and it works great . (This one was made with the newer version of Automator that shipped with 10.6 vs. Automator on 10.5 which made the action I am having trouble with)
    Any input would be appreciated!

    There is a check in *Snow Leopard* to see if the items have completed their copy/download, but Leopard does not do any checking - the script is triggered immediately. You can add your own delay with a *Run AppleScript* action, though, for example:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #DAFFB6;
    overflow: auto;"
    title="this text can be pasted into an Automator 'Run AppleScript' action">
    on run {input, parameters} -- wait for file copy to complete by testing the size of the containing folder
    set theFolders to {} -- to handle items in different folders
    set skippedItems to {}
    repeat with anItem in the input -- get a list of unique folders
    tell application "Finder"
    get (container of anItem) as alias
    if the result is not in theFolders then set the end of theFolders to the result
    end tell
    end repeat
    repeat with aFolder in theFolders
    set timeToWait to 30 -- time to wait for copy to complete
    set interval to 2 -- test every interval seconds
    set copied to false
    tell application "Finder" to set currentSize to size of aFolder -- get initial size
    repeat with timer from timeToWait to 1 by -interval -- check every interval seconds up to maximum time
    delay interval
    tell application "Finder" to set newSize to size of aFolder -- recheck size
    if (newSize is equal to currentSize) then
    set copied to true
    exit repeat -- success
    else -- update size
    set currentSize to newSize
    end if
    end repeat
    if not copied then set the end of skippedItems to quoted form of (aFolder as text) -- timed out
    end repeat
    showSkippedAlert for skippedItems
    return input
    end run
    to showSkippedAlert for skippedItems
    show an alert dialog for any items skipped, with the option to cancel the rest of the workflow
    parameters - skippedItems [list]: the items skipped
    returns nothing
    if skippedItems is not {} then
    set {alertText, theCount} to {"Error with waiting for items to copy", count skippedItems}
    if theCount is greater than 1 then
    set theMessage to (theCount as text) & space & " folders timed out"
    else
    set theMessage to "1 folder timed out"
    end if
    set theMessage to theMessage & " - copy of contents may be incomplete:"
    set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
    set {skippedItems, AppleScript's text item delimiters} to {skippedItems as text, tempTID}
    if button returned of (display alert alertText message (theMessage & return & skippedItems) alternate button "Cancel" default button "OK") is "Cancel" then error number -128
    end if
    return
    end showSkippedAlert
    </pre>
    The action will check the folder sizes, and when there is no change (or the wait times out) the input items are passed on.

  • Folder Action to Launch Perl Script

    Hello.
    I wrote a perl script which I wanted to execute when a file was dropped into a folder. I added a folder action with a very simple applescript:
    on adding folder items to this_folder after receiving added_items
    do shell script ¬
    ("perl /Users/Alexander/Library/Scripts/gte2.pl")
    end adding folder items to
    The folder action didn't do anything, any thoughts on what I'm doing wrong? Note, the perl script works fine when I run it from the terminal.
    thanks.

    Thanks Camelot, I appreciate the help. My script below is trying to read data from a file in folder in my system. So I will try your suggestion, I didn't realize the environment and path my be different.
    Regards Alex
    #!/usr/bin/perl -w
    #This program is to convert files from gamin running GPS watch to text file which can be loaded into excel.
    # To make executable, remember to set: chmod u+x <file>
    #set all the flags. Note the flags are used to stop the matching
    $i = 1; $k = 0; $start = "no";
    #Open data file and find values
    open(DATA,"/Users/Alexander/Alex's Misc/Health/Garmin_Conversion/run.tcx") || die "Couldn't open file*\n";
    #read in the data line by line until "end of file"
    while (<DATA>){
    #start parsing for information to keep
    if (/.<Id>./) {
    @Idline=split(/>/);
    @Idbeat=split(/T/,$Idline[1]);
    $Id=$Idbeat[0];
    if (/.<Track>./){
    $start = "yes";
    if ($start eq "yes"){
    if (/.<Time>./) {
    @timeline=split(/T/);
    @timebeat=split(/Z/,$timeline[2]);
    $Time[$i]=$timebeat[0];
    elsif (/.<LatitudeDegrees>./) {
    @HRline=split(/>/);
    @HRbeat=split(/</,$HRline[1]);
    $Latitude[$i]=$latbeat[0];
    elsif (/.<LongitudeDegrees>./) {
    @longline=split(/>/);
    @longbeat=split(/</,$longline[1]);
    $Longitude[$i]=$longbeat[0];
    elsif (/.<AltitudeMeters>./) {
    @altline=split(/>/);
    @altbeat=split(/</,$altline[1]);
    $Altitude[$i]=$altbeat[0];
    elsif (/.<DistanceMeters>./) {
    @distline=split(/>/);
    @distbeat=split(/</,$distline[1]);
    $Distance[$i]=$distbeat[0];
    elsif (/.<Value>./) {
    @HRline=split(/>/);
    @HRbeat=split(/</,$HRline[1]);
    $HR[$i]=$HRbeat[0];
    $i++;
    } #string matching
    } #if start flag is yes
    } #while data loop
    close (DATA) || die "couldn't close file.\n";
    #write all data to file in space delimited format
    open (NEWFILE, ">/Users/Alexander/Alex's Misc/Health/Garmin_Converted/$Id run") || die "can't create file.\n";
    $Time[0]="Time"; $Latitude[0]="Latitude"; $Longitude[0]="Longitude"; $Altitude[0]="Altitude"; $Distance[0]="Distance"; $HR[0]="HR";
    print NEWFILE "0 $Time[0] $Latitude[0] $Longitude[0] $Altitude[0] $Distance[0] $HR[0]\n";
    for ($j = 1; $j <= $i; $j++) {
    $k=$j+1;
    print NEWFILE "$j $Time[$j] $Latitude[$j] $Longitude[$j] $Altitude[$j] $Distance[$j] $HR[$j]\n";
    } #for j loop
    close (NEWFILE) || die "couldn't close newfile.\n";
    #This is the end of the program

  • Creating a simple Folder Action

    Hello, I am trying to make a simple folder action.
    Well first off I have all my applications stored in the "application" folder (Mac MD>Applications) and I have aliases to all the apps stored in a separate application folder in which I have arranged the apps by type. One folder I have is called "new apps" (Mac HD>Users>Me>Applications>New Apps) it contains obviously new applications I have downloaded and have yet to try out.
    *What I want to do is whenever I drag a new application to the new apps folder I want it to 1) make an alias of that application and then 2) move the application to my actual "applications" folder.
    I went to automator and selected "New Aliases" and selected the new apps folder for its location to be made, and then followed it by "Move Finder Item" and selected my applications folder. I then saved it as a folder action attached to my new apps folder... It doesn't work. Yes folder actions are enabled. Is there something else I need to do for the folder action to actually pass the new files added into the folder into the script? thank you much
    Sean

    Spotlight can search for a color label but you must make that an active search criterion. Open a new Smart Folder in the Finder. Click on the + button to the right of the Save button. From the drop down menu that displays "Kind" select Other. Scroll down the list until you find the "File label" entry and then check the box to the right of the item. Click Close button. Now you should see the drop down menu has the "File label" selection followed by the color options. Select the "Green" color.
    Now, Spotlight will find files with a green label, but it may not display folders with the green label. I've not tested that. If it does not locate folders with a green label, then you will need to set the color of the files in the green labeled folders to the green label.

  • Folder actions no longer works after migration

    The script below was working perfectly on an iMac G4. I use it as a type of print spooler for a DOS application that runs in Dosbox for OS X (also works for OS9 apps). I just send the file to the monitored folder and the script prints the contents and deletes the file from the folder.
    I moved to an iMac G5 and used Setup Assistant to transfer my system (no lectures please...). Configure Folder Actions indicates that the script is enabled for the particular folder. However the Folder Action is no longer triggered when I add files to the monitored folder. I have tried repairing permissions, recompiling the script, deleting the folder and creating a new one...
    Is this a quirk of migration?
    on adding folder items to this_folder after receiving added_items
    delay 20 -- time for job to finish?
    repeat with each_item in added_items
    tell application "Printer Setup Utility" to open each_item
    delay 40 -- time before file is deleted from folder
    tell application "Finder" to delete each_item
    tell application "Printer Setup Utility"
    quit
    end tell
    end repeat
    end adding folder items to

    Michael,
    That script seems to work here.
    You could check whether the script is actually attached by using the Folder Actions Setup utility which is located here:
    ~/Applications/AppleScript
    This utility gives you all the folders and their attached scripts in one window.
    You might also want to check to see whether locating your script in the following location helps:
    ~/Library/Scripts/FolderActions
    as that is where the utility wants them to go when you are attaching a folder action script to a folder.

  • Help Needed: Automator Applescript for Folder Action - Encode Video

    Hi !
    I have created an Automator Applescript for a Folder Action to do the following:
    When a new video file is moved to the target folder (i.e. Download of Vuze is done), automatically launch the Applescript Action that does the followin g(Applescripted):
    1) Using "run shell script" and FFMPEG on a UNIX command line, determine Width/Height, Framerate, Bitrate
    2) Calculate encoding parameters (slightly reduced bitrate, reduced Aspect etc.)
    3) Using "run shell script" with ffmpeg on the command line and the calculated parameters to encode the video file
    At the same time, the action is written to a log file so I know if a file is recognized, when encoding started etc.
    It works fine if I save this Action as an .app, make an alias on the Desktop and drop video files on it.
    It also works fine if I attach the script to a folder as a folder action and drag a video file in there.
    However, when I attach the script as a folder action to the Vuze download folder, it encodes only some video files, i.e. if there was a download of 5 files, chances are good that it will not encode 1 or 2 files out of those 5.
    If for example a second download finishes while the encoding for the first download is still going on, sometimes the second file starts encoding after the first encode finishes, sometimes it does not, the file does not make the log file at all, i.e. the folder action missed it or the automator action dropped it because it was still encoding. Still, sometimes it happens, sometimes not.
    As I need a solution that is 100% accurate, I would like to ask if there are any ideas on how to do this better maybe? As I am not an Applescript Guru, I would need some help to know what works and what doesn't and what the syntax is.
    My main idea right now:
    Similar to how ffmpegX works with its "process" application, have a second script (as .app) that receives the files to be encoded from the automator action and puts them in a queue, then proceeds to encode this queue while the main automator action is free to receive the next file.
    Writing this second app is quite straightforward (a modified version of my current script) but I have some questions I need help with:
    1) How do I call another applescript from within an existing applescript that launches the new applescript in a new process?
    2) How do I pass parameters to this new applescript?
    3) In case of this "Queueing" Idea, once I called the external applescript the first time, how do I make sure when I call next time, that I don't open a second instance of this script but rather pass another queue item to the original instance to be processed?
    Or in general: Is there a better way to achieve this automatic encoding solution that I have not thought about?
    Alternatively:
    Does anyone know how to call the "process" application that comes with the ffmpegX package with the correct parameters to use as a queueing / processing tool?
    Thanks!
    Joe
    Message was edited by: Joe15000
    Message was edited by: Joe15000

    To do this, I created an Automator workflow with an Applescript snippet to change the 'media kind'.
    Here is the 'Run Applescript' workflow step code:
    on run {input, parameters}
              tell application "iTunes"
                        set video kind of (item 1 of input) to movie
              end tell
              return input
    end run
    Prior to this running, I have an 'Import Files into iTunes' workflow step.
    You can switch out 'movie' with: 'TV show', 'music video', or anything in ITLibMediaItemMediaKind.
    Good luck,
    Glenn

  • Downloads Folder Action

    Hello,
    I found a simple shell script that will help keep my Downloads folder organized by modification date. I used Automator to create a Finder Plug-In that's nothing but a Run Shell Script action: touch "$." Works great. I saved it as a folder action and attached it to my Downloads folder, but it won't work as a folder action. I added a Wait for Files to Copy action (testing with a pdf extension and download), and it still doesn't work. I tried to attach it to a dummy folder on my desktop that I directed Safari to save downloads to, still wouldn't work. I've saved it as a script, and attached it to the folder as a script, no joy. Will someone please help me with this. It should be very simple, I just want the items to be touched without having to touch each one myself.
    I have checked permissions on my user folder and Downloads folder, also deleted ~/Library/LaunchAgents/com.apple.FolderActions.enabled.plist and com.apple.FolderActions.folders.plist, logged out/in, disabled and re-enabled folder actions. Also, I have another folder action attached to my Downloads (Unquarantine), and it seems to work fine.
    Thanks in advance for any help,
    Jess

    I'm closing this question because the folder actions somehow work now. I must have shut down/started up enough times, or done something inadvertently to kick it into gear. I frequently have to check to make sure the folder actions are enabled, but other than that, my script works like a charm! Thanks for giving this your attention.
    Jess

  • Folder action adding date to added file

    I need to write a folde action that will add the date to a files name after it is added. can anyone help here. here is what I have done but the file still does not get named correctly.
    set m to month of (current date)
    set d to day of (current date)
    set y to year of (current date)
    if month of (current date) is January then
    set m to 1
    else
    if month of (current date) is February then
    set m to 2
    else
    if month of (current date) is March then
    set m to 3
    else
    if month of (current date) is April then
    set m to 4
    else
    if month of (current date) is May then
    set m to 5
    else
    if month of (current date) is June then
    set m to 6
    else
    if month of (current date) is July then
    set m to 7
    else
    if month of (current date) is August then
    set m to 8
    else
    if month of (current date) is September then
    set m to 9
    else
    if month of (current date) is October then
    set m to 10
    else
    if month of (current date) is November then
    set m to 11
    else
    if month of (current date) is December then
    set m to 12
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    set theshortdate to m & "/" & d & "/" & y as string
    --display dialog theshortdate
    set source_folder to "Macintosh HD 2:Users:Edit2:Desktop:test"
    tell application "Finder"
    --set theFile to every item in folder source_folder
    set old_name to "123"
    set new_name to old_name & ".scpt" & " " & theshortdate as string
    set name of file "Macintosh HD 2:Users:Edit2:Desktop:test:123.scpt" to new_name as string
    end tell

    this thing keeps repeat forever and adding the 11-1-07 date to the file name over and over, I cant figure out why
    on adding folder items to this_folder after receiving added_items
    set m to month of (current date)
    set d to day of (current date)
    set y to year of (current date)
    if month of (current date) is January then
    set m to 1
    else
    if month of (current date) is February then
    set m to 2
    else
    if month of (current date) is March then
    set m to 3
    else
    if month of (current date) is April then
    set m to 4
    else
    if month of (current date) is May then
    set m to 5
    else
    if month of (current date) is June then
    set m to 6
    else
    if month of (current date) is July then
    set m to 7
    else
    if month of (current date) is August then
    set m to 8
    else
    if month of (current date) is September then
    set m to 9
    else
    if month of (current date) is October then
    set m to 10
    else
    if month of (current date) is November then
    set m to 11
    else
    if month of (current date) is December then
    set m to 12
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    set theshortdate to m & "-" & d & "-" & y as string
    tell application "Finder"
    display dialog theshortdate
    set n to count items in added_items
    display dialog n as text
    repeat with an_item in added_items
    set file_name to name of an_item as string -- get the current name
    --display dialog file_name as string
    set newname to file_name & " " & theshortdate
    --display dialog newname
    set name of an_item to newname as text
    end repeat
    end tell
    end adding folder items to

Maybe you are looking for

  • How to link to a file in UCM with content presenter site studio template

    Hi, I have Webcenter spaces with content presenter showing Site studio content. In this site studio region I have an element for rich text (html) Now we want to create a link in this text to an existing document in UCM. The question is how achief thi

  • I have a problem with lion.  My MacBook pro froze and now I get a gray folder with a question mark.

    I recently upgraded to lion but my screen just froze. I had to shut it down by holding the power button down. Every time I tried to start it again I got a grey folder with a question mark and couldn't do a thing. I' ve been told to restore snow leopa

  • Percentage issue, please?

    Hi Gurus, i have issue with percentage calculation Names |Count|Percentage AAAA | 4------|80.00% BBBBB | 1------|16.67% Total---| 5----- |100.00% I am getting wrong result in above table for 16.67%, but 1/5 is 20.00%. How i am doing is i am counting

  • Regarding XI only

    Hello,        Do XI is using for only intergration? or Can we do any other communication with this. what is meant by people integation? and information integration? Thank you

  • How do I burn audio from iTunes on pc with windows 7

    how do I burn cd in iTunes? I went to the help menu but that did not pertain to my iTunes app. I go to edit menu, preferences, but there is no burn tab, I also don't have a play list. can anyone help?